Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For DrupalCon sites, we want to limit people to buying one ticket per person. (If you want more, prepaid tickets can be bought in bulk, and then handed to the actual people for registration.) If someone already has a registration, we can use rules to alert users to their status on the product page, and remove the item from the cart as it is added. But we can't disable or replace the actual button. If someone misses the status message and clicks, it isn't great UI.
I think there should be a rules action to achieve this.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1909098.add_to_cart_availability.patch | 754 bytes | rszrama |
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedI'm pretty sure this is already works as is, so let me throw out a solution and see if it works for you:
The product pricing system currently answers two questions (we'll be splitting these out to separate events in D8): does the product have a valid sale price for the current user right now? and what is that sale price? By unsetting the unit price amount in a pricing rule, you're basically telling Commerce that the product does not have a valid sale price, and it will unset the button on the Add to Cart form accordingly.
Step 2 ensures that this only happens on the Add to Cart form, not for products already in a shopping cart. I can't recall exactly how this works for product displays unfortunately, so lemme know if it screws up pricing somewhere on the page. For an example of this, look at the default product pricing rule titled "Unset the price of disabled products in the cart."
Comment #2
drummI did try that, but without step 2. In
commerce_cart_add_to_cart_form()
hascommerce_product_calculate_sell_price()
returnsIt does blank out the amount, but doesn't make the price data structure null, which would disable the button.
I tried adding step 2, but I think there isn't a line item yet on viewing a product page, so line-item-id is empty.
I'm testing with commerce 1.4, is this something that has changed in 1.x-dev?
Comment #3
rszrama CreditAttribution: rszrama commentedSorry, I instructed you backwards on Step 2. I was copying the condition from the default rule that only should operate on products in the shopping cart, not products on an Add to Cart form. If you un-negate it, does it work as expected?
Comment #4
drummNo, I tried negated, un-negated, and without the condition. None disables the add to cart button.
Comment #5
rszrama CreditAttribution: rszrama commentedI'm not sure I realized we had this inconsistency between the Add to Cart form and shopping cart refresh process. Pretty clear we need the if statements to match, this being the one from the cart refresh process:
Can you test the attached patch? I think it'll fix this for ya and I can get it in for 1.5.
Comment #6
rszrama CreditAttribution: rszrama commented(Updating for test bot.)
Comment #7
drummLooks good!
Comment #8
rszrama CreditAttribution: rszrama commentedGreat, thanks for the test, Neil. Glad it worked. : )
Comment #10
tahiticlic CreditAttribution: tahiticlic commentedA bit late, but solution using Rules only :
It's not an answer to the question though, since it doesn't stop the add to cart. So you still have the "your product has been added to cart" :-(