Are coupon expirations and relationships on the roadmap? It would be great to be able to have them expire after a campaign period. Additionally, it would be great to be able to limit the coupon to certain products.

Is this in the works or is it possible now via rules?

Files: 

Comments

Version:7.x-1.0-beta4» 7.x-1.x-dev

Limiting the coupon to certain products => #1377318: Applying coupon to specific product.

Expiration would be a new date field and rules scheduler, I'll try to put together an example

StatusFileSize
new21.51 KB
new22.66 KB

Surprisingly easy if you are familiar w/ the new Rules interface.

Screenshots attached.

1) Add date field to Coupon entity
2) Create new rule according to attached picture #2

Assigned:aaronortega» Unassigned

FYI, I expanded on @drastik's suggestion: added a date field (field_valid_during) to a coupon that included an end date (defining a duration or period). I created two rules coupon validity checking rules: one testing for the start of the period and one testing the end of the period; the message shown for each one can be distinct. Rules pasted below:

{ "rules_coupon_validation_check_period_start" : {
    "LABEL" : "Coupon validation: Check period start",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "coupon" ],
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "field_valid_during" } },
      { "data_is" : {
          "data" : [ "coupon:field-valid-during:value" ],
          "op" : "\u003E",
          "value" : [ "site:current-date" ]
        }
      }
    ],
    "DO" : [
      { "commerce_coupon_action_is_invalid_coupon" : [] },
      { "drupal_message" : {
          "message" : "Sorry, coupon [coupon:commerce-coupon-code] can not be used at this time. Please try after [coupon:field-valid-during:value].",
          "type" : "error"
        }
      }
    ]
  }
}

and
{ "rules_coupon_validation_check_period_end" : {
    "LABEL" : "Coupon validation: Check period end",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "coupon" ],
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "field_valid_during" } },
      { "data_is" : {
          "data" : [ "coupon:field-valid-during:value2" ],
          "op" : "\u003C",
          "value" : [ "site:current-date" ]
        }
      }
    ],
    "DO" : [
      { "commerce_coupon_action_is_invalid_coupon" : [] },
      { "drupal_message" : {
          "message" : "Sorry, coupon [coupon:commerce-coupon-code] can no longer be used.",
          "type" : "error"
        }
      }
    ]
  }
}

Perhaps this can go into a coupon docs or recipes page?

That'd be awesome!
Feel free to create one and we can link it from the project page, something like "Coupon recipes" or something

I'll export mine to provide for this as well.

Thank you for the image, I managed to have both expired and upcoming coupons throw errors, the only problem now is that I have two error messages:

    This coupon has expired ====== Message 1
    Your coupon code is not valid. ====== Message 2

How can I remove the second message.

Help appreciated

@kadimi

Check in your coupon rules for any actions named: "Show a message on the site".
If the parameter/message details in the action match your message, you can safely delete that action if you wish.

If it's not coming from a rule, I suggest grep'ing for the message (minus any variables in the message) within your sites/all (if you have command-line). That way you could find out which module is throwing it, assuming it's not saved in the DB. (Hopefully a module would not put something like that anywhere other than rules).

Thanks.

Has this made it into the release or (if no) is it planned to go into a release?

Has this made it into the release or (if no) is it planned to go into a release?

There's nothing like this in the roadmap for me, but I'll gladly review a patch if someone wants to contribute this.

As you can see in #4 this is a very features-like thing, adding a date field and taking care of it in rules should be enough for a basic usage.

I just added a check if the end date is set or not... This should allow to set only a start date:

{ "rules_coupon_validation_check_period_end" : {
    "LABEL" : "Coupon validation: Check period end",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "coupon" ],
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "field_valid_during" } },
      { "NOT data_is_empty" : { "data" : [ "coupon:field-valid-during:value2" ] } },
      { "data_is" : {
          "data" : [ "coupon:field-valid-during:value2" ],
          "op" : "\u003C",
          "value" : [ "site:current-date" ]
        }
      }
    ],
    "DO" : [
      { "commerce_coupon_action_is_invalid_coupon" : [] },
      { "drupal_message" : {
          "message" : "Sorry, coupon [coupon:commerce-coupon-code] can no longer be used.",
          "type" : "error"
        }
      }
    ]
  }
}

So if a limited time only coupon is an edge case, what exactly can this module do?

@RKS

Add 1 field to coupon entity, and 1 rule and you have limited time coupons.

I don't think it's a matter of 'edge case', but for the sake of keeping this module as a customizable coupon toolkit, and not being a bloated 'trying to do everything at once' module.

At least that is my observation, I don't want to speak for the maintainer.

Hi @drastik

I appreciate that adding a rule and a field are relatively minor steps to setting up expiry on coupons. However, I find it hard to imagine a scenario where a coupon would *not* have an expiry date associated with it. Whilst this module could potentially bloat up if every conceivable scenario were incorporated into it, I think this feature is an exception.

Any accountant worth their salt will tell you that having coupons out in the wild that are valid forever is a nightmare from an accrual accounting point of view since they can theoretically be redeemed at any point in the future, which means the accountant needs to carry a liability on the books forever as well. That's messy.

Setting a limit on redemptions is a counter-argument to that, but if I create a voucher for 500 redemptions and only get 200 redemptions within my campaign period then I really want that coupon to die so I don't keep getting unexpected redemptions from now until whenever.

In an ideal world, I would expect the expiry date to be a mandatory field (with an optional valid-from field). I would argue that this feature should be a core feature of any coupon/discount module. I'd code a patch myself but my coding is as good as my singing.

To be clear - I'm not asking for this feature. I'll create fields and rules if I need to. But if there's a roadmap, this post is my +1 for including expiration dates in the module as a core feature.

David

liability on the books forever

Haha, good points. Yeah like I said, I don't see this as an edge case at all. I hadn't thought of it being that critical, but you make a good point.

I see there are too much passion on comment flow. So I picked up all you ideas and i created a sandbox project related to this issue.

Check out the project:

https://drupal.org/sandbox/minarikede/2120313

Any comments are welcomed!

Thanks for this technique. It works great!