Answer the question
In order to leave comments, you need to log in
How to change the measurement factor after import?
Hello, I want to update the coefficient of the unit of measurement after updating the import, but I get an error
Fatal error: Cannot redeclare customCatalogImportStep() (previously declared in /var/www/html/local/php_interface/init.php:161) in /var/www/html/local/php_interface/init.php on line 371
[ErrorException] E_COMPILE_ERROR
Cannot redeclare customCatalogImportStep() (previously declared in /var/www/html/local/php_interface/init.php:161) (0)
/var/www/html/local/php_interface/init.php:371
function setRatio() {
\Bitrix\Main\Loader::includeModule('sale');
\Bitrix\Main\Loader::includeModule('catalog');
\Bitrix\Main\Loader::includeModule('iblock');
$arSelect = Array("ID", "PROPERTY_CML2_TRAITS", 'PROPERTY_TRANSPORTNAYA_UPAKOVKA', 'IBLOCK_ID');
$arFilter = Array("IBLOCK_ID" => 18, "!PROPERTY_CML2_TRAITS" => false);
$res = \CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
$el = new CIBlockElement;
while ($prod = $res->GetNextElement()) {
$PRODUCT_ID = $prod->GetFields()['ID'];
$value = $prod->GetProperty('CML2_TRAITS')['VALUE'];
$keys = $prod->GetProperty('CML2_TRAITS')['DESCRIPTION'];
$params = array_combine($keys, $value);
$is_error = false;
if (!empty($params['МинимальнаяУпаковкаНаименование']) && !empty($params['МинимальнаяУпаковкаКоличество'])) {
$db_enum_list = CIBlockProperty::GetPropertyEnum("TRANSPORTNAYA_UPAKOVKA", Array(), Array("IBLOCK_ID" => 18, "VALUE" => $params['МинимальнаяУпаковкаНаименование']));
if (!$PropID = $db_enum_list->GetNext()['ID']) {
$ibpenum = new CIBlockPropertyEnum;
if (!$PropID = $ibpenum->Add(Array('PROPERTY_ID' => '248', 'VALUE' => $params['МинимальнаяУпаковкаНаименование'])))
$is_error = true;
}
if (!$is_error) {
if ($el->SetPropertyValuesEx($PRODUCT_ID, 18, array("MIN_UPAKOVKA" => $params['МинимальнаяУпаковкаКоличество'], "TRANSPORTNAYA_UPAKOVKA" => $PropID))) {
$newRatioValue = preg_replace("/[^0-9]/", '', $params['МинимальнаяУпаковкаКоличество']);
$db_measure = \CCatalogMeasureRatio::getList(array(), $arFilter = array('PRODUCT_ID' => $PRODUCT_ID), false, false);
if ($ar_measure = $db_measure->fetch()) {
$test = \CCatalogMeasureRatio::update($ar_measure['ID'], array("PRODUCT_ID" => $PRODUCT_ID, "RATIO" => $newRatioValue));
} else {
\CCatalogMeasureRatio::Add(
array(
"PRODUCT_ID" => $PRODUCT_ID,
"RATIO" => $newRatioValue
)
);
}
}
}
} else {
if ($el->SetPropertyValuesEx($PRODUCT_ID, 18, array("MIN_UPAKOVKA" => '', "TRANSPORTNAYA_UPAKOVKA" => ''))) {
$newRatioValue = 0;
$db_measure = \CCatalogMeasureRatio::getList(array(), $arFilter = array('PRODUCT_ID' => $PRODUCT_ID), false, false);
if ($ar_measure = $db_measure->fetch()) {
$test = \CCatalogMeasureRatio::update($ar_measure['ID'], array("PRODUCT_ID" => $PRODUCT_ID, "RATIO" => $newRatioValue));
} else {
\CCatalogMeasureRatio::Add(
array(
"PRODUCT_ID" => $PRODUCT_ID,
"RATIO" => $newRatioValue
)
);
}
}
}
if (!empty($params['МинимальнаяУпаковкаКоличество'])) {
$el->SetPropertyValuesEx($PRODUCT_ID, 18, array("KOMPLEKTATSIYA_PERVICHNAYA_UPAKOVKA" => $params['МинимальнаяУпаковкаКоличество']));
}
}
}
AddEventHandler('catalog', 'OnSuccessCatalogImport1C', 'customCatalogImportStep');
function customCatalogImportStep()
{
setRatio();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question