• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/shipmentcollection.php
  • Класс: BitrixSaleShipmentCollection
  • Вызов: ShipmentCollection::calculateDelivery
public function calculateDelivery()
{
	/** @var Result $result */
	$result = new Result();

	$calculatedDeliveries = [];

	$collection = $this->getNotSystemItems();

	/** @var Shipment $shipment */
	foreach ($collection as $shipment)
	{
		if ($shipment->getDeliveryId() == 0)
			continue;

		if ($shipment->isCustomPrice())
		{
			$priceDelivery = $shipment->getPrice();

			$calcResult = new DeliveryCalculationResult();
			$calcResult->setDeliveryPrice($priceDelivery);
		}
		else
		{
			/** @var DeliveryCalculationResult $calcResult */
			$calcResult = $shipment->calculateDelivery();
			if (!$calcResult->isSuccess())
			{
				$result->addErrors($calcResult->getErrors());
				continue;
			}

			$priceDelivery = $calcResult->getPrice();
			if ($priceDelivery < 0)
			{
				$result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_WRONG_DELIVERY_PRICE'), 'WRONG_DELIVERY_PRICE'));
				continue;
			}
		}

		$priceDelivery = PriceMaths::roundPrecision($priceDelivery);
		$shipment->setField('BASE_PRICE_DELIVERY', $priceDelivery);

		$calculatedDeliveries[] = $calcResult;
	}

	$result->setData(['CALCULATED_DELIVERIES' => $calculatedDeliveries]);

	return $result;
}