0

I am trying to figure out a way to set a maximum quantity at the product level instead of on the individual variants.

The specific use case is selling tickets to events, where my client needs to be able to limit the maximum amount of tickets they can sell for a given event. However, each event can have multiple variants (full ticket, student ticket, etc.).

My current solution uses a custom number field on the product, and then I simply query all completed orders and count how many times the specific variant has been sold. But this seems very hacky and has a lot of potential edge cases.

I am somewhat new to Commerce so I might be missing something obvious, but I haven't been able to find anything in the documentation.

Any suggestions?

4
  • Just to clarify, are you talking about the maximum that can be bought in a single transaction, or are you talking about the total stock? (i.e., the maximum that can be bought across the whole store?). Commerce has two different fields for managing those things, but as you have noticed, if a product is configured to have variants, both those fields are held at the variant level instead of the product level. Commented Aug 4, 2022 at 16:05
  • @JamesSmith The latter. I want to limit the total stock across all variants for a given product. For example a product could be a ticket to an event, and I want to set a hard limit of 500 regardless of the combination of variants sold.
    – Peter U
    Commented Aug 4, 2022 at 17:16
  • I'm fairly sure Commerce doesn't provide anything out of the box for your use case unfortunately. It'd make a good feature request though, or a custom plugin. Commented Aug 5, 2022 at 10:13
  • @JamesSmith Thank you for taking the time. I solved this by creating a custom module that prevents lineitems from being added or sold if it exceeds the maximum allowed.
    – Peter U
    Commented Aug 8, 2022 at 12:18

0

Your Answer

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

Browse other questions tagged or ask your own question.