S
S
sergeyviktorovich2021-05-11 21:36:54
1C-Bitrix
sergeyviktorovich, 2021-05-11 21:36:54

How to rewrite the function of updating the field Coefficient of the unit of measure to the new syntax?

AddEventHandler("catalog", "OnPriceUpdate", "HandlerOnPriceUpdate");
function HandlerOnPriceUpdate($ID,&$arFields)
{
 
     
    $element = $arFields['PRODUCT_ID'];    //ID товара
    $iblockId = 9;
   /*$coeff= CIBlockElement::GetByID($arFields['PRODUCT_ID'])->GetNextElement()->GetProperties('VES_V_GRAMMAKH_SHAG');*/ //например
    $coeff= 100;
        $curElementRatio = CCatalogMeasureRatio::getList(
        Array(),
        array('IBLOCK_ID' => $iblockId, 'PRODUCT_ID' => $element ),
        false, false);

    while ($arRatio = $curElementRatio->GetNext()) {
        $ratioId = $arRatio['ID'];
        $arFieldsNew = Array(
            'RATIO' => $coeff,
        );

        CCatalogMeasureRatio::update($ratioId, $arFieldsNew);
    }

}


tried like this

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler(
    'catalog',
    '\Bitrix\Catalog\Price::OnAfterUpdate',
    static function ( $event ) {
       $result = new \Bitrix\Main\ORM\EventResult;
       $arFields   =   $event->getParameter('fields');
       $iblockId = 9;
         /*** получаем ID товара*/
       $element = $event->getParameter('primary')['ID'];
       $coeff= CIBlockElement::GetByID($arFields['PRODUCT_ID'])->GetNextElement()->GetProperties('VES_V_GRAMMAKH_SHAG'); //например
      
      
      $curElementRatio = CCatalogMeasureRatio::getList(
        Array(),
        array('IBLOCK_ID' => $iblockId, 'PRODUCT_ID' => $element ),
        false, false);

      while ($arRatio = $curElementRatio->GetNext()) {
          $ratioId = $arRatio['ID'];
          $arFieldsNew = Array(
              'RATIO' => $coeff,
          );

       return CCatalogMeasureRatio::update($ratioId, $arFieldsNew);
    }


    
    }
);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question