R
R
redesupar2022-03-01 13:55:43
1C-Bitrix
redesupar, 2022-03-01 13:55:43

How to change the number of goods after the exchange of 1s Bitrix?

After the exchange, I need to change the available quantity of goods, I do this

AddEventHandler('catalog', 'OnCompleteCatalogImport1C', 'quantityCatalogImportStep');

function quantityCatalogImportStep() 
{
      $addProps = CIBlockElement::GetList (
  Array("QUANTITY" => "ASC"),
  Array("IBLOCK_ID" => 18),
false,
    false,
      Array(
      'ID', 'QUANTITY', 'NAME', 'PROPERTY_MIN_UPAKOVKA'
      )
);
while($ar_fields = $addProps->GetNext())
{

   $kolvo = $ar_fields['QUANTITY'];
   $min_upakovka = $ar_fields['PROPERTY_MIN_UPAKOVKA_VALUE'];
  $new_kolvo = (int)($kolvo / $min_upakovka);
      if ($ar_fields['QUANTITY'] > 0 && $ar_fields['PROPERTY_MIN_UPAKOVKA_VALUE'] > 0) {

  Cmodule::IncludeModule('catalog');
  $PRODUCT_ID = $ar_fields['ID'];
  $arFields = array(
    'QUANTITY' => $new_kolvo
  );
  CCatalogProduct::Update($PRODUCT_ID, $arFields);
    }


}
}


but it changes after the last exchange, and the quantities appear early i.e. the amount that I don't need hangs while the import is in progress (half an hour / hour) for which event or how to make it change immediately?
set it to OnSuccessCatalogImport1C, but then it changes the number with each package, which is 12 times

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Livach, 2022-03-01
@Mausglov

Have you tried changing the quantity during the exchange?
An example handler can be viewed here .
And a couple of notes:

  1. don't use GetNext() if Fetch() is enough
  2. it would be better to first check that the packing size is non-zero, and then divide by it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question