
use Bitrix\Main\Loader;
use Bitrix\Iblock\ElementTable;
use Bitrix\Catalog\MeasureRatioTable;
Loader::includeModule('iblock');
Loader::includeModule('catalog');
$iblockId = 39;
$updateElements = ElementTable::getList([
'select' => ['ID'],
'filter' => ['IBLOCK_ID' => $iblockId],
]);
while ($arFields = $updateElements->fetch()) {
$propertyValue = CIBlockElement::GetProperty(
$iblockId,
$arFields['ID'],
[],
[
'CODE' => 'KRATNOST'
]
);
if ($arProperty = $propertyValue->Fetch()) {
$coeff = $arProperty['VALUE'];
$curElementRatio = MeasureRatioTable::getList([
'filter' => [
'=PRODUCT_ID' => $arFields['ID'],
],
]);
if ($arRatio = $curElementRatio->fetch()) {
MeasureRatioTable::update($arRatio['ID'], [
'RATIO' => $coeff,
]);
}
}
}
/******************* Обновление коэффициентов после импорта **************/
use Bitrix\Main\Config\Option;
use Bitrix\Main\Loader;
use Bitrix\Iblock\ElementTable;
use Bitrix\Catalog\MeasureRatioTable;
CModule::IncludeModule("iblock");
CModule::IncludeModule('catalog');
AddEventHandler("catalog", "OnSuccessCatalogImport1C", "UpdateElementRatio");
function UpdateElementRatio($arParams, $arFields)
{
$updateElements = ElementTable::getList([
'select' => ['ID'],
'filter' => ['IBLOCK_ID' => 39],
]);
while ($arFields2 = $updateElements->fetch()) {
$propertyValue = CIBlockElement::GetProperty(
39,
$arFields2['ID'],
[],
[
'CODE' => 'KRATNOST'
]
);
if ($arProperty = $propertyValue->Fetch()) {
$coeff = $arProperty['VALUE'];
$curElementRatio = MeasureRatioTable::getList([
'filter' => [
'=PRODUCT_ID' => $arFields2['ID'],
],
]);
if ($arRatio = $curElementRatio->fetch()) {
MeasureRatioTable::update($arRatio['ID'], [
'RATIO' => $coeff,
]);
}
}
}
}
/******************* Обновление коэффициентов после импорта **************/