1

I have a site where the owners want to stop customers from ordering more than 1 type of item.

The Twig logic is already in place to stop any forms showing that would allow customers adding more than type, which is fine for when navigating between pages. If a customer opens a product on several tabs, they can add multiples of the product.

I had gone through the route listening for the EVENT_BEFORE_ADD_LINE_ITEM, but I think this isn't occurring as once a product is added to the cart any further products of this type aren't new line items, they are quantity changes.

Is there an event to listen to for quantity changes for the cart?

1
  • I'm guessing that you meant to write that you want to stop customers from ordering more than 1 of a single type of item, right? From the first paragraph of your question, I thought you were saying that an order must consist of only one line item, but that line item can have any quantity. Nov 24, 2023 at 4:05

2 Answers 2

2

I might be misunderstanding your situation, but Commerce has built-in min/max "Allowed Quantity" per product (per variant technically) here: enter image description here

Limiting that to 1 max will prevent more from being added to the cart. You'll just need to handle error messages at your end, naturally.

1
  • Talk about overthinking the issue! I thought it would have to be done in code. I'll keep that in mind, but I think in this site's case the owners may not like the idea of going through every variant to set a max.
    – Jaytrix
    Nov 23, 2023 at 15:34
1

I found a coded solution using EVENT_BEFORE_SAVE_LINE_ITEM

... but I think @JamesSmith's answer would be the ideal solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.