1

I’m using the Digital Products plugin to sell licenses so that users are listed on the site for a certain amount of time.

The options are something like "buy 3 month", "buy 6 month" etc. You see, the concept of the cart doesn’t really apply here. There would be no point in buying "3 month" twice.

That’s why I’d like to set the items in the cart always to the quantity of 1. Even better would be if I could empty the cart each time a product is added to the cart. That’s because people are supposed to select between the given options, not buying several options at once or multiple times.

Any hints?

2

You should be able to handle this with some logic in a plugin listening to events like:

https://craftcommerce.com/docs/events-reference#commerce_cart.onbeforeaddtocart

The parameters for this include both the order as it stands, and the lineItem being added to the cart, which gives you the opportunity to manipulate both. You could clear the order, and chec the qty of the lineitem being added is 1 at this point (and change it if needed).

Obviously it would be good to have some front end stuff in place limiting the quantity to 1 as well.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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