• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/sku.php
  • Класс: BitrixCatalogProductSku
  • Вызов: Sku::handlerIblockElementSetPropertyValues
static function handlerIblockElementSetPropertyValues(
	$elementId,
	$iblockId,
	$newValues,
	$propertyIdentifyer,
	$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 ($propertyIdentifyer)
	{
		if (is_int($propertyIdentifyer))
		{
			$propertyId = $propertyIdentifyer;
		}
		else
		{
			$propertyId = (int)$propertyIdentifyer;
			if ($propertyId.'' != $propertyIdentifyer)
				$propertyId = ($skuPropertyCode == $propertyIdentifyer ? $skuPropertyId : 0);
		}
		if ($propertyId == $skuPropertyId)
		{
			$skuValue = $newValues;
			$foundValue = true;
		}
		unset($propertyId);
	}
	else
	{
		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
		{
			$skuValue = current($skuValue);
			if (!is_array($skuValue))
				$newSkuPropertyValue = (int)$skuValue;
			elseif (!empty($skuValue['VALUE']))
				$newSkuPropertyValue = (int)$skuValue['VALUE'];
		}
	}
	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;

	// no error - first condition for event OnAfterIblockElementUpdate handler
	if (!static::allowedPropertyHandler() || ($currentSkuPropertyValue != $newSkuPropertyValue))
	{
		self::$offers[$elementId] = array(
			'CURRENT_PRODUCT' => $currentSkuPropertyValue,
			'NEW_PRODUCT' => $newSkuPropertyValue,
			'PRODUCT_IBLOCK_ID' => $iblockData['PRODUCT_IBLOCK_ID']
		);
	}
}