protected function XquantityStockOrderEventSubscriber::updateStock in Commerce Extended Quantity 8
Calls xquantity_stock availability checker to update the entity stock.
Parameters
\Drupal\commerce_order\Entity\Order $order: The commerce order.
\Drupal\commerce_order\Entity\OrderItem $order_item: The commerce order item.
bool $delete: Whether the order item is going to be deleted.
4 calls to XquantityStockOrderEventSubscriber::updateStock()
- XquantityStockOrderEventSubscriber::onOrderCancel in modules/
xquantity_stock/ src/ EventSubscriber/ XquantityStockOrderEventSubscriber.php - Performs a stock transaction for an order Cancel event.
- XquantityStockOrderEventSubscriber::onOrderDelete in modules/
xquantity_stock/ src/ EventSubscriber/ XquantityStockOrderEventSubscriber.php - Performs a stock transaction on an order delete event.
- XquantityStockOrderEventSubscriber::onOrderItemDelete in modules/
xquantity_stock/ src/ EventSubscriber/ XquantityStockOrderEventSubscriber.php - Returns quantity to the stock when an order item is deleted.
- XquantityStockOrderEventSubscriber::onOrderItemUpdate in modules/
xquantity_stock/ src/ EventSubscriber/ XquantityStockOrderEventSubscriber.php - Performs a stock transaction on an order item update.
File
- modules/
xquantity_stock/ src/ EventSubscriber/ XquantityStockOrderEventSubscriber.php, line 141
Class
- XquantityStockOrderEventSubscriber
- Commerce order event subscriber.
Namespace
Drupal\xquantity_stock\EventSubscriberCode
protected function updateStock(Order $order, OrderItem $order_item, $delete = FALSE) {
$state = $order
->getState()->value;
if ($state != 'canceled' && $state != 'completed') {
$quantity = $delete ? '0' : $order_item
->getQuantity();
$old = $delete ? $order_item
->getQuantity() : $order_item->original
->getQuantity();
$context = new Context($this->currentUser, $order
->getStore(), time(), [
'xquantity' => $delete ? 'delete' : 'update',
'old' => $old,
]);
$result = $this->availabilityManager
->check($order_item, $context, $quantity);
if ($result
->isUnavailable()) {
throw new \InvalidArgumentException("The quantity {$quantity} to update on the {$order_item->getTitle()} order item is not available on the stock.");
}
}
}