I
I
Ilya17912017-01-16 17:57:07
CMS
Ilya1791, 2017-01-16 17:57:07

Why doesn't CCatalogProduct::Update work when adding a new item?

Good afternoon!
There is a task: when adding a new product to Bitrix, automatically put down its quantity.
My code:

AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("UpdateClass", "OnAfterIBlockElementAddHandler"));
class UpdateClass
{
    
    function OnAfterIBlockElementAddHandler(&$arFields)
    {
        
          $PRODUCT_ID = $arFields['ID'];
                    $arFields = array('ID' => $arFields['ID'], 'QUANTITY' => 1);// количество товара
                    CCatalogProduct::Update($PRODUCT_ID, $arFields);
    }
}

But the item quantity is not updated. I started to figure out what was the matter, and eventually found out that updating the fields does not work for the newly created element. If you put the ID of another element in PRODUCT_ID, everything works fine.
What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2017-01-17
@winer

You confuse adding a new product and a new infoblock element. These are two different tables and different modules.
For the "when adding a product" event, you need an OnProductAdd
handler And here see other possible events of the "shopping catalog" module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question