should allow for unlimited.... when save this fields with a blank value it get reset to 1.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lathan’s picture

PS: same applies for the fixed amount not going to open a duplicate issue for that.

pcambra’s picture

Project: Commerce coupon percentage » Commerce Coupon

This is common code and it's on commerce coupon itself.

pcambra’s picture

Category: bug » feature
generalconsensus’s picture

If you disable the default rule it should not matter what the value in the field is. This is a temporary fix fyi

pcambra’s picture

Title: Number of Uses » Change the UI to allow unlimited uses for a coupon
hadsie’s picture

To allow for some coupons to have unlimited and others not I modified the default rule to have a data comparison check on the coupon-number-of-uses. If the number of uses is set to 0 then it will fail the conditions and run a check.

{ "commerce_coupon_validate_uses_of_coupon" : {
    "LABEL" : "Coupon Validation: Check the number of redemptions",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "commerce_coupon_number_of_uses" } },
      { "NOT data_is" : { "data" : [ "coupon:commerce-coupon-number-of-uses" ], "value" : "0" } }
    ],
    "DO" : [
      { "commerce_coupon_action_get_coupon_uses" : {
          "USING" : { "commerce_coupon" : [ "coupon" ] },
          "PROVIDE" : { "number_of_uses" : { "number_of_uses" : "number of uses" } }
        }
      },
      { "component_commerce_coupon_validate_uses_of_coupon_component" : {
          "commerce_coupon" : [ "coupon" ],
          "number_of_redemptions" : [ "number-of-uses" ]
        }
      }
    ]
  }
}
switch13’s picture

Status: Active » Needs review

I don't have experience committing code but if hadsie's code works, can someone put this into the next build?

I'd like to test it as well. Where do I drop that code? in the commerce_coupon.rules.inc file? commerce_coupon.rules_defaults.inc? and where in that code?

Does this need to be turned into a patch to get committed?

=>switch<=

hadsie’s picture

You could import that into rules through the UI. Or you could simply add the NOT data comparison to the conditions of the rule that's already there. Add a new data comparison condition on the coupon-number-of-uses field and you should be good to go. If you do just import the code above as a new rule, you'll need to disable the default rule that comes with the coupon module.

pcambra’s picture

Status: Needs review » Needs work

No patch to review, we need a UI configuration in the field widget to accept -1 or an unlimited value, I don't think 0 is the right value for unlimited.

star-szr’s picture

I'm looking to put together a patch for this, this really threw me off when setting up this module. A couple possible approaches I mocked up:

1. Just use a magic value as suggested in #9.
commerce_coupon-1532452-magic.png

2. Use the #states API to show/hide the maximum number of uses field. More complicated to implement but perhaps a better user experience.

commerce_coupon-1532452-states-unlimited.png

commerce_coupon-1532452-states-limit.png

torgosPizza’s picture

I like both of those approaches. Unlimited coupons is a much-needed feature, because we have thousands of customers, and it makes more sense to have one code that can be reused (and added to promotional graphics) thank having to generate untold numbers of unique codes.

Would love to see a patch, @Cottser! I'd be happy to test it out.

torgosPizza’s picture

Just FYI I was able to accomplish this by editing the default "Check number of redemptions" rule to include an AND "Data comparison is NOT equal to Fixed Coupon", then deleted the field "Max number of uses" from the Fixed Coupon Type, and it seems to work fine.

I don't think it's the best/cleanest solution, because there may be times when you want a limited-use Fixed Coupon; however you could always just create a new Fixed Coupon type, and exclude that from the NOT condition above. But again it seems like this is a lot of mucking about with Rules and Fields, when it could more simply be a "-1" value for max uses.

If I get to work on this in more depth I will submit a patch that does this, but realize it would also mean disabling or changing the default rule that ships with Commerce Coupon.

remydenton’s picture

Status: Needs work » Needs review
FileSize
1.6 KB

Here's a simple patch that allows '-1' to indicate a coupon with no usage limit (option #1 illustrated by Cottser is comment #10).

Note that if you have existing coupon types, you'll need to update the 'Maximum number of Uses' field manually to allow -1 to be accepted and/or update the field description.

star-szr’s picture

Thanks @remydenton, I've been meaning to get to this but have been too bogged down elsewhere. Haven't tested the code yet but looks pretty nice. I do see a bit of trailing whitespace (http://drupal.org/coding-standards#indenting).

marktheshark’s picture

Has there been any progress on the topic of unlimited coupon / promo codes?

Is there a mechanism to ensure the coupon can be redeemed only once per order or per user?