/** * @param Sale\ShipmentCollection $shipmentCollection * * @return Sale\Shipment * @throws Main\ArgumentNullException */ public static function createShipmentFromShipmentSystem(Sale\ShipmentCollection $shipmentCollection) { $shipment = null; /** @var Sale\Shipment $systemShipment */ $systemShipment = $shipmentCollection->getSystemShipment(); if ($systemShipment->getDeliveryId() > 0) { /** @var Sale\Shipment $shipment */ $shipment = static::getShipmentByDeliveryId($shipmentCollection, $systemShipment->getDeliveryId()); if (!$shipment) { if ($service = Sale\Delivery\Services\Manager::getService($systemShipment->getDeliveryId())) { /** @var Sale\Shipment $shipment */ $shipment = $shipmentCollection->createItem($service); $shipment->setField('DELIVERY_NAME', $service->getName()); } } } return $shipment; }