protected function LicenseMultiplesCartEventSubscriber::forceOrderItemQuantity in Commerce License 8.2
Forces the quantity of an order item to 1, and saves it.
Parameters
\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.
2 calls to LicenseMultiplesCartEventSubscriber::forceOrderItemQuantity()
- LicenseMultiplesCartEventSubscriber::onCartEntityAdd in src/
EventSubscriber/ LicenseMultiplesCartEventSubscriber.php - Enforces the maximum count when a product is added to the cart.
- LicenseMultiplesCartEventSubscriber::onCartItemUpdate in src/
EventSubscriber/ LicenseMultiplesCartEventSubscriber.php - Enforces the maximum count when an item is updated.
File
- src/
EventSubscriber/ LicenseMultiplesCartEventSubscriber.php, line 112
Class
- LicenseMultiplesCartEventSubscriber
- Ensures only 1 of each license may be added to the cart.
Namespace
Drupal\commerce_license\EventSubscriberCode
protected function forceOrderItemQuantity(OrderItemInterface $order_item) {
// Force the quantity back to 1.
$order_item
->setQuantity(1);
// Save the order item again.
$order_item
->save();
}