For use case where cart quantity-based discounts apply, but only if a coupon is not being used. I've added a condition to the quantity-based discounts so that they only apply if the condition (see patch) evaluates as TRUE (i.e. order has coupon line item, negated).

This condition is closely based on a similar condition in commerce_shipping.

The 'any' option works but I haven't tested the option for a specific coupon code.

Members fund testing for the Drupal project. Drupal Association Learn more


pcambra’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Status: Active » Needs work

All changes should be applied using the latest -dev version.

You could do this with "commerce_coupon_action_get_coupons_for_order" already existing action, right?

pcambra’s picture

Status: Needs work » Closed (won't fix)

Closing this as you can now get the coupons referenced in an order and you can use something like "Fetch entity by property" which is in Rules itself


jonathan_hunt’s picture

Status: Closed (won't fix) » Active

I've reopened this as I've tried to implement my existing rule using your suggestion but without success. I can test for existence of a Commerce line item with Property=Type and Value=Coupon but that seems to apply across all orders not just the order being evaluated. My current rule is triggered when Calculating the sell price of a product, and it works by applying a tax rate that discounts the price if (say) the line item quantity is 30 or more. The patch above makes it easy to disallow the quantity discount if a coupon is present.

If the patch above is not the solution, I'd appreciate a specific worked example that demonstrates how to achieve the outcome described.

pcambra’s picture

Status: Active » Closed (won't fix)

Same answer than in #1649390: Remove Coupon if Eligible Product is Removed

Now the coupons applied to an order are available with an entity reference field, this means that you can take the order element and with entity has field you can pull the reference field (commerce_coupon_order_reference) and then use the "List has item" comparation from rules.

As I said in the issue above, I'm up for adding a direct condition "Coupon has been applied to order" to simplify this. Patches are welcome.

jonathan_hunt’s picture

Status: Closed (won't fix) » Needs review
1.67 KB

Attached patch implements a simple condition "Coupon has been applied to order".

pcambra’s picture

Status: Needs review » Needs work

Ok, some thoughts on review:

It seems that patch is generated from "all" folder, please reroll it from the module folder.

* Variant of patch at
No need to specify the issue number

'label' => t('Coupon has been applied to order'),
Not sure what's the target of this patch, looking at the code, I'd say that this is more a "Any coupon has been applied to the order", is this rule really useful or you were looking more for a "An specific coupon has been applied to the order"?

function commerce_coupon_rules_line_item_exists($order, $coupon) {
Coupon is specified here, but not declared as parameter in the condition.

jonathan_hunt’s picture

Status: Needs work » Needs review
1.57 KB

Revised patch: rerolled from commerce_coupon dir, no ref to issue, dropped coupon parameter.
This rule targets whether a coupon has been redeemed on an order. A future patch could allow for targeting a specific coupon id.

dopry’s picture

see for a patch to add a conditional to check if a specific coupon has been applied to an order.

pcambra’s picture

Status: Needs review » Needs work
+++ b/
@@ -47,6 +47,50 @@ function commerce_coupon_rules_event_info() {
+ * Variant of patch at

No need to inform the issue in the module

+++ b/
@@ -47,6 +47,50 @@ function commerce_coupon_rules_event_info() {
+    'label' => t('Coupon has been applied to order'),

We need to improve the wording here, "Any coupon has been applied to the order"?

+++ b/
@@ -47,6 +47,50 @@ function commerce_coupon_rules_event_info() {
+  if (count($order_wrapper->commerce_coupon_order_reference) > 0) {

Coupons may have status, so maybe an entity field query or a new api function makes sense here

davidwhthomas’s picture

Status: Needs work » Needs review
1.72 KB


I actually added this functionality to a recent project.

Here's a simple patch attached, very similar to the patch already in progress.

It provides a rules condition to check for the existence of a coupon on an order. ( i.e any coupon, not specific coupon )

Ready for review.



illmatix’s picture

Great thanks for the patch Dekita. Although we can't seem to apply it to our version of the file. We tried to manually patch it but with similar luck.

davidwhthomas’s picture

Thanks Illmatix, patch was rolled against latest -dev, so that may be your issue there.
If running an older version, may need manual patching.

illmatix’s picture

We tried the dev version and then tried manually patching it but it was throwing errors on line 221. assigning a value to a method and the second was something about a Reflection error. Both i didn't know enough of to figure out.

davidwhthomas’s picture

Illmatix, you mean the patch applied but got a PHP error? or was it a problem applying the patch itself.

davidwhthomas’s picture

Here's an adjusted patch that removes the isset() on the ->raw() in case that was the issue there.

The code I used actually just had

 * Rules condition callback
 * Check if coupon is set on order
 * i.e check commerce_coupon_reference field not empty
function commerce_coupon_order_has_coupon($order){
  if (empty($order->commerce_coupon_order_reference[LANGUAGE_NONE][0]['target_id'])) {
    return FALSE;
    // Field is set, has coupon
    return TRUE;

but probably better to use the order_wrapper, as per the patch, to provide better multi-language support in the check there.