Magento2: Discount code issues on cart page

Created on 4 Jun 2019  路  10Comments  路  Source: magento/magento2

Preconditions (*)

  1. Magento Enterprise 2.2.5 (2.2.8 same issue)
  2. Few products in the shopping cart (guest / registered has same issue)

Steps to reproduce (*)

  1. Create new module and create preference for MagentoCheckoutControllerCart\Index
  2. In method execute try to set a new coupon on customer quote, couponCode is set in the URL parameter
$couponCode = $this->getRequest()->getParam('code');
$cartQuote = $this->cart->getQuote();
        $cartQuote->getShippingAddress()->setCollectShippingRates(true);
        $cartQuote->setCouponCode($couponCode)->collectTotals();
        $this->quoteRepository->save($cartQuote);

        /** redirect to cart to remove code from URL */
        $this->_redirect('checkout/cart');

Expected result (*)

  1. Coupon applied
  2. Discount calculated

Actual result (*)

  1. Discount calculated
  2. Coupon is not applied

Look at the screenshot here:
cart_issue

Important: this code fully works if code is set in the cookie variable / register / is hardcoded and user access cart page from different URL. Code does not work if cart page is refreshed and coupon is set in execute method.

Format is valid

Most helpful comment

I've resolved the issue and I'm closing this one.
@orlangur it turned out that another peace of the code was not casting variables in the right way, 3rd party extension :-/
Another win for xDebug

@orlangur @dmanners @shikhamis11 thanks for jumping in and all your feedback and help.
It is now safe to close the issue.

All 10 comments

Hi @qsolutions-pl. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@qsolutions-pl do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

Update the same issue is when I removed preference and created plugin beforeExecute

GitHub is intended for bug reports. Please use Stack Overflow for questions.

This is a bug. I've reproduced it on Magento vanilla installation.

@qsolutions-pl no. Functionality works perfectly fine in core while your code not. So, ask a question adding your code so that others can help you.

I am going to reopen this and have ask our QA maintainers to take another look over this.

Hi @shikhamis11. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

@dmanners we need to describe in more details somewhere in https://github.com/magento/magento2/blob/2.3-develop/.github/ISSUE_TEMPLATE/developer-experience-issue.md how a proper bug report should look like. In this one there is obviously lack of debug on developer side in own custom code.

I can share the entire module if needed.
The part of the code I copied here as bug report, which is related to applying coupon code, is a direct copy-paste from Magento 2 Core CouponPost class, from this file
vendor/magento/module-checkout/Controller/Cart/CouponPost.php
I was operating on checkout sesssion before and had the exact same issue

I've resolved the issue and I'm closing this one.
@orlangur it turned out that another peace of the code was not casting variables in the right way, 3rd party extension :-/
Another win for xDebug

@orlangur @dmanners @shikhamis11 thanks for jumping in and all your feedback and help.
It is now safe to close the issue.

Was this page helpful?
0 / 5 - 0 ratings