H
H
Hfnas2019-09-30 23:03:42
C++ / C#
Hfnas, 2019-09-30 23:03:42

Why do events not work when updating the quantity OnProductUpdate, OnBeforeProductUpdate?

AddEventHandler('catalog', 'OnProductUpdate', ['MyClass', 'OnProductUpdateHandler']);
class MyClass
{
    function OnProductUpdateHandler($id, &$arFields)
    {
         $arLoadProductArray = $arFields['QUANTITY'] > 0 ? Array("IN_STOCK" => "Y") : Array("IN_STOCK" => "N");
    }
}
AddEventHandler("catalog", "OnBeforeProductUpdate", "notInStore");
function notInStore($ID,&$arFields){
        if (($arFields['QUANTITY'] != $arFields['OLD_QUANTITY']) || (!is_null($arFields['QUANTITY']) && is_null($arFields['OLD_QUANTITY']))) {
            if (intval($arFields["QUANTITY"]) > 100) {
                $arFields["QUANTITY"] = 100;
            }
        }
}

I change the Available quantities in the infoblock.
And also is there such an event that, with several warehouses, only the warehouse that has been updated counts?
$eventManager->addEventHandler('catalog','OnStoreProductAdd', 'UpdateAvailableQuantity');
$eventManager->addEventHandler('catalog','OnStoreProductUpdate', 'UpdateAvailableQuantity');
$eventManager->addEventHandler('catalog','OnStoreProductDelete', 'DeletesAvailableQuantity');

use  \Bitrix\Main\Loader;
Loader::includeModule('catalog');
function UpdateAvailableQuantity($id, $arFields){
    $obProduct = new CCatalogProduct();
    if (intval($arFields["AMOUNT"])>=100){
        $obProduct->Update($arFields["PRODUCT_ID"], ['QUANTITY' => 100, 'SUBSCRIBE' => 'D']);
    }else{
        if ($arFields["AMOUNT"]==0)
            $obProduct->Update($arFields["PRODUCT_ID"], ['QUANTITY' => 0, 'SUBSCRIBE' => 'D']);
        else
            $obProduct->Update($arFields["PRODUCT_ID"], ['QUANTITY' => $arFields["AMOUNT"], 'SUBSCRIBE' => 'D']);
    }
}

Passes 2 times as there are 2 warehouses and that's bad.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VoidVolker, 2018-06-06
@MarianaSE

See the documentation for the following WinAPI calls: OpenProcess, ReadProcessMemory, WriteProcessMemory, CloseHandle. In addition, there is such a thing as restrictions on reading and writing to the memory of other processes, and you may need to set these additional flags or request rights.

D
Derevianko Alexander, 2018-06-06
@dio4

You probably need to see the address of the object in memory, and not "... the object whose value in memory I need to find" or is it still the address of the object's property? But anyway - create a pointer to an object or property and initialize it with whatever you want, then print that pointer to stdout ("%p") and see the address of what you want. Moreover, regardless of Win or Lin .. :)

H
Hfnas, 2019-10-04
@Hfnas

These are obsolete events, you need to enable support for obsolete events in the settings of the "Trade catalog" module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question