• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Reservation/Actions/ProcessInventoryManagement.php
  • Класс: Bitrix\Crm\Reservation\Actions\ProcessInventoryManagement
  • Вызов: ProcessInventoryManagement::ship
private function ship(Crm\Item $item): Main\Result
{
	$entityBuilder = new Crm\Reservation\Entity\EntityBuilder();
	$entityBuilder
		->setOwnerTypeId($item->getEntityTypeId())
		->setOwnerId($item->getId())
	;

	$productRows = [];

	$itemProductRows = $item->getProductRows();
	if ($itemProductRows)
	{
		/** @var Crm\ProductRow $productRow */
		foreach ($itemProductRows as $productRow)
		{
			$productRows[$productRow->getId()] = $productRow->toArray();
		}
	}

	$basketReservation = new Crm\Reservation\BasketReservation();
	$basketReservation->addProducts($productRows);
	$reservationMap = $basketReservation->getReservationMap();

	$defaultStore = Catalog\StoreTable::getDefaultStoreId();
	foreach ($productRows as $product)
	{
		$storeId = (int)$product['STORE_ID'] > 0 ? (int)$product['STORE_ID'] : $defaultStore;

		$xmlId = null;
		if (isset($reservationMap[$product['ID']]))
		{
			$basketReservationData = Sale\Reservation\Internals\BasketReservationTable::getById(
				$reservationMap[$product['ID']]
			)->fetch();
			if ($basketReservationData)
			{
				$basketItem = Sale\Repository\BasketItemRepository::getInstance()->getById(
					$basketReservationData['BASKET_ID']
				);
				if ($basketItem)
				{
					$xmlId = $basketItem->getField('XML_ID');
				}
			}
		}

		$entityBuilder->addProduct(
			new Crm\Reservation\Product($product['ID'], $product['QUANTITY'], $storeId, $xmlId)
		);
	}

	$entity = $entityBuilder->build();

	return (new Crm\Reservation\Manager($entity))->ship();
}