• Модуль: salescenter
  • Путь к файлу: ~/bitrix/modules/salescenter/lib/controller/order.php
  • Класс: BitrixSalesCenterControllerOrder
  • Вызов: Order::createShipmentAction
public function createShipmentAction(array $basketItems = array(), array $options = [])
{
	if ((int)$options['orderId'] <= 0 && CrmManager::getInstance()->isOrderLimitReached())
	{
		$this->addError(
			new MainError('You have reached the order limit for your plan')
		);

		return [];
	}

	$basketItems = VatRate::prepareTaxPrices($basketItems);
	$basketItems = $this->processBasketItems($basketItems);

	$options['basketItems'] = $basketItems;
	$options['withoutPayment'] = true;

	$isEnabledAutomaticReservation = SaleConfiguration::isEnableAutomaticReservation();
	if ($isEnabledAutomaticReservation)
	{
		SaleConfiguration::disableAutomaticReservation();
	}

	/** @var CrmOrderOrder $order */
	$order = $this->buildOrder(
		$options,
		[
			'builderScenario' => SalescenterBuilderSettingsContainer::BUILDER_SCENARIO_SHIPMENT,
			'orderErrorsFilter' => [
				'SALE_BASKET_AVAILABLE_QUANTITY',
				'SALE_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY',
			],
		]
	);
	if ($order === null)
	{
		// if throw error not in 'orderErrorsFilter'
		if ($this->errorCollection->count() === 0)
		{
			$this->addError(
				new Error(Loc::getMessage('SALESCENTER_CONTROLLER_ORDER_CANT_BUILD_ORDER'))
			);
		}

		return [];
	}

	$shipment = $this->findNewShipment($order);

	$result = $order->save();

	if ($isEnabledAutomaticReservation)
	{
		SaleConfiguration::enableAutomaticReservation();
	}

	if ($result->isSuccess())
	{
		$dealId = 0;

		if ($shipment)
		{
			$binding = $order->getEntityBinding();

			if ($binding)
			{
				$dealPrimaryContactId = $this->getDealPrimaryContactId($binding->getOwnerId());
				if ($dealPrimaryContactId)
				{
					$this->tryToFillContactDeliveryAddress($dealPrimaryContactId, $shipment->getId());
				}

				$productManager = new CrmOrderProductManager($binding->getOwnerTypeId(), $binding->getOwnerId());
				$productManager->setOrder($order)->syncOrderProducts($basketItems);
			}

			$this->saveDeliveryAddressFrom($shipment->getId());
		}

		return [
			'order' => [
				'number' => $order->getField('ACCOUNT_NUMBER'),
				'id' => $order->getId()
			],
			'deal' => $this->getDealData((int)$dealId)
		];
	}
	else
	{
		$this->addErrors($result->getErrors());
	}

	return [];
}