Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
I ran into the same issue. I tried writing my own patch, but was not able to add a form to the drupal checkout page. This is because the coupon panel is added as a form markup area, so it's ignored by the form API. This is therefore a bug in commerce, not in the coupon module, so it should probably be entered add such. I'll open the bug sometime later, when I actually have a computer.
I've applied this patch by hand but I don't think the permissions are correct; in my case, an anonymous user can't remove a coupon from the cart. The callback to coupon_log_access() requires update ability on the log, but looking at commerce_cart.module it's more appropriate to map to view_content permission.
Seems module structure has been changed - at least now in dev release there is no db table coupon logs. So all patches above not working anymore. I saw that already there is function
Maybe there is possibility to add views field with AJAX link which can execute function which deleting coupon by name? Or maybe there are some issues with this solution? I think this option must be in stable release of module!
I've added patch which add possibility to remove coupon when user on checkout form. But seems function commerce_coupon_remove_coupon_from_order() not working properly. After I've executed it it still shows coupon connected with order. Would be good if someone can review patch and maybe give some feedback!
To activate "remove link" you need manually edit commerce coupon view and add there new field 'Remove from Order'.
Yes, #1356170 is what is needed, although for D8 - in case of D7 the one linked in my comment #15 here is the one that made all the difference for this patch.
$ patch -p1 < commerce_coupon-ajax_coupon_remove-1305242-15.patch
patching file commerce_coupon.info
Hunk #1 FAILED at 17.
1 out of 1 hunk FAILED -- saving rejects to file commerce_coupon.info.rej
patching file commerce_coupon.module
Hunk #1 succeeded at 152 (offset 8 lines).
patching file includes/commerce_coupon.checkout_pane.inc
Hunk #2 FAILED at 50.
Hunk #3 succeeded at 63 (offset -1 lines).
Hunk #4 succeeded at 84 (offset -7 lines).
Hunk #5 succeeded at 121 (offset -7 lines).
Hunk #6 succeeded at 176 (offset -6 lines).
Hunk #7 succeeded at 188 (offset -6 lines).
1 out of 7 hunks FAILED -- saving rejects to file includes/commerce_coupon.checkout_pane.inc.rej
patching file includes/views/commerce_coupon.views.inc
patching file includes/views/commerce_coupon_ui.views_default.inc
patching file includes/views/handlers/commerce_coupon_handler_field_coupon_remove. inc
When I tried to apply what was in the .rej manually I just got a blank/white screen of death when I reloaded my website. I've removed this for now, but any tips would be appreciated as I am fairly new to how patches work. Am I missing another pre-req patch for this?
Kim, the patch is meant to be applied against 7.x-1.x-dev version, which already includes patch from #1329600 - so if you had to add it first, it meant you're patching the wrong version.
Have just checked it quickly and it still applies cleanly against the most recent 7.x-1.x-dev.
- Secured the removal link, both with permissions and crsf attack protection.
- Fixed the ajax redirection
- Tweaked the views handler to use get_result_entities
- Fixed documentation and callback names.
I'm marking this one as fixed, I think we should open a followup to provide optional ajax support.
After installing the latest dev version (2013-Feb-06), coupons are added in the checkout fine, but only the cart summary view is refreshed. The coupon field set should also refresh to display the new 'delete' link after each coupon code. At the moment you have to physically refresh the page to display the delete links which is not good.
Any guidance to get this to work properly would be great, thanks.
Comments
Comment #1
schultetwin commentedCould you add your commerce_coupon_handler_field_coupon_log_remove.inc file to the patch?
Comment #2
kleinmp commentedI updated the patch a little bit and added the missing file.
It would be nice to add the remove button as an actual button instead of link, but I was having issues submitting a form on the checkout page.
Also, it's patched against 7.x-1.0-beta3 because the dev version wasn't working for me.
Comment #3
schultetwin commentedI ran into the same issue. I tried writing my own patch, but was not able to add a form to the drupal checkout page. This is because the coupon panel is added as a form markup area, so it's ignored by the form API. This is therefore a bug in commerce, not in the coupon module, so it should probably be entered add such. I'll open the bug sometime later, when I actually have a computer.
Comment #4
kleinmp commented@schultetwin I didn't realize that about the coupon panel. That's good to know.
Here's an updated patch that modifies the user use condition to count the number of uses, rather than assuming it should be 1.
Comment #5
bkonetzny commentedWorks perfectly, thanks for your patch!
Comment #6
jonathan_hunt commentedI've applied this patch by hand but I don't think the permissions are correct; in my case, an anonymous user can't remove a coupon from the cart. The callback to coupon_log_access() requires update ability on the log, but looking at commerce_cart.module it's more appropriate to map to view_content permission.
Comment #7
adamgerthel commentedI applied the patch in #4 to beta3 but I don't see a remove coupon button. Attached is the patched module
I got these two errors when applying it:
Comment #8
adamgerthel commentedUpdate: I forgot the added file from #2
Anyway, like Jonathan says: Anonymous users can't remove it. There is no permission to allow then to either
Comment #9
pcambraWe're mixing stuff in here, one thing is removing a coupon from an order #1443570: When removing a coupon from an order, remove it also from log and reset it, other is displaying a button in the checkout pane to remove the coupon and a different thing is restrict users to use the button.
I'm working in the remove coupon from order issue so we can have an API to call and some rules actions.
Comment #10
pcambraSee also #1295316: Remove Coupons from the checkout
Comment #11
pcambraThe API for deleting coupons from an order has been added in #1443570: When removing a coupon from an order, remove it also from log and reset it so we should rely on that for the coupon checkout pane form.
Comment #12
vadim.eremeev commentedSeems module structure has been changed - at least now in dev release there is no db table coupon logs. So all patches above not working anymore. I saw that already there is function
commerce_coupon_remove_coupon_from_order($order, $coupon);Maybe there is possibility to add views field with AJAX link which can execute function which deleting coupon by name? Or maybe there are some issues with this solution? I think this option must be in stable release of module!
Comment #13
vadim.eremeev commentedI've added patch which add possibility to remove coupon when user on checkout form. But seems function
commerce_coupon_remove_coupon_from_order()not working properly. After I've executed it it still shows coupon connected with order. Would be good if someone can review patch and maybe give some feedback!To activate "remove link" you need manually edit commerce coupon view and add there new field 'Remove from Order'.
Comment #14
vadim.eremeev commentedJust found issue #1838328: API function commerce_coupon_remove_coupon_from_order doesn't remove coupon in some cases. which describe bug with
commerce_coupon_remove_coupon_from_order(). Solution will be useful for this thread.Comment #15
maciej.zgadzaj commentedAttached patch introduces ajaxified Remove coupon buttons to the Checkout pane - however, at least in my case, it also needs the patch from
#1715508: drupal_get_form on Ajax callback returns this javascript error: “TypeError: element_settings.url.replace is not a function”. (If someone finds a way to make it work without patching common.inc, I'd be more that happy to rewrite it.)#208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice.
Comment #16
pcambraI'm still thinking that the way to go is to provide a button that is not ajaxified and then ajaxify it in a followup
Comment #17
maciej.zgadzaj commentedUm, from what I've seen a non-ajaxified version was already provided before, for example in comment #13...
Comment #18
pcambraIs the patch in #1356170: Remove all uses of array_merge_recursive, or document why they are being used instead of NestedArray::mergeDeep() what is needed? seems the one up to date for D7, right?
Comment #19
maciej.zgadzaj commentedYes, #1356170 is what is needed, although for D8 - in case of D7 the one linked in my comment #15 here is the one that made all the difference for this patch.
Comment #20
kimberlydb commentedI had patched the add ajax button http://drupal.org/node/1329600#comment-6491844, and then tried this patch maciej.zgadzaj (#15) has posted. I get a few failing hunks:
When I tried to apply what was in the .rej manually I just got a blank/white screen of death when I reloaded my website. I've removed this for now, but any tips would be appreciated as I am fairly new to how patches work. Am I missing another pre-req patch for this?
Thanks!
Comment #21
maciej.zgadzaj commentedKim, the patch is meant to be applied against 7.x-1.x-dev version, which already includes patch from #1329600 - so if you had to add it first, it meant you're patching the wrong version.
Have just checked it quickly and it still applies cleanly against the most recent 7.x-1.x-dev.
Comment #22
maciej.zgadzaj commentedNew version with debug code removed and sligtly refactored. Still requires core patch from #208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice.
Comment #23
maciej.zgadzaj commentedRe-rolled patch from #13 plus updated views (new displays, hiding Remove links on Review step).
Comment #24
pcambraWe need to protect the link against csfr as for #755584: Built-in support for csrf tokens in links and menu router
Also, removing a coupon from there prevents adding it back.Clarification: Adding a coupon using the ajax interface makes the redirection happen to system/ajax
Comment #25
pcambraI will take this to the finish line, some things to fix still.
Comment #26
pcambraI've committed the non ajaxified version.
Some changes made:
- Secured the removal link, both with permissions and crsf attack protection.
- Fixed the ajax redirection
- Tweaked the views handler to use get_result_entities
- Fixed documentation and callback names.
I'm marking this one as fixed, I think we should open a followup to provide optional ajax support.
Thanks a lot to everyone involved
Comment #28
karengrey commentedAfter installing the latest dev version (2013-Feb-06), coupons are added in the checkout fine, but only the cart summary view is refreshed. The coupon field set should also refresh to display the new 'delete' link after each coupon code. At the moment you have to physically refresh the page to display the delete links which is not good.
Any guidance to get this to work properly would be great, thanks.
Comment #29
pcambraPlease open new issues instead of reopening, this got committed so anything that pops out now should be a new issue.