Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently the feature to add a coupon to an order from the order_ui admin area is broken.
The form provides an 'amount' and 'currency' (based on the shipping module?) that doesn't actually work.
This feature is marked as "TODO" in the code.
The attached patch fixes that issue and provides the ability to add commerce coupon line items from the admin order edit form.
Attached.
Please review and commit when possible.
DT
P.S Thanks for the useful module!
Comments
Comment #1
pcambraI think you must have coded the patch against beta because it doesn't apply to the latest -dev
More things I see in the patch review:
Comment #2
davidwhthomas CreditAttribution: davidwhthomas commentedYes, this was coded against the recent beta, it needs rework for the latest -dev
Currently possible perhaps with just
commerce_coupon_redeem_coupon($coupon, $order)
but raises an Entity Exception as coupon_reference field not quite set correctly... looking into it though.cheers,
DT
Comment #3
pcambraMarking this one as dependent of #1547440: Kill coupon log entity
After killing the coupon log, we can expose our own form in the order UI, so we don't depend on the line item manager (not all coupons create line items).
Additionally we'll have to filter out all coupons from the line item manager.
Comment #4
davidwhthomas CreditAttribution: davidwhthomas commented@pcambra,
Thanks, but can you give an example of when a coupon wouldn't create a line item?
Even if it doesn't adjust the price, it can show as a line item, with no price adjustment ( e.g free gift coupon )
Isn't it always useful to have a line item on the order indicating a coupon has been added to it?
DT
Comment #5
pcambraPercentage coupons don't create a line item by design. If we create a line item for % coupons, there would be no way to combine the % with other taxes and discounts and therefore we couldn't decide the order in which the % would be applied.
Comment #6
davidwhthomas CreditAttribution: davidwhthomas commented@pcambra, thanks for the explanation.
Attached is a patch that provides a local action menu item on the admin order view to add a coupon ( as opposed to line item manager ).
It does this
The coupon is added to the order in the submit handler via the generic
commerce_coupon_redeem_coupon($coupon, $order)
It's working for fixed amount coupons, which add a line item, but for percentage coupons, it adds to the log and shows the correct granted amount, but doesn't adjust the order total. I tried various refresh hook calls and order save/load but the percentage coupon wouldn't adjust the order total.
In any case, it's better than nothing as is working for fixed amount coupons from the admin order ui.
Feedback welcome,
thanks,
DT
Comment #7
pcambraThat's great, we've got a good start point here.
Next steps would be:
Comment #8
davidwhthomas CreditAttribution: davidwhthomas commentedThanks, unfortunately I don't have time on this project to add much finesse other than basic functionality to add coupons to orders from admin.
However, I did get the percentage coupon applying fine by adding commerce_cart_order_refresh to the submit handler.
That function is normally called during checkout when progressing between pages.
Updated function is
thanks,
DT
Comment #9
pcambraOk, an update after fixing #1547440: Kill coupon log entity
After this patch coupons are a field in the order, so there's a widget appearing in the order UI form.
All we need to do here now is avoid to display the line item coupon in the line item manager.
Comment #10
ivanbueno CreditAttribution: ivanbueno commentedI updated David's patch to work with the latest dev version commerce_coupon_ui. I added the following implementations:
- remove Coupon option in the Add Line Item dropdown
- disable updates on coupons that are listed in the line item manager
- create Coupons tab in the order
- @see screenshot http://i.imgur.com/tOQ1M3V.png
--Ivan
Comment #11
pcambraThanks for rescuing this!
I like the addition of blocking the coupon line items and moving the coupons to a different tab might be a good idea.
But commerce_coupon_order_reference field might be enough for this, it should be displayed intentionally at the end of the order edit form with an autocomplete widget... thoughts?
Some minor review stuff.
Watch out for the extra spaces
Maybe this should be a combination of administering orders and coupons?
Comment #11.0
pcambraclarity