Apply Coupon to Specific Products
highfly - June 2, 2008 - 04:47
| Project: | Ubercart Discount Coupons |
| Version: | 5.x-1.9 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Make the Coupon Module more powerful by adding a field in the UI that allows store managers to assign the coupon to a particular product, or set of products.

#1
+1
#2
This would be great – I'll be happy to help test once a patch proposed...
:) Scott
#3
I'll be happy to test as well.
#4
Sorry for lack of response, I've been tied up on a few other projects. I would love to implement this feature and will be working on this over the weekend, and should hopefully have something by next friday. I'll keep updates as progress is made and if I could get some help with testing that might be great too! =]
Blake
#5
Fantastic... Just that I'm needing
I'll be happy to test too...
When you think that will be ready :)
Thanks...
#6
thanks Blake ... look forward to helping you test the updated module ;)
#7
Work on this isn't going as fast as scheduled. I have been putting in hours on my Summer of Code project: http://drupal.org/project/search_ranking. I am about 20% done on this ticket so far. My plan is to implement this so that you can assign a single product to a coupon. The result will be that you can hand out a coupon code that will be valid for any purchase that includes that product.
Scenario 1: You assign a $10 off coupon for product X.
User shops and buys 4 product Ys and 3 product Xs. Enters coupon. They will receive a $30 discount for their coupon.
Scenario 2: You assign a 15% off coupon for product X.
User shops and buys 4 product Ys ($50 each) and 3 product Xs ($20 each). Enters coupon. They will receive a $9 discount for their coupon.
Unfortunately I will not be able to add much more functionality other than described above. I would enjoy writing this module for Drupal 6 when the time comes should SimpleTest support be provided by UberCart. Without UberCart's support for a full SimpleTest suite it makes debugging and testing all of the use cases for these product coupons too intense. I'd prefer to not release code that is used in ecommerce that contains math errors.
As a side note, I have cleaned up a bit of the code and made sure to document it more thoroughly so that anyone daring enough can go through and make future additions to this 5.x codebase. If you would like to have CVS access to this module please let me know. (Contact me via my contact form: http://drupal.org/user/24450)
#8
@BlakeLucchesi : one of the strong of open source is that you are not alone, you can post your snapshot and let the community give you feedback.
For the product selection to apply discount, you can look to my modified module : http://www.ubercart.org/contrib/1991 that allow to do that.
I abandonned it a little because i'm working on D6 now, but I will need to upgrade it one day, maybe you will upgrade yours before (I hope so ^^).
#9
Hey all,
I was previously working with zmoves "Improved" coupon module but with the latest tax issues I was compelled to try this version. The feature I missed was selecting multiple products to apply the coupon to. I found it was somewhat easier to update the the drupal.org version to include the multi select than it was to decipher the tax fix on zmoves.
So, here's a patch against 5.x-1.6 that needs review. It's working in my tests. Features:
Regarding the last point. I was setting up coupons valid for "Product A" but not "Product B". If the coupon's value was $20 but the total of "Product A" was only $10, the coupon was still applying -$20 to the total, indirectly discounting "Product B". Now it will only discount "UP TO" the coupon's value on specified products only.
This works for my needs and hopefully satisfies others who wanted the option of selecting multiple products. Please review and provide feedback.
Happy Drupaling!
#10
Thanks for posting this!
I have updated the patch for 1.7, cleaned it up and made changes to maintain backward compatibility. In 1.6/1.7, when multiple products match a cash value coupon the discount is applied per-product, but in the patch the coupon was only applied once (with an added check that the coupon doesn't discount more than the subtotal of the products). The check is still in place but coupons will now apply per-product as before.
These changes have been committed to CVS and will show up in the next 5.x-1.x-dev release.
#11
Thanks for applying this work!
Almost there. I spot 2 issues.
ISSUE 1
RE: the min() check. I was checking for the total value of applicable products vs the coupon value. This means the discount will be up to $x.xx applied to the total of the valid items.
i.e. Coupon value = $10
Item value = $5
Example Order 1: item quantity of 1 (value $5) then the total discount is lesser of $5 or $10.
Example Order 2: item quantity of 3 (value $15) then the total discount is only $10. The lesser of total (applicable) items value $15 and the coupon value $10.
For my situation I want to give away up to 3 gift cards with a purchase of over a certain amount. So I set the max value of the coupon to the price of 3 gift cards. If they only order 2 the discount is only the value of 2 gift cards. If they order 5, the discount is still only the value of 3 cards. They end up paying for the 4th and 5th. This is the behavior I want, so I remove the (multiply by quantity) from the min() function.
With your method, it keeps applying the discount higher than the item value and multiplied by quantity, meaning they can order an unlimited amount of free cards.
I do see that someone might want to apply a small discount to every applicable item with a coupon code. I.e. $1 off all gift cards regardless of quantity. Maybe we should add an option in the settings for each coupon to apply discount to each item or to the total for qualified items?
ISSUE 2
In the coupon table, the products column is varchar(50) so a long list of products is getting trimmed down to 50 characters, eliminating a number of products from the list. I guess a quick fix is to simply increase the size for that column but a new table is probably a better option. Is this something you're working on? I can probably spend some time on it this week.
#12
Just updating the Status because of my last post. I'll work on a new patch this weekend.
#13
Here's another patch against 5.x-1.x-dev.
I've updated the .install to add a uc_coupons_products table. This addresses the varchar issue that currently exists after enabling multiple products. The products column was varchar(50) which was clipping off node ids when a lot of items were added to the coupon. This also may be a better choice than using a text type column in the uc_coupons table, in case we want to add more criteria to valid products in a coupon later.
Uninstall function is updated too but the update function needs work. I'm not fully familiar with that yet.
Modified the .module to use the new table for products.
#14
I have the problem of the system cutting of long product lists. I tried to increase the products varchar(50) to products varchar(200) in the uc_coupon.install file, but it did not help. Will sleepingmonk´s fix be included in the 5.x-1.x-dev soon? I do not have the ability to apply patches to a module. How do you do that?
Can someone please help me out?
Kindly,
Karl Oskar
#15
I managed to patch the files manually, but did not get the new version to work. I could select unlimited products to be discounted, but when using the discount code it said the code was not valid. I tried to uninstall the module completely and reinstall it, but no success.
After that I once again increase the products varchar(50) to products varchar(200) in the original uc_coupon.install file instead, this time after uninstalling the module completely. Now it works for me, but a new version taking car of this problem would be appriciated...
Kind regards,
Karl Oskar
#16
I'm wondering if this needs to be in a separate table at all. We always need to know the full list of products a coupon applies to, so maybe having a single serialized "data" field in the coupon table to store this product list would work just as easily. This should also allow me to add other feature requests more quickly as I could store more coupon options in that field - changing the schema for each request and making sure updates work consistently each time is a lot of work!
I can't think of any useful reason why we would need to join against the product data separately, so I'll throw this idea out there for now in case anyone has any thoughts...
#17
longwave,
You're right. The extra table may be too complicated for this problem. A serialized array in the coupons table would probably work as well. Someone smarter than me would have to tell me which method is better; a join, or un/serializing a potentially large array.
I went this route because it's the way it was done in zmoves version. It was easier to add features to this module rather than sort out the tax issue in zmoves, so I've been using his as a model.
I've been working on other things since I posted this patch, hoping to hear back with your thoughts. Will you be posting an updated version with your fix soon?
Thanks for the feeback.
#18
I've committed an update to the way coupon products are stored, and changed the products multiple select list to a set of autocomplete text fields which are far easier to use. These changes have also been made to the list of applicable users. This is only for the DRUPAL-5 branch at the moment.
You will need to run update.php to convert the tables to the new format.
Please test this and let me know of any issues or improvements!
#19
This change has been put out as 5.x-1.9 and 6.x-1.1, which should close this issue for good, I hope!
#20
Automatically closed -- issue fixed for 2 weeks with no activity.
#21
I apologize if the answer is obvious and I'm needlessly opening a previously closed issue, but I have been trouble finding further information on this.
I have implemented the uc_coupon module (5.x-1.9) in my existing Ubercart installation. The coupon module shows up fine in the admin area, but I cannot find anything that allows the coupon to be tied to a specific product. From everything that I've see, it looks as though this functionality has been in place since version 1.8, but I've searched all over and can't find info on it. I've posted this to the Ubercart forums as well (http://www.ubercart.org/forum/support/11498/how_apply_coupon_specific_pr...). Thanks in advance!
#22
This works for me. Steps to do this in the latest release:
- Visit /admin/store/customers/coupon
- Click "Add new coupon"
- Enter coupon details
- Expand the "Applicable products" fieldset
- Start typing the name of a product and select it from the autocomplete dropdown
- Repeat for up to three products
- Save coupon
If more than three products are needed, extra product selection fields will be shown when you edit the coupon again.
#23
Thanks for the response! Therein lies the problem. There is no "Applicable Products" text on the "Add a Coupon" page. However, this spurred me on to look around some more and I discovered that there was a "uc_coupon" directory in two places. One at the root of the "modules" directory and one nested within "ubercart". I thought I had uploaded the previous one to the Ubercart directory with success, but now I don't even see that one (uc_discounts).
The result of all this is that I've removed the uc_coupons folder from the Ubercart directory and replaced [an apparently old] one at the modules root. Now it's displaying the fieldset you reference. Wow, that took a lot of work to resolve! Thanks for your help!
#24
Automatically closed -- issue fixed for 2 weeks with no activity.