Patch to add new type of discount: set price or absolute price of item
| Project: | Ubercart Discount Coupons |
| Version: | 5.x-1.11 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (to be ported) |
This is a very easy hack to uc_coupon 5.11 that adds a new type of discount action available for coupons. The new type of discount allows the user to change the per-unit price of a product when the coupon is entered. For example I have a widget selling for $20. I could set up a coupon with a "price set to" type and a value of "15" that, when entered correctly, adds a line-item discount of -$5 for every unit of widget in my shopping cart (the result is that the user pays $15/unit of widget).
Usually, a user can simply do this adding a relative price discount of -5 using the "price" type of discount. Well, in my case I have a client who uses a sort of arcane (to me anyway) set of overlapping discounts, and some of them work by actually changing the price of the item dynamically (instead of as a line-item). So, as the original price isn't a fixed quality, I can't reliably set widget X to cost price Y by setting up a relative amount discount. My widget price might in some cases be $25, and so a discount of -5 would result in a price of $20, instead of the desired $15 in all cases that the coupon is used.
Here's the code: just added a type to the settings form and an extra "else" statement in the uc_coupon_validate function (which derives the coupon amount for the user).
309,310c309
< 'price' => 'Price',
< 'set_price' => 'Set price to',
---
> 'price' => 'Price'
963,965d961
< }
< else if ($coupon->type == 'set_price') {
< $result->amount = $applicable_total - ($applicable_qty * $coupon->value);
