I'm currently working on a way to add coupon discounts for the admin area.
I'll post patches (hopefully) here.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | coupon_order_pane.patch | 5.29 KB | Island Usurper |
| #8 | coupon_order_pane_1.patch | 2.38 KB | andreiashu |
| #3 | coupon_order_pane.patch | 1.41 KB | Island Usurper |
| #1 | discount_codes_admin.patch | 3.5 KB | andreiashu |
Comments
Comment #1
andreiashu commentedHere is a first patch.
I stumbled upon a problem:
hook_order('load', ... )is called before the implementation of a pane in the order area thus we can't store the coupon entered in the 'edit-process' operation of such a pane. So I implemented a submit callback for the edit order form.It still needs, upon submission, to verify if the actual inserted coupon is valid (passes the coupon conditions).
Comment #2
andreiashu commentedIt is still in CNW but I need some opinions on the work done until now.
Thanks
Comment #3
Island Usurper commentedI was surprised to see that you can't add to the $order->data array from an order pane. I guess that's what you meant when you said that hook_order('load') happens before the order panes are processed. Fortunately, there's still another way, and I think it's a bit cleaner than adding a submit hook.
Like the quotes module, you can add a button to the order pane, and effectively add a submit function to that button. This happens after uc_order_save(), so it has to load the order, add the coupon code, and save it again. It's still not great, but I like it better than stashing the coupon code in a function's static variable.
Ryan's been working on the checkout pane system lately, and I think I've convinced him to do the order panes the same way. That should make features like this easier to implement in the future.
Comment #4
andreiashu commentedHi Island,
I really like your approach. I didn't know that you can do that in UC order panes.
The patch works fine :)
RTBC ?
Comment #5
andreiashu commentedHmm... I just remembered: shouldn't we warn a user when the coupon code is invalid (ie. doesn't return true when passed to the CA conditions) ?
Cheers !
Comment #6
andreiashu commentedAnd I stumbled a bug:
1. from admin area create an order;
2. apply a valid discount code/coupon - XXX => you'll get your discount applied (expected behavior);
3. look at the order's logs: you see "Coupon code XXX redeemed" (expected behavior);
4. apply (to the same order) an invalid coupon code - YYY
5. in the order's logs you have another log line with "Coupon code XXX redeemed" (unexpected behaviour).
6. the actual discount is not applied when entering invalid discounts (expected);
Can you replicate ?
Comment #7
andreiashu commentedCorrect me if I'm wrong but I think a solution for both issues raised in #5 and #6 would be to actually run the conditions in the
case t('Apply coupon'):code and if they don't return TRUE just save the order without a coupon code and show a warning message.Would that work ?
Comment #8
andreiashu commentedI was wrong :))
The "solution" in #7 solves just the #5 issue (I attached a patch).
For the moment I don't know what to say about #6. It is most probably the way uc_discount handles discount codes in
hook_uc_order()Cheers
Comment #9
Island Usurper commentedYeah, I like the idea of validating during
case t('Apply coupon'):. That probably means I should do the same thing for the checkout pane as well. Entering an invalid coupon shouldn't stop them from continuing to check out, though.I think this takes care of both of those problems.
Comment #10
andreiashu commentedJust tested it. Its brilliant :)
(I also reviewed my prev patch and saw how crappy that was)
RTBC if no one else screams.
Cheers !
Comment #11
andreiashu commentedThis time actually really setting it as RTBC...
Comment #12
Island Usurper commentedOK, I think it's good enough to commit. If anybody really does have a problem with it, they can scream in another issue. :) Thanks.