We have a fair number of orders created by staff for customers, and want to use coupons to provide standard discounts for these customers ( resellers, actually ). I've implemented the ability to apply a coupon directly to an order in the order edit form:
- and order / edit pane for the coupon input form
- a JS callback to apply the coupon to the order
- a copy of uc_coupon that takes the order_id as the second param, loads the order instead of the cart, then loops through the order->products array to calculate the total discount.
It occurred to me while doing this that a) this might be useful to somebody else, and b) this could be made simpler by re-factoring uc_coupon_validate() to take either the cart contents *or* the order products as a param.
I realize you're already thinking about version 2; if this feature is interesting enough to you I could roll a patch against uc_coupon 1.x HEAD in the next week or so.
Comments
Comment #1
longwaveVersion 2 is a long way off (or may never come, as uc_discount seems to be coming along well enough that it could eventually replace uc_coupon entirely), so if you have time to provide a patch for this, please do!
Comment #2
norio commentedI came up with the following code that works. I've put this in customtweaks.module which is my own custom module that I put on clients' sites for specific tweaks that they ask for. Replace 'customtweaks' with your own module name.
And a bit further down:
It doesn't warn you if the coupon is invalid and it might not be secure. I leave those to someone else to do as I'm on a tight schedule.
Comment #3
tchurch commentedsubscribing
Comment #4
technikh commentedsubscribing
Comment #5
technikh commentedI replaced coupon functionality of discount module with coupon module's code and it worked.
In uc_discount.module
Comment #6
maksim24 commentednorio, your code doesn't work because
if ($coupon->valid) { will be always return FALSE
because in function uc_coupon_validate we have a
$order->products = uc_cart_get_contents();
products is NULL because we are in order but not in cart
this code better