• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/basketitem.php
  • Класс: BitrixSaleBasketItem
  • Вызов: BasketItem::add
protected function add()
{
	$logFields = $this->getLoggedFields();

	$result = parent::add();

	/** @var BasketItemCollection $collection */
	$collection = $this->getCollection();

	/** @var BasketBase $basket */
	if (!$basket = $collection->getBasket())
	{
		throw new MainObjectNotFoundException('Entity "Basket" not found');
	}

	if ($basket->getOrderId() > 0)
	{
		$registry = Registry::getInstance(static::getRegistryType());
		/** @var OrderHistory $orderHistory */
		$orderHistory = $registry->getOrderHistoryClassName();

		if (!$result->isSuccess())
		{
			$orderHistory::addAction(
				'BASKET',
				$basket->getOrderId(),
				'BASKET_ITEM_ADD_ERROR',
				null,
				$this,
				["ERROR" => $result->getErrorMessages()]
			);
		}
		else
		{
			$orderHistory::addLog(
				'BASKET',
				$basket->getOrderId(),
				"BASKET_ITEM_ADD",
				$this->getId(),
				$this,
				$logFields,
				$orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
			);

			$orderHistory::addAction(
				'BASKET',
				$basket->getOrderId(),
				"BASKET_SAVED",
				$this->getId(),
				$this,
				[],
				$orderHistory::SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
			);
		}
	}

	return $result;
}