In my website I would like to limit product quantity to 1, meaning is that user can order only one of a product in one order. And my question is how to configure to set maximum quantity to 1 . Any suggestion is greatly appreciated.


3 Answers 3


You can achieve this using Rules by following steps given below:

Event: After udpdating an already existing line item

Conditions: 1/ data comparison: commerce-line-item:type = product 2/ data comparison: commerce-line-item:commerce-product:type = Your given product type 3/ data comparison: commerce-line-item:quantity is greater than 1

Action: - set data value: commerce-line-item:quantity 1 - display custom message

Reference: https://drupalcommerce.org/questions/8066/how-limit-maximum-quantity-1-one-given-product-type

  • - display custom message does not find in action, I am stuck on -display custom message. thanks
    Apr 6, 2015 at 7:30
  • Its under System as Show a message on the site Apr 6, 2015 at 7:37

I found this link, it is very simple. http://bonify.io/blog/2014/09/limit-quantity-when-adding-product-cart

  1. Events
    • Before saving a commerce line item
  2. condition

    • Entity is of bundle

      data selector: commerce-line-item, value: product

    • Data comparison

      Data to compare : commerce-line-item:commerce-product:product-id, operator: equal, Value:1

  3. Action

    • set a data value

      data: commerce-line-item:quantity, value: 1

    • Save Entity

      Data selector: commerce-line-item,

    • Show a message on the site

      Message: This product only available for 1., Value: warning

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
    – bummi
    Apr 6, 2015 at 8:54

October 2022: Running Commerce Core on Drupal 7

So I struggled with this. On my website we sell digital products so the quantity never needed to be larger than one. I tried using spinners to prevent double clicking on the "Add to Cart" buttons but somehow users still found ways to double click. I still don't know how but they did. I started my solution from trying to follow the drupal commerce user guide.


The problem I ran into was that when I tried to set the condition to

commerce-line-item:quantity > 1 it tried to force me to use data selectors which doesn't give me any value option.

The only thing I could do was set

commerce-line-item:quantity = 2 and then the routine would work. But if someone triple and went really crazy with the clicks this would not work because the QTY would get to three before the rule would finish firing. I then tried adding more conditions in an OR statement but found the performance of the rule was unreliable even in non stress situations. THEN THE EUREKA MOMENT.

I didn't need any condition since everything on my website is to be set to 1. So no product type conditions, no pre-existing quantity conditions, etc... needed to be checked.

So here is what appears to be working for me. I'll come back and edit this if it fails at any point.

  1. Create new Rule
  2. Set Event to "After adding a product to the cart"
  3. Set Actions to
    1st Action: Set a Data Value commerce-line-item:quantity = 1 2nd Action: Set Save Entity commerce-line-item:order I left "Force Immediate Save to false (or unchecked).

Comments: On my website you must be logged in to make a purchase. It appears to work for regular registered users and the admin role. I'll come back and update if I have any new problems with this running. What this routine does is make sure that after the user has finally stopped clicking the "Add to Cart" button, line item quantity is set back to 1 and the cart is recalculated. I imagine it increases the "Add to Cart" time a little bit. But it should be worth it not to have calls from people that didn't realize they had overpaid because they added the product to the cart twice. I'm a bit surprised but it happens all the time. Especially on my website cause when I was on drupal 6 I used a different commerce solution and forcing a quantity of 1 was already coded in. So many customers never bothered to check.

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.