I'm currently working on a way to add coupon discounts for the admin area.
I'll post patches (hopefully) here.

Comments

andreiashu’s picture

StatusFileSize
new3.5 KB

Here 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).

andreiashu’s picture

Status: Active » Needs review

It is still in CNW but I need some opinions on the work done until now.

Thanks

Island Usurper’s picture

StatusFileSize
new1.41 KB

I 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.

andreiashu’s picture

Status: Needs review » Reviewed & tested by the community

Hi Island,

I really like your approach. I didn't know that you can do that in UC order panes.

The patch works fine :)

RTBC ?

andreiashu’s picture

Status: Reviewed & tested by the community » Needs work

Hmm... 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 !

andreiashu’s picture

And 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 ?

andreiashu’s picture

Correct 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 ?

andreiashu’s picture

StatusFileSize
new2.38 KB

I 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

Island Usurper’s picture

StatusFileSize
new5.29 KB

Yeah, 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.

andreiashu’s picture

Just tested it. Its brilliant :)
(I also reviewed my prev patch and saw how crappy that was)
RTBC if no one else screams.

Cheers !

andreiashu’s picture

Status: Needs work » Reviewed & tested by the community

This time actually really setting it as RTBC...

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

OK, I think it's good enough to commit. If anybody really does have a problem with it, they can scream in another issue. :) Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.