public function Update($ID, $arFields) { global $DB; $ID = (int) $ID; if ($ID <= 0) { return false; } foreach (GetModuleEvents("catalog", "OnBeforeProductUpdate", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields)) === false) { return false; } } if (array_key_exists('ID', $arFields)) { unset($arFields['ID']); } if (!CCatalogProduct::CheckFields("UPDATE", $arFields, $ID)) { return false; } $strUpdate = $DB->PrepareUpdate("b_catalog_product", $arFields); $boolSubscribe = false; if (!empty($strUpdate)) { if (isset($arFields["QUANTITY"]) && $arFields["QUANTITY"] > 0) { if (!isset($arFields["OLD_QUANTITY"])) { $strQuery = 'select ID, QUANTITY from b_catalog_product where ID = ' . $ID; $rsProducts = $DB->Query($strQuery, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arProduct = $rsProducts->Fetch()) { $arFields["OLD_QUANTITY"] = doubleval($arProduct['QUANTITY']); } } if (isset($arFields["OLD_QUANTITY"])) { $boolSubscribe = $arFields["OLD_QUANTITY"] <= 0; } } $strSql = "update b_catalog_product set " . $strUpdate . " where ID = " . $ID; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (CBXFeatures::IsFeatureEnabled('CatCompleteSet') && (isset($arFields['QUANTITY']) || isset($arFields['QUANTITY_TRACE']) || isset($arFields['CAN_BUY_ZERO']) || isset($arFields['WEIGHT']))) { CCatalogProductSet::recalculateSetsByProduct($ID); } if (isset(self::$arProductCache[$ID])) { unset(self::$arProductCache[$ID]); if (defined('CATALOG_GLOBAL_VARS') && 'Y' == CATALOG_GLOBAL_VARS) { /** @var array $CATALOG_PRODUCT_CACHE */ global $CATALOG_PRODUCT_CACHE; $CATALOG_PRODUCT_CACHE = self::$arProductCache; } } } foreach (GetModuleEvents("catalog", "OnProductUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } //call subscribe if ($boolSubscribe) { if (self::$saleIncluded === null) { self::$saleIncluded = Loader::includeModule('sale'); } if (self::$saleIncluded) { CSaleBasket::ProductSubscribe($ID, 'catalog'); } } return true; }