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.
As discussed in #1329308: Provide better core support for AJAX reloading of checkout panes / pages for Commerce and #1287124: Support recalculating shipping when the address is entered for Commerce Shipping, using ajax to reload the form would provide a better UI for customers. Added ajax functionality would greatly improve usability as customers would instantly see the effect of the added coupon.
Are there any current plans for this, and is it possible to do?
Comments
Comment #1
jonathan_hunt CreditAttribution: jonathan_hunt commentedI'd like to see this also, along with AJAX validation of any coupon codes entered.
Comment #2
lathanHere is a patch that submits the coupons via an ajax add coupon button on the coupon form.
There is currently one issue I'm not sure how to get around, the view is using the log to get the value for the coupon. I assumed commerce_coupon_redeem_coupon($coupon, $order); would have handled... looks like it does not as the values for each coupon do not show up.....
Comment #3
lathanPatch works perfectly.... there are how ever in the latest dev branch missing actions....
namely.
This rule wrong as not sure how get the outstanding amount (NOT THE ORDER TOTAL THATS WRONG) * by the percent amount.....?
Comment #4
lathanRight figured it all out... here is working patch with ajax button and default actions.... for calculating the values.
Comment #5
lathanMore work on this patch
Comment #6
lathanReroll to head of 7.x-1.x dev...
Comment #7
lathanThis patch now applies.
Comment #8
meghanmary CreditAttribution: meghanmary commentedI would love to get this functionality working. Other than applying this patch is there anything else that needs to be done to get the button to show up and that new Calculate coupon with percent amount rule working?
Comment #9
lathanshux man soz for all the patches there is a new file and my diff was just not including it right... rebuilt it from the ground up of dev.
@meghanmary
these are the issues still outstanding with this patch.
1. need to get % amount displaying correctly in the summary of the checkout page.. currently its not (this is a bug in this module but on my road map 2 fix)
2. the summary section of the form needs to update with the new total coupon discount value.
Comment #10
lathan- 'Ajaxified' form.
- Added default rules (fixed and percentage).
- Coupon table and Cart summary table are refreshed.
Comment #11
meghanmary CreditAttribution: meghanmary commentedThanks for working on this - it is working great but I've come across one bug that is stumping me. If a user adds a coupon, does not hit "add coupon" but continues to enter the rest of the checkout information, and submits the checkout page the coupon gets validated at the time of checkout. That would not be a problem except that if the coupon is not valid the page returns with the "coupon is not valid" message but payment information still gets submitted. If a user then corrects the information and tries to submit the page nothing will work and the only way I have found of fixing this is to delete the user account and recreate. Any ideas on how to get around this issue?
Comment #12
lathan@meghanmary nice find with that bug! I think that is a core coupon issue and that bug would work against the standard version with out this patch.. I will check it out in the morning as that is definitely not something we can allow...
Prob need a separate issue for that but ill link it to here once iv checked that out, thanks for the feedback.
Comment #13
meghanmary CreditAttribution: meghanmary commentedThanks jucallme. If you find anything out let me know, I'm wanting to use this for a live site but can't put it out there until this bug is resolved. I'll look into it also and update with anything I find.
Comment #14
lathan@meghanmary Looks like here is the main issue http://drupal.org/node/1445464
Comment #15
pcambraCould you test this to see if it's related? #1380310: Optionally require all panes on a checkout page to validate before processing them
Comment #16
mrfelton CreditAttribution: mrfelton commentedUpdated version, seems to be working pretty well. If you have commerce_payment_example enabled, you'll need the patch from #1532550: Error in commerce_payment_example_submit_form can prevent ajax callbacks from firing on the checkout page. as without it, the ajax callback will not fire correctly.
Comment #17
lathanRerolled and fixed some issues.
- Fixed the pass by reference issue when loading log by order
- Checked the triggered key is set in the form
Comment #18
pcambraThis definitely needs a reroll after killing the log entity.
Comment #19
mitako CreditAttribution: mitako commentedHi,
I've installed last patch for adding an ajax button to coupon form and I don't know if I did something wrong but it is actually not working for percentage coupons.
Is there someone who is having the same issue ?
Can anybody help ?
Cheers
Comment #20
mitako CreditAttribution: mitako commentedProblem solved my Calculate by percent rule was misconfigured
Comment #21
bkonetzny CreditAttribution: bkonetzny commentedStill works, despite the removed log. Adding an coupon via this button assigns it to the order and reloads summary and coupon-listing, so this part seems fine.
One problem is that the field for the coupon stays filled after I added the coupon with this button. If i now submit the form, the coupon-code will get applied again. I think the field should get cleared, if the ajax-submit is successful.
Comment #22
xenophyle CreditAttribution: xenophyle commentedOne suggestion:
In function commerce_coupon_ajax_render_alter(), instead of assuming the view used is commerce_cart_summary,
do something like
as done in commerce_cart_contents_pane_checkout_form().
Comment #23
xenophyle CreditAttribution: xenophyle commentedWhen I apply the coupon code, the redeemed coupon list is updated, but the view for the cart summary (which contains the total) still contains the old data, as though the coupon was not applied. Has anyone seen anything like this? (This happens whether or not the code is modified as I suggested in the previous comment.)
Comment #24
essbee CreditAttribution: essbee commentedThis line
$form['commerce_coupon']['coupon_code']['#value'] = '';
does not work.
The coupon form doesnt exist in the $form variable at that point, so it isnt able to clear the coupon text field after it is applied.
This of course then cause an error to be thrown when the form is submitted as we dont want to allow the same coupon to be applied twice.
Comment #25
essbee CreditAttribution: essbee commentedWell after chasing my tail for an afternoon with $form/$form_state and all manner of combinations, I'm no close to figuring out how to clear (and ideally disable in my case) the coupon code field after a successful "Add coupon"
Hopefully someone with better ajax-fu will be able to provide a solution.
Comment #26
Jayzen CreditAttribution: Jayzen commentedI really need to add a button on my coupon, but I didn't success to apply the last patch with the last dev version of Commerce Coupon ...
It's an error with the new version or I'm stupid today ?
Thanks
Comment #27
pcambraThis might be helpful #1287124: Support recalculating shipping when the address is entered
Comment #28
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedAttached patch re-rolled against the latest dev:
- correctly clears the Coupon Code field after adding a new coupon,
- addresses the issue from comment #22.
I still don't like how it deals with errors (hiding already added coupons and showing Your coupon code is not valid error message instead, should fix it in the next patch version though.
Comment #29
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedNew version of the patch, properly showing errors and rebuilding the form only if necessary (when still staying on the same page).
Comment #30
essbee CreditAttribution: essbee commentedGreat patch.
Have tested and working in my implementation with both fixed and percentage based coupons.
Like the way it handles errors as it handles my rule to block multiple coupons perfectly (replaces the coupon on the order with the new one).
Great work.
Comment #31
pcambraLooks great, thanks all. Some minor details before pushing this in.
I think that it's better to include some checkout references to the id class
Do we need to clean up element validate for some reason?
Watch out this space
If we're already adding the order id as static, probably it's enough with it and we don't need the extra boolean here.
Comment #32
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedRight you are sir. And speaking of which, I believe other panes' ids could use some unification too...
Actually, no. I have just left it there from previous patches. Removed.
Oh boy! Nasty Netbeans. ;)
It's not enough I'm afraid. Updating "Shopping cart contents" stops working after removing it.
Polished (sic!) patch attached.
Comment #33
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedComment #34
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedAnd another version, this one also properly updating shopping cart contents and added coupon list amounts for percentage coupons too (resolving the issue that mitako was talking about in comment #19).
Comment #35
pcambraLooks great, thanks! I'd say that the only thing to do here is making this button optional (despite enabled would be the best option) and add a setting in the checkout pane for it so people that doesn't want multiple coupons at all can just disable it.
Comment #36
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedHere, checkout pane settings option added.
Comment #37
pcambraWe need to handle the variable deletion on module uninstall too
Comment #38
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedThere you go.
And for all other module variables, which are not being deleted either, I have created a new issue. ;P
Comment #39
lathanjust fixing white space issue.
Comment #40
maxime_sbk CreditAttribution: maxime_sbk commentedHi guys,
I think I found a bug but I'm not sure as I don't know how it's suppose to work.
I moved the coupon pane in the
checkout_review
page (where you chose the payment methods). It make sense for me becauseI'm using express checkout (without cart). When I select the payment and submit (continue), the
checkout_review
page is reloaded with the following error:Your coupon code is not valid.
I think there is an issue in the validation:
Line 58:
if (!empty($code) && commerce_coupon_code_is_valid($code, $order)) {
No problem here, except in the
else
we are not checking for empty code so if we don't specify a code the validation is failing.Am I right ?
UPDATE
No I'm not right. Sorry about that, I understand that this is the ajax validation so it make sense to fail on empty code.
Comment #41
pcambraPlease don't modify the status of a feature request to "bug report" if the code hasn't been even committed. Also check the priority levels of issues
The problem that you described would seem as a limit validation errors issue but we're doing that in the patch, we need to test this in a single checkout page and see what happens.
Comment #42
pcambraGreat work in this issue to all that have participated!
Extra kudos to jucallme, mrfelton and maciej!
I've committed this with a slighlty modification, I've added the global validation variable to display the error message consistently with non ajax requests, basically this:
For making the pane UI completely ok this should be next #1305242: Add a Remove coupon view button and Make a User used coupon rule condition
Comment #44
davident CreditAttribution: davident commentedUsing #39 I've been able to spot an issue where if a coupon code is entered in the text field without clicking the add button, the order will have the coupon attached but without the discount applied. This happened when Payment pane was in the Checkout Pane and Review was in Completion pane.
Can anyone verify this?
Comment #45
zroeduardo CreditAttribution: zroeduardo commentedI think this must be an issue, in: commerce_coupon_add_coupon_callback() on line 148:
$commands[] = ajax_command_replace('.view-commerce-cart-summary', $cart_summary);
The class was hard coded, so in my pane I've used another view to load the cart summary, making the class slightly different. I have to manually change the class to the loaded one for the refresh to work (in my case) :
$commands[] = ajax_command_replace('.view-checkout-cart-summary', $cart_summary);
Comment #46
skumar_drupal CreditAttribution: skumar_drupal commentedHi,
I'm facing problem for update commerce shipping (Flat rate shipping) values in commerce coupon modules. I tried many patches but not found solution. Please guide me...