• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/basketitem.php
  • Класс: BitrixSaleBasketItem
  • Вызов: BasketItem::onFieldModify
protected function onFieldModify($name, $oldValue, $value)
{
	$result = new Result();

	$r = parent::onFieldModify($name, $oldValue, $value);
	if (!$r->isSuccess())
	{
		$result->addErrors($r->getErrors());
		return $result;
	}
	elseif ($r->hasWarnings())
	{
		$result->addWarnings($r->getWarnings());
	}

	if (!$this->isBundleParent())
		return $result;

	if ($name === 'QUANTITY')
	{
		$deltaQuantity = $value - $oldValue;
		if ($deltaQuantity != 0)
		{
			if ($bundleCollection = $this->getBundleCollection())
			{
				$bundleBaseQuantity = $this->getBundleBaseQuantity();

				/** @var BasketItemBase $bundleItem */
				foreach ($bundleCollection as $bundleItem)
				{
					$bundleProductId = $bundleItem->getProductId();

					if (!isset($bundleBaseQuantity[$bundleProductId]))
						throw new ArgumentOutOfRangeException('bundle product id');

					$quantity = $bundleBaseQuantity[$bundleProductId] * $value;

					$r = $bundleItem->setField('QUANTITY', $quantity);
					if (!$r->isSuccess())
					{
						$result->addErrors($r->getErrors());
					}
				}
			}
		}
	}
	elseif ($name == "DELAY")
	{
		/** @var BundleCollection $bundleCollection */
		if ($bundleCollection = $this->getBundleCollection())
		{
			/** @var BasketItemBase $bundleItem */
			foreach ($bundleCollection as $bundleItem)
			{
				$r = $bundleItem->setField('DELAY', $value);
				if (!$r->isSuccess())
				{
					$result->addErrors($r->getErrors());
				}
			}
		}
	}
	elseif ($name == "CAN_BUY")
	{
		/** @var BundleCollection $bundleCollection */
		if ($bundleCollection = $this->getBundleCollection())
		{
			/** @var BasketItemBase $bundleItem */
			foreach ($bundleCollection as $bundleItem)
			{
				$r = $bundleItem->setField('CAN_BUY', $value);
				if (!$r->isSuccess())
				{
					$result->addErrors($r->getErrors());
				}
			}
		}
	}

	return $result;
}