Discussions

Force 1 product per cart and quantity to one

Hello,

i'm trying to add a rule to my drupal commerce install. i need to force 1 product per cart, with max quantity = 1.

I tried:

Event: Before adding a product to the cart
Conditions : Elements: Total product quantity comparison Parameter: Order: [commerce_order] => Quantity >=1

and that's working smoothly.

But i can't find a rule to deny adding product to the cart. Already tried

Set a data value:
Selected data: commerce-order:commerce-line-items:1:quantity = 0

but it is not working. Just
Remove all products from an order
Parameter: Order to empty: [commerce_order]

works, but i'd like to remove the second product added, not the first one :)

thanks!

Posted: Jun 8, 2012

Comments

FINeX on September 17, 2012

Hi, you can create a rule to empty the cart before adding a product, moreover you can disable the qty field on cart and on the product page.

The rule I'm using is:

{ "rules_empty_cart" : {
    "LABEL" : "Empty cart",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_cart" ],
    "ON" : [ "commerce_cart_product_prepare" ],
    "DO" : [
      { "commerce_cart_empty" : { "commerce_order" : [ "commerce_order" ] } }
    ]
  }
}
drupalcommerce Check out the #Drupal Commerce 2.x Roadmap to see where you can get involved: http://t.co/WAc3jmXY2a
drupalcommerce A new blog discussing the new showcase listing http://t.co/FHOzhAg3tl http://t.co/J5C87imjhb
drupalcommerce RT @drupalcon: Thanks @CommerceGuys and @CommerceJohn for your support, and for #CommerceKickstart! Take the tour http://t.co/ivKEYH7k0o
drupalcommerce Updating our extensions directory: 665 new or updated modules, distributions, sandboxes, & themes. http://t.co/6NMMofYo12 #weloveyouguys