I have coupon that validate if a minimum order amount is reached. I used a new field and a rule, it works ok in checkout, but after redeem the coupon, the user can change product quantity (in other browser tab) and the validation doesn't be called again. I tried to delete coupons in order when line items changed but the order doesn't have coupons referenced in that instance (Event: Line items add/update/delete). Can you tell me how we can ensure the cart isn't changed after coupon is added or delete coupons if cart changes.

Thanks!

Comments

Just chiming in to mention that I have this same issue. Created a field for minimum order amount and a validation rule that works great initially. But after you start checkout, you can go back to the cart and remove products or change quantities until the order amount goes lower than the minimum, and the coupon still applies.

It seems that validation should fire for all existing coupons when line items are changed as the OP indicates.

same issue, this seems like a deal breaker.

subscribing

Status:Active» Postponed

This is not simple business here, you probably need to implement that yourself using hook_commerce_order_refresh and invoking the rule event validation again there... hopefully in the 2.x version we can properly fix this with commerce discount.

If someone wants to take a look there and do a backport we can bring this back to live.

You can achieve this with rules, it's pretty straightforward actually.

just create a rule that fires whenever a line item gets updated or removed and call the coupon validation again...

(should be built in, but we're developers after all...)

(should be built in, but we're developers after all...)

Patches are welcome

Patch attached to revalidate all coupons on hook_commerce_cart_order_refresh and remove invalid ones.

The patch uses a new function commerce_coupon_code_is_still_valid() which is identical to commerce_coupon_code_is_valid() but without the check for existing coupons on the order (as we're not adding a new one and all codes we're checking should be on the order). This probably needs tidying up later to reduce duplication but one step at a time.

Status:Postponed» Needs review

Oops, forgot to update status.

Version:7.x-1.0-beta6» 7.x-1.x-dev
Category:bug» task
Priority:Critical» Normal
Status:Needs review» Needs work

Wow, amazing effort, thanks! Moving this to task as it seems something we would need.

So, reviewing the patch, it's a great start and the hook used seems correct, even though we could evaluate the possibility of using hook_commerce_order_presave instead.

Removing seems fine, but what the patch doesn't do is update the value of the coupon, what is needed here is IMHO what commerce discounts do in the refresh hook, first it loops all the line items and remove all the price components related with discounts, then the line items and then reattaches the discounts related with the order.

Confirming that the patch in #6 works. Thanks.