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.
Hi,
Maybe this is dummy question, but I can't find out how to display the coupon field on the cart page.
Any help is appreciated.
Thanks
Laurent
Comment | File | Size | Author |
---|---|---|---|
#94 | 2872455-phpcs-on-commit.diff | 1.87 KB | mglaman |
#90 | interdiff-84-90.txt | 4.88 KB | czigor |
#90 | commerce-2872455-90-coupon_redemption_on_cart.patch | 19.58 KB | czigor |
| |||
#73 | 2872455-latest-patch.gif | 426.42 KB | mglaman |
#73 | 2872455-73.patch | 20.54 KB | mglaman |
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedThere is none.
#2792653: Checkout coupon pane implementation tracks the issue for checkout, let's track the cart side here.
Comment #3
mglamanIt is possible if you review the Promotions test module.
However there is no exposed block for this.
EDIT: see https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/promotio...
Comment #4
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedHi !
The solution by @mglaman adds the redemption form by the end of the cart, ie beneath the total and checkout button.
Better UX would be to have the coupon redemption in the views footer, above the "order total" field.
To do so, I am willing to provide a patch with a new global view field. I made on extending AreaPluginBase (just like commerce_order_total). However, in the render() method, something like the following does not render. I do not know why though. I guess I have to gt the correct renderer but can't find one.
Do you know about it ?
Comment #5
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedI managed to do so: I will make it as a patch as soon as possible.
Comment #6
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedHere is a patch for this issue.
The patch defines a new "Coupon Redemption" field available in views that you can add to your view footer:
The patch includes:
- the definition of the CouponRedemption views area plugin
-- this include a configuration to let you redeem multiple coupon from the cart
-- the field takes it's order in the footer into account
- a change on how the OrderTotal views area plugin is rendered
-- to allow the coupon pane from the view to actually reload in ajax the order total when a coupon is applied
-- to allow the ordering of the footer fields to be considered
Finally, after configuration you have an ajax enabled coupon redemption form within your cart view:
Don't forget to /core/rebuild.php after applying the patch.
Comment #7
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedAdding a new patch: it may happen that someone remove the "Order total" from cart views footer. The new patch prevent the coupon redemption to fail in that case.
Comment #8
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedBecause both CouponRedemtion and OrderTotal are now views area plugins, the alteration of form adds 'actions' to commerce_order_summary form in the checkout process.
This new patch removes this side effect.
Comment #9
sorabh.v6Comment #10
sorabh.v6@Dom. Coupon form is appearing on cart footer after setting coupon redemption field in cart-form view. It applies coupon on cart page perfectly. But it making checkout page in loop and I am also not able to apply or remove coupon from order-summary sidebar on checkout page.
When I click on 'Continue to review' button it just refresh the page and don't take me to next checkout step.
Error which I am getting for adding/removing coupon -
Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\HttpException: "The specified #ajax callback is empty or not callable." at /var/www/d8Contrib/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php line 67, referer: http://d8contrib.dev/checkout/7/order_information
Thanks
Comment #11
sorabh.v6Comment #12
mglamanTypo
Comment #13
sorabh.v6Comment #14
sorabh.v6Hi All,
I am trying to complete this work. But after hours of debugging, I am still not able to find which code is causing the problem. I can apply the coupon on the cart page and it reduces the cart total price. Then I click the checkout button. On order_information checkout step, if I try to add or remove coupon then I get below error -
I also saw the ajax call on browser console and there in response I am getting -
I tried to move to next checkout step by clicking 'Continue to review' button. It just refreshes the page and does not take me to next step of checkout. If I try to go to next step manually by altering the checkout url, then again it would take me order_information checkout step even if I put the review in the URL instead of order_information.
If you can guide me, then I will be able to complete this patch.
@mglaman What is typo error you mentioned in #12?
Thanks All
Comment #15
sorabh.v6Patch uploaded for coupon field on cart form. Initial work from #8. Removed changes from commerce_checkout.module and updated changes in OrderTotal.php. Please review.
Comment #16
drugan CreditAttribution: drugan as a volunteer commented#15 fixed empty ajax callback issue but introduced another (minor) one. That is when on a cart page you've applied coupon and then removed it, so the ajax replacing stops working on all subsequent attempts to apply/remove a coupon. So, the order summary stays the same what it was after the first ajax action applied, though having right expected value on the background.
Comment #17
sorabh.v6Issue mentioned in #16 by @drugan is resolved in the attached patch. Please review.
Thanks All
Comment #18
sorabh.v6Comment #19
drugan CreditAttribution: drugan as a volunteer commentedI've tested the #17 and for me it works great. The only thing that would be useful is to add functional test for this change.
Comment #20
sorabh.v6@drugan Thanks for reviewing the patch. I was planning to write test, but since its a view area I was not sure if I can write test for it. Therefore, I saw test for OrderTotal view area plugin in the commerce_order module. And there was no test for that view area, so I thought maybe we don't write test for view area.
If we do, please provide any test for view area that I can refer for writing test for CouponRedemption view area.
Thanks
Comment #21
drugan CreditAttribution: drugan as a volunteer commented@sorabh.v6
Go to the web directory of your site:
cd my-site/web
... and run:
locate -r $PWD".*/FunctionalJavascript/.*\Test.php"
FunctionalJavascript test is exactly what we need for this change.
Comment #22
sorabh.v6@drugan Thanks, working on test now.
Comment #23
sorabh.v6@drugan New patch contains test for coupon redemption on cart page. Please review.
Comment #24
drugan CreditAttribution: drugan as a volunteer commentedGreat work!
But, I think it will not hurt a lot if you'd made these changes:
First, I remember from the d.o testing framework docs that it is always better to use explicit values in a test instead of randomly generated ones;
That way we'd also check how utf-8 value coupons work. Also, it would be useful to apply coupon once more after // Coupon removal. block.
Just to be sure that #16 does not appear any more.
Comment #25
gauravjeet CreditAttribution: gauravjeet as a volunteer and at Acro Commerce commentedPatch #17 works as expected. Great work.
I agree with drugan's thought #24
Comment #26
sorabh.v6Thanks @gauravjeet @drugan I will make suggested changes.
Thanks
Comment #27
sorabh.v6Changes made as per #24. Please review.
@drugan Thanks for the suggestion.
Thanks All
Comment #28
drugan CreditAttribution: drugan as a volunteer commentedYESSS!
Comment #29
mglamanLooks good. Just one concern about test coverage. I'll also give it a manual test.
The test is great, but it does not verify that this AJAX refresh command works.
Comment #30
mglamanThis is great! One problem. CartCouponRedemptionTest.php is a duplicate of CouponRedemptionElementTest.php and doesn't actually test the view plugin.
We need to alter the cart form view to embed the plugin and not rely on commerce_promotion_test to alter it in. I am fine with testing the view area plugin as part of the form element test. So updating CartCouponRedemptionTest to add the view area plugin to the default cart view instead of commerce_promotion_test altering it in. Keep a blank commerce_promotion_test.module instead.
Comment #31
mglamanI'll wrap this up so we can integrate it into the Belgrade theme.
Comment #32
joshmiller@mglaman - Any update on this? Either it's sitting in branch finished but unshared or it got lost in the holiday shuffle. No worries, just thought a little prod here might keep it moving.
Comment #33
mglamanThis feel through the cracks. Bringing it back up.
Comment #34
mglamanReroll #30.
Comment #35
mglamanI just realized that this would break if anyone (previously) extended the theme template.
Maybe it is worth using the prefix.
Comment #36
mglamanUpdates tests of the element to use the views plugin.
Local decided to not run PhantomJS right after I think I fixed last test. Semi-blind patch post.
Comment #38
mglamanI forgot we had duplicate tests, fixed. Add schema.
Comment #40
mglamanNeed to try and figure out the schema issues.
Comment #41
gmem CreditAttribution: gmem as a volunteer commentedManaged to get tests working locally and the patch applies and functions well in manual testing. Had to change the plugin_id in the test, which seems to have fixed the issue with the schema for allow_multiple not being found.
Comment #43
gmem CreditAttribution: gmem as a volunteer commentedInterdiff got tested by accident, patch itself passes.
Comment #47
mglamanoof! thanks for the catch.
Comment #48
p4trizio CreditAttribution: p4trizio at Elicos commentedI have an issue with messages not showing after ajax but only on next page reload. Anybody has the same problem?EDIT: sorry, this is working perfectly, looking forward for the patch to be committed
Comment #49
p4trizio CreditAttribution: p4trizio at Elicos commentedComment #50
mglamanForgot to update this earlier. We discussed this internally and decide that we should provide this by default -- why hide such a nice feature.
We would want to work with the default UX then. The full-width message is not great nor the default styling.
Two options I considered
Comment #51
p4trizio CreditAttribution: p4trizio at Elicos commentedHi @mglaman sorry I didn't know that.
You are right it's such a nice feature! About the options you considered I personally like the second, so that the coupon redemption is above the order total: frontend devs will be able to customize the position.
Comment #52
mglamanWorks for me, I mind either, just so long as its _something_ better than being thrown on the page.
Comment #53
mglamanI forgot we can't add this by default, because then cart is dependent on promotion. Here's some quick CSS.
Comment #54
p4trizio CreditAttribution: p4trizio at Elicos commented@mglaman pretty clean indeed, should we wait for more feedbacks on this to move the state of the issue to reviewed?
Comment #55
mirom CreditAttribution: mirom at Slovak Drupal Association, MADE it digital s.r.o. for Drupal Europe commentedIs there different behaviour for coupons which can be combined with others? From the gif it seems that you can use only single coupon.
Comment #56
mglamanI'd like to get some feedback.
You can allow multiple. The default I was testing was with single coupon.
Comment #57
jeroendegloire CreditAttribution: jeroendegloire at Calibrate commentedNew patch with https://www.drupal.org/project/commerce/issues/2896303 included.
Comment #59
Maico de JongRerolling patch #53 for latest dev, which is working fine for me!
@jeroendegloire
Not sure why you've included another patch in this one? Referred issue is also included in latest dev now/
Comment #61
joekersTested the latest patch from #59 and it's still working well.
Comment #62
trebormcPatch from #59 working well.
Comment #63
trebormcfor last DEV version
Comment #64
Povilas Uogintas CreditAttribution: Povilas Uogintas as a volunteer commentedHey,
Somehow latest patch does not work... Ajax refresh fail... There are the errors:
This part is failing:
Any ideas?
Cheers!
Comment #65
Povilas Uogintas CreditAttribution: Povilas Uogintas as a volunteer commentedI tested and changing that into this:
seems to solved the issue.... I might create my own Views Area plugin for now... That way it will be easier to control other potential bugs!
Comment #66
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, the latest patches (#59 and #63 on -dev). Both adds the coupon to the cart but the ajax refresh doesn't work, you have to manually refresh the page to see it. The "remove coupon" button does the same: it removes the coupon but the cart summary is not ajax-refreshed.
After this test I've updated ajaxRefreshSummary() according to #65 but nothing changed.
Comment #67
bojanz CreditAttribution: bojanz at Centarro commentedThe patch will need to be rerolled to use the inline form instead of the deprecated commerce_coupon_redemption_form element.
Comment #68
luca_cracco CreditAttribution: luca_cracco commentedHi! I tried using the inline form but it doesn't work.
The trait "AjaxFormTrait" doesn't work because of the core bug #2897377 and would also require reloading the cart view (for the order summary total component). The trait only reloads the form (i think).
Comment #69
lisastreeter CreditAttribution: lisastreeter at Centarro commented@luca_cracco I'm working on rerolling this patch and also having trouble getting it to work with the inline form.:
Comment #70
lisastreeter CreditAttribution: lisastreeter at Centarro commentedHere is a WIP patch that is not working. It applies to the current dev, though, so it might be helpful to anybody looking at this issue. Coupons can be applied and removed, but the order summary disappears. Also, once you use one of the coupon redemption form buttons, neither the checkout nor the update-order button will work.
I made a variety of unsuccessful attempts to try to attach the ajax callback attached to the coupon redemption form.
Comment #71
mglamanSo, I did some debugging. The problem is.......... VIEWS! Or so it seems. \Drupal\commerce\AjaxFormTrait works fine. It returns the form entirely. But Views is missing the order total area and it changes the form's action to be
/cart?ajax_form=1&_wrapper_format=html
, breaking all non-AJAX buttons (ie: remove, update, checkout.)Comment #72
mglamanThis broke due to the fact InlineForm replaces the entire form, instead of a subset. Views builds forms in a weird way, and this is causing the havoc.
Comment #73
mglamanHere is a patch which is mostly working. There's some extra stuff being inserted.
EDIT: The extra "stuff" is the outer field divs when running Replace on
[data-drupal-selector="order-total-summary"].
Each AJAX is nesting more and more.Comment #74
mglaman🙌🎉. Need to see about them tests.
Comment #77
trebormc#74 works fine. Thanks
Comment #78
introfini CreditAttribution: introfini commented#74 worked with me also. Thanks!
Comment #79
Marko B CreditAttribution: Marko B commentedWorks on 2.13 commerce, thnx
Comment #80
chrisrockwell CreditAttribution: chrisrockwell commentedWorks on 2.14
Comment #81
sekoz CreditAttribution: sekoz as a volunteer commentedI'm not seeing any changes in the cart page.
Nothing mentioning coupons in the source of the /cart page, I tried with the default bartik theme too.
All hunks of patch 74 applied successfully .
drupal 8.8.1
drupalcommerce 8.x-2.16
then I've got a few extra modules commerce paypal, commerce extended quantity, commerce product tax, commerce stock..
could there be some conflict there? or it just doesn't work for 2.16?
Comment #82
joekers@sekoz have you updated the view to include the new Coupon redemption handler in the Footer? If not, comment #4 should help.
Comment #83
sekoz CreditAttribution: sekoz as a volunteer commented@joekers thanks I missed updating the view.
It is now working fine as described by others.
Comment #84
czigor CreditAttribution: czigor at Centarro commentedRemoving the commerce_promotion_test module dependency from the test since that made the coupon redemption form appear twice on the cart form view.
Also replaced the waitForAjaxToFinish() calls with their non-deprecated counterparts.
Comment #85
introfini CreditAttribution: introfini commentedI've applied patch #84 to Commerce 2.17 and it's working as expected. Thanks czigor!
Comment #86
3ssom CreditAttribution: 3ssom at Acro Commerce commentedI've applied the patch #84 also and tested it. works fine!
I'll put this as RTBC.
Comment #87
mglaman🙌 I'll commit on Monday. I think it's time.
Comment #89
mglamannits for later. and phpcs from https://www.drupal.org/pift-ci-job/1610564
Can't remember why we removed this. Is it because we now put the classes in a prefix? Some folks might be relying on this.
😬this isn't scoped
whitespace
I think we should unnest this logic and quit early if the order is null
since we're adding this by default, is this used anymore?
Comment #90
czigor CreditAttribution: czigor at Centarro commented1. Re-added the attributes.
2. Not sure why but since the patch in #70 we don't attach the css, so let's remove the css file and the library definition too.
3. Fixed.
4. Fixed.
5. Some older tests (e.g. CouponRedemptionElementTest) depend on this so I think we should leave this. Alternatively we could convert the old tests to add the area to the view footer inside the test as CartCouponRedemptionElementTest does though.
Comment #91
mglamanOh yeah! We should keep it then, the idea is to prove this works without the View or the CheckoutPane.
Comment #92
3ssom CreditAttribution: 3ssom at Acro Commerce commentedI applied patch #90 in a new fresh install with latest release of core and commerce, works as expected :)
RTBC again, hopefully this will get committed soon.
Comment #94
mglamanThank you, everyone! This has now landed. 🥳
Fixed some phpcs on commit.