Questions? Answers.

1
Answers
Vote up!
0
Vote down!

How to stop default commerce coupon error message?

Hi all,

I'm currently in the middle of implementing commerce coupon on my site, along with commerce_coupon_pct (Percentage coupons).

My main goal was to set up a rule that would make sure only one coupon could be applied to any individual order.

Using the rule and the rules component provided in comment #6 on https://drupal.org/node/1538158 I have been successful in getting that functionality set up on my shop.

However, the following scenario occurs. If a user tries to enter a second (different) coupon, the receive the error message output in the rule "Sorry, the maximum number of coupons for this order has been reached." However, a second message "Sorry, your coupon is not valid" is also output.

I find this misleading, because although the coupon can't be applied due to the presence of another coupon, the coupon isn't actually invalid, e.g. if they wanted to use it on another order they could. There's a global variable called $_commerce_coupon_validation_error_message, and it is because this is not set that the default message of "Your coupon is not valid" appears (when you submit the coupon form it uses AJAX to reload the form and perform validation on the actual form creation, not in the validate hook so form_alter is not appropriate). I have tried setting this variable as part of the rule being used but had zero success. From Googling and reading various things it appears setting global variables through Rules is not particularly straight forward. Does anyone have any ideas? I've been trying to sort this for days and it is driving me mad.

Asked by: JeebsUK
on December 20, 2013

1 Answer

Vote up!
0
Vote down!

JeebsUK,

Pretty sure you would need a custom module that could re-write the status messages. It's almost never a good idea to try and control a global variable per-session.

Josh

Answer by: joshmiller
Posted: Jan 2, 2014