You are here

public function OrderItemSubscriber::onOrderItemUpdate in Commerce Shipping 8.2

Force repack/rates recalculation when quantity is updated.

Parameters

\Drupal\commerce_order\Event\OrderItemEvent $order_item_event: Order item event.

File

src/EventSubscriber/OrderItemSubscriber.php, line 45

Class

OrderItemSubscriber

Namespace

Drupal\commerce_shipping\EventSubscriber

Code

public function onOrderItemUpdate(OrderItemEvent $order_item_event) {
  $order_item = $order_item_event
    ->getOrderItem();
  $order = $order_item
    ->getOrder();
  if (!$order || !$this
    ->shouldRefresh($order)) {
    return;
  }
  if ($order_item
    ->getQuantity() !== $order_item->original
    ->getQuantity()) {
    $order
      ->setData(ShippingOrderManagerInterface::FORCE_REFRESH, TRUE);
  }
}