D
D
Dmitry Klimantovich2021-08-06 18:11:33
1C-Bitrix
Dmitry Klimantovich, 2021-08-06 18:11:33

How to bulk change the coefficient. units measurements for goods by decimal value?

On a random page, I made the following code:

if (CModule::IncludeModule("catalog")) {
 $get_list = CCatalogProduct::GetList(array('SORT'=>'ASC'), array('MEASURE'=> 8, "%ELEMENT_NAME" => "Портьера"));											
 while($kg_result = $get_list->GetNext()) {
  $ed_list = CCatalogMeasureRatio::GetList(array(), array('PRODUCT_ID'=>$kg_result['ID']), false, false, array());     
   while($ed_result = $ed_list->GetNext()) {										
    CCatalogMeasureRatioAll::update($ed_result['ID'], array('PRODUCT_ID'=>$kg_result['ID'], 'RATIO' => 0.5));   
   }
  }     
}

But this only works if I set the Ratio to any value greater than or equal to 1.
And I need to set it to 0.5.
Moreover, after setting the product manually to 0.5, and then updating the code for all 1, and then back to 0.5 - it works only with the product that had 0.5 manually set earlier.
Some kind of poltergeist.
How to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-08-06
@PetrPo

First you get the id-nicknames of the products for which you need to change the coefficient (as I understand it, this is your first request), then

\Bitrix\Main\Loader::includeModule('catalog');

$productIds = [323, 316];
$ratio = '0.5';

$iterator = \Bitrix\Catalog\MeasureRatioTable::getList([
  'select' => ['ID'],
  'filter' => ['PRODUCT_ID' => $productIds]
]);

while($row = $iterator->fetch()) {
  \Bitrix\Catalog\MeasureRatioTable::update($row['ID'], ['RATIO' =>$ratio]);
}

instead of $productIds you substitute your id-nicknames

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question