Скрипт который решает эту проблему
AddEventHandler("catalog", "OnStoreProductUpdate", ["StoreProduct", "update"]);
AddEventHandler("catalog", "OnStoreProductAdd", ["StoreProduct", "update"]);
AddEventHandler("catalog", "OnBeforeStoreProductDelete", ["StoreProduct", "delete"]);
class StoreProduct
{
public static function update($id, $arFields)
{
$allAmountProduct = 0;
$obStoreProduct
= \Bitrix\Catalog\StoreProductTable::GetList(['filter' => ['PRODUCT_ID' => $arFields['PRODUCT_ID']]]);
while ($arStoreProduct = $obStoreProduct->Fetch()) {
if(($id == 0 && $arFields['STORE_ID'] != $arStoreProduct['STORE_ID']) or $id > 0) {
$allAmountProduct = $allAmountProduct + $arStoreProduct['AMOUNT'];
}
}
$arFieldsProduct = array(
"QUANTITY" => $allAmountProduct,
);
\Bitrix\Catalog\Model\Product::update($arFields['PRODUCT_ID'], $arFieldsProduct);
}
public static function delete($id)
{
$arFields = \Bitrix\Catalog\StoreProductTable::getRowById($id);
if ($arFields != null) {
self::Update(0, $arFields);
}
}
}