public function CartSubscriber::onCartEmpty in Commerce Shipping 8.2
Remove shipments from an emptied cart.
The order refresh does not process orders which have no order items, preventing the shipping order processor from removing shipments.
@todo Re-evaluate after #3062594 is fixed.
Parameters
\Drupal\commerce_cart\Event\CartEmptyEvent $event: The event.
File
- src/
EventSubscriber/ CartSubscriber.php, line 51
Class
Namespace
Drupal\commerce_shipping\EventSubscriberCode
public function onCartEmpty(CartEmptyEvent $event) {
$cart = $event
->getCart();
if (!$this->shippingOrderManager
->hasShipments($cart)) {
return;
}
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface[] $shipments */
$shipments = $cart
->get('shipments')
->referencedEntities();
foreach ($shipments as $shipment) {
$shipment
->delete();
}
$cart
->set('shipments', []);
}