• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/sku.php
  • Класс: BitrixCatalogProductSku
  • Вызов: Sku::handlerAfterIblockElementUpdate
static function handlerAfterIblockElementUpdate(&$fields)
{
	$process = true;
	$modifyActive = false;
	$modifyProperty = false;
	$iblockData = false;
	$elementId = 0;

	if (!$fields['RESULT'])
		$process = false;
	else
		$elementId = $fields['ID'];

	if ($process)
	{
		$modifyActive = isset(self::$changeActive[$elementId]);
		$modifyProperty = (
			isset(self::$offers[$elementId])
			&& self::$offers[$elementId]['CURRENT_PRODUCT'] != self::$offers[$elementId]['NEW_PRODUCT']
		);
		$process = $modifyActive || $modifyProperty;
	}

	if ($process)
	{
		$iblockData = CCatalogSku::GetInfoByOfferIBlock($fields['IBLOCK_ID']);
		$process = !empty($iblockData);
	}

	if ($process)
	{
		if ($modifyActive && !isset(self::$offers[$elementId]))
		{
			$parent = CCatalogSku::getProductList($elementId, $fields['IBLOCK_ID']);
			if (!empty($parent[$elementId]))
				self::$offers[$elementId] = array(
					'CURRENT_PRODUCT' => $parent[$elementId]['ID'],
					'NEW_PRODUCT' => $parent[$elementId]['ID'],
					'PRODUCT_IBLOCK_ID' => $parent[$elementId]['IBLOCK_ID']
				);
			unset($parent);
		}

		if (isset(self::$offers[$elementId]))
		{
			$offerDescr = self::$offers[$elementId];

			if ($offerDescr['CURRENT_PRODUCT'] > 0)
			{
				if ($modifyActive || $modifyProperty)
				{
					self::calculateComplete(
						$offerDescr['CURRENT_PRODUCT'],
						$iblockData['PRODUCT_IBLOCK_ID'],
						CatalogProductTable::TYPE_SKU
					);
				}
			}
			if ($offerDescr['NEW_PRODUCT'] > 0)
			{
				$elementActive = (
					$modifyActive
					? self::$changeActive[$elementId]
					: self::$currentActive[$elementId]
				);
				if ($modifyProperty && $elementActive == 'Y')
				{
					self::calculateComplete(
						$offerDescr['NEW_PRODUCT'],
						$iblockData['PRODUCT_IBLOCK_ID'],
						CatalogProductTable::TYPE_SKU
					);
				}
			}

			if ($offerDescr['CURRENT_PRODUCT'] == 0 || $offerDescr['NEW_PRODUCT'] == 0)
			{
				$type = (
					$offerDescr['NEW_PRODUCT'] > 0
					? CatalogProductTable::TYPE_OFFER
					: CatalogProductTable::TYPE_FREE_OFFER
				);
				self::disableUpdateAvailable();
				$result = CatalogModelProduct::update($elementId, array('TYPE' => $type));
				unset($result);
				self::enableUpdateAvailable();
				unset($type);
			}

			unset($offerDescr);
		}
		else
		{
			self::disableUpdateAvailable();
			$result = CatalogModelProduct::update($elementId, array('TYPE' => CatalogProductTable::TYPE_FREE_OFFER));
			unset($result);
			self::enableUpdateAvailable();
		}
	}
	if (isset(self::$offers[$elementId]))
		unset(self::$offers[$elementId]);
	if (isset(self::$currentActive[$elementId]))
		unset(self::$currentActive[$elementId]);
	if (isset(self::$changeActive[$elementId]))
		unset(self::$changeActive[$elementId]);
	static::enablePropertyHandler();
}