You are here

public function XquantityStockOrderEventSubscriber::onOrderItemDelete in Commerce Extended Quantity 8

Returns quantity to the stock when an order item is deleted.

Parameters

\Drupal\commerce_order\Event\OrderItemEvent $event: The order item event.

File

modules/xquantity_stock/src/EventSubscriber/XquantityStockOrderEventSubscriber.php, line 123

Class

XquantityStockOrderEventSubscriber
Commerce order event subscriber.

Namespace

Drupal\xquantity_stock\EventSubscriber

Code

public function onOrderItemDelete(OrderItemEvent $event) {
  $order_item = $event
    ->getOrderItem();

  // Do not run on order delete event as the order don't exist there.
  if ($order = $order_item
    ->getOrder()) {
    $this
      ->updateStock($order, $order_item, TRUE);
  }
}