Problem/Motivation

User attempts to redeem coupons may fail because the associated discount condition fails.

Today this results in a generic error "Unable to redeem coupon" that offers no guidance as to what the user should do.

This is a usability and customer service problem.

Proposed resolution

CAUSE:

commerce_coupon_pane_checkout_form() checks drupal_static('commerce_coupon_error_' . strtolower($code)). That's fine for coupon conditions where the coupon code is known, and the appropriate commerce_coupon_error_X can be set. Discount conditions have no idea which particular coupon code triggered them, so they cannot set this static variable.

PROPOSED RESOLUTION:

Have commerce_coupon_pane_checkout_form() also check drupal_static('commerce_coupon_error_discount_conditions'), a new static variable that can be set by discount conditions if they want to expose more specific (and more helpful) error information to users.

Comments

josephr5000 created an issue. See original summary.

josephr5000’s picture

Title: No way for discount conditions to provide helpful error messages if they fail and prevent coupon redemption » No way for discount conditions to provide helpful error messages if they fail and prevent "apply coupon" action
Issue summary: View changes
josephr5000’s picture

StatusFileSize
new922 bytes
josephr5000’s picture

Status: Active » Needs review
josephr5000’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Category: Bug report » Feature request

Reconsidered: this is probably more accurately filed as a feature request than as a bug.

deggertsen’s picture

I agree with this. I definitely think we need more options for customization of coupon errors.

rar’s picture

I agree this is needed.

It would be nice for clients, when creating a coupon, to have the ability to type in an error message that is displayed when the coupon's conditions don't match but someone tries it anyway. Something like "I'm sorry - this coupon is only for when you have more than 30 widgets in the cart "

rar’s picture

I've looked into this quite a bit more (7.x-2.0). The error messages are generated by

$error = &drupal_static('commerce_coupon_error_' . strtolower($coupon->code));

As part of the function commerce_coupon_commerce_cart_order_refresh().

Following the logic you get to commerce_coupon_evaluate_conditions
which calls drupal_alter which allows you to use

HOOK_commerce_coupon_condition_outcome_alter

Unfortunately there are a few issues which prevent being able to use HOOK_commerce_coupon_condition_outcome_alter

1. $outcome = rules_invoke_component('coupon_type_' . $coupon_wrapper->type->value() . '_conditions', $coupon_wrapper, $order_wrapper, $data); always returns TRUE no matter what.

2. commerce_coupon_commerce_cart_order_refresh gets called several times even if not actually adding the coupon. So .you can generate the static error message. Unfortunately if you add $error = &drupal_static('commerce_coupon_error_' . strtolower($coupon->code)); early, then other logic in the commerce_coupon module will cause adding of the coupon to fail with that error message even if the coupon should have been added.

Ran into a wall and out of time to look into this more.