public function OrderSubscriber::onFulfill in Commerce Shipping 8.2
Ships the order's shipments when the order is fulfilled.
Parameters
\Drupal\state_machine\Event\WorkflowTransitionEvent $event: The transition event.
File
- src/
EventSubscriber/ OrderSubscriber.php, line 120
Class
Namespace
Drupal\commerce_shipping\EventSubscriberCode
public function onFulfill(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event
->getEntity();
if (!$this->shippingOrderManager
->hasShipments($order)) {
return;
}
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
foreach ($order
->get('shipments')
->referencedEntities() as $shipment) {
if (!$shipment
->getState()
->isTransitionAllowed('ship')) {
continue;
}
$shipment
->getState()
->applyTransitionById('ship');
$shipment
->save();
}
}