public function ShippingOrderManager::pack in Commerce Shipping 8.2
Packs the given order into shipments.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order.
\Drupal\profile\Entity\ProfileInterface $profile: The shipping profile.
Return value
\Drupal\commerce_shipping\\Entity\ShipmentInterface[] The unsaved shipments.
Overrides ShippingOrderManagerInterface::pack
File
- src/
ShippingOrderManager.php, line 106
Class
Namespace
Drupal\commerce_shippingCode
public function pack(OrderInterface $order, ProfileInterface $profile = NULL) {
if (!$profile) {
$profile = $this
->getProfile($order) ?: $this
->createProfile($order);
}
$shipments = $order
->get('shipments')
->referencedEntities();
list($shipments, $removed_shipments) = $this->packerManager
->packToShipments($order, $profile, $shipments);
// Delete any shipments that are no longer used.
if (!empty($removed_shipments)) {
$shipment_storage = $this->entityTypeManager
->getStorage('commerce_shipment');
$shipment_storage
->delete($removed_shipments);
}
return $shipments;
}