• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/sku.php
  • Класс: BitrixCatalogProductSku
  • Вызов: Sku::handlerIblockElementSetPropertyValuesEx
static function handlerIblockElementSetPropertyValuesEx(
	$elementId,
	$iblockId,
	$newValues,
	$propertyList,
	$currentValues
)
{
	$iblockData = CCatalogSku::GetInfoByOfferIBlock($iblockId);
	if (empty($iblockData))
		return;

	$skuPropertyId = $iblockData['SKU_PROPERTY_ID'];
	if (!isset($propertyList[$skuPropertyId]))
		return;
	$skuPropertyCode = (string)$propertyList[$skuPropertyId]['CODE'];
	if ($skuPropertyCode === '')
		$skuPropertyCode = (string)$skuPropertyId;

	$foundValue = false;
	$skuValue = null;
	if (array_key_exists($skuPropertyId, $newValues))
	{
		$skuValue = $newValues[$skuPropertyId];
		$foundValue = true;
	}
	elseif (array_key_exists($skuPropertyCode, $newValues))
	{
		$skuValue = $newValues[$skuPropertyCode];
		$foundValue = true;
	}
	if (!$foundValue)
		return;
	unset($foundValue);

	$newSkuPropertyValue = 0;
	if (!empty($skuValue))
	{
		if (!is_array($skuValue))
		{
			$newSkuPropertyValue = (int)$skuValue;
		}
		else
		{
			if (array_key_exists('VALUE', $skuValue))
			{
				$newSkuPropertyValue = (int)$skuValue['VALUE'];
			}
			else
			{
				foreach($skuValue as $row)
				{
					if (!is_array($row))
						$newSkuPropertyValue = (int)$row;
					elseif (array_key_exists('VALUE', $row))
						$newSkuPropertyValue = (int)$row['VALUE'];
				}
				unset($row);
			}
		}
	}
	unset($skuValue);
	if ($newSkuPropertyValue < 0)
		$newSkuPropertyValue = 0;

	$currentSkuPropertyValue = 0;
	if (!empty($currentValues[$skuPropertyId]) && is_array($currentValues[$skuPropertyId]))
	{
		$currentSkuProperty = current($currentValues[$skuPropertyId]);
		if (!empty($currentSkuProperty['VALUE']))
			$currentSkuPropertyValue = (int)$currentSkuProperty['VALUE'];
		unset($currentSkuProperty);
	}
	if ($currentSkuPropertyValue < 0)
		$currentSkuPropertyValue = 0;

	if (!static::allowedPropertyHandler() || ($currentSkuPropertyValue != $newSkuPropertyValue))
	{
		self::$offers[$elementId] = [
			'CURRENT_PRODUCT' => $currentSkuPropertyValue,
			'NEW_PRODUCT' => $newSkuPropertyValue,
			'PRODUCT_IBLOCK_ID' => $iblockData['PRODUCT_IBLOCK_ID']
		];
	}
}