| Project: | Ubercart Discount Coupons |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | rszrama |
| Status: | closed (fixed) |
Issue Summary
I would like a coupon that can be applied to any one of a number of items but does not apply a discount to all matching items in the order.
Right now, I have a coupon that can be used to reduce the cost by $5 of, let's say, a tshirt. I have three different tshirts. I want the user to be able to order as many tshirts as he or she wants but only use the coupon for one of the tshirts. When the user enters the coupon, the discount gets applied to all matching items: $5 off on each tshirt. This works fine if the user only orders one tshirts but gives excess discount if the user is ordering multiple tshirts.
I know I could create unique coupons for each tshirt but I believe this is a far worse user experience.
Does anyone have any ideas or insight? Thank you.
Comments
#1
I'd also find this useful. At the moment a fixed £10 or $10 discount is applied to every item in the basket, regardless of whether the coupon is set to only be used once.
One use == one use at checkout, rather than one discount (on one item). I don't think this is what most users would expect.
#2
I agree this certainly should be added, it's currently done the way it is only for reasons of backward compatibility - some people may be using this feature as-is so we can't just pull it out from under them. I suspect that changing the discount type options from percentage and price to percentage, price (per item) and price (per cart) would work.
I will work on this feature when I find time, which at the moment is hard to come by!
#3
I've just found that by selecting 'product class: none' - my code is only applied once (and to the order as a whole). Maybe this is the workaround to use until a specific option is in place?
#4
Hey guys. I took this on for someone and have the attached patch as a result. What it does is add two form elements to the coupon form, one for the maximum number of applicable products and the other to specify whether the cheapest or most expensive products should be discounted. There is help text in there that I believe sufficiently explains the settings.
When a coupon is validated now, instead of incrementing $applicable_total and $applicable_qty for every matching product, I add the product price [qty.] number of times to a $prices array. I then check to see if a maximum number of products has been specified. If so, I sort the prices array, slice off the appropriate prices, and tally them up into the $applicable_total and $applicable_qty values. If the coupon applies to every product, I just tally up the whole shebang.
I've tested this on a local site, but I was not able to test it quickly with a coupon that applied to products of varying price. I have no reason to expect this not to work, but it would be best for whoever reviews this to verify that. I'll do this tomorrow if I can.
btw, this is against 6.x-1.3. I tried working against HEAD, but it was broken when I tried to add a coupon.
#5
Whoops! On a quick review, I see that I had a superfluous $qty declaration in there. Also, some of this patch is just some automated whitespace fixing from Komodo.
#6
We've been testing this and it seems to work well, with the exception that, if a coupon is created with max items set but no applicable products, you *must* select 'products' otherwise the logic falls through and applies the coupon to the entire cart.
Unsure what the ideal behavior is, it's just a training issue to always target either a specific product or the entire products category.
#7
Thanks for the patch! Committed to 6.x, with a minor typo fix and a validation check to ensure that a restriction has been selected if the maximum number of applicable products feature is used.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.
#9
It would be great to have this applied to a stable release. Thanks!