Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mini-cart not emptied for logged out users checking out with PayPal Express #9994

Merged
merged 1 commit into from
Jun 21, 2017

Conversation

driskell
Copy link
Contributor

@driskell driskell commented Jun 20, 2017

Description

When checking out of M2 using PayPal Express as a logged in user, the mini-cart is not emptied after you reach the success page. In fact, you'll still have the same cart contents in the mini-basket as you purchased. As soon as you add a new item to the basket it does then reset and only shows the new items (old contents are gone). This is, however, confusing, as clicking the mini-cart then proceeding to cart of course shows "No items in the cart".

There are two modules providing API for setting payment information, Magento_Quote and Magento_Checkout. The former, Magento_Quote has entries in sections.xml to invalidate and reload the cart data. In this code it is using Magento_Checkout for guests and Magento_Quote for logged in users, causing logged in users to have their cart data reloaded too early, before the cart is in fact reset, and causing it to persist after checkout is completed. By modifying this to use Magento_Checkout APIs for both (as one would likely expect) the issue is resolved, as there are no sections.xml entries for the Magenta_Checkout APIs.

This PR also introduces consistency as the same module API is used for both types of users.

I'm unsure how to make integration tests for this.

Manual testing scenarios

  1. Log in to M2
  2. Perform checkout and reach payment page
  3. Select PayPal Express payment method
  4. Accept any agreement and click to proceed to PayPal
  5. Enter facilitator credentials and confirm payment
  6. Upon return to M2 proceed to the home page or a category page
    Before PR: You will see items still in mini-cart even though you bought them
    After PR: You will see an empty mini-cart

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

…al Express

*Problem*

When checking out of M2 using PayPal Express as a logged in user, the mini-cart is not emptied after you reach the success page. In fact, you'll still have the same cart contents in the mini-basket as you purchased. As soon as you add a new item to the basket it does then reset and only shows the new items (old contents are gone). This is, however, confusing, as clicking the mini-cart then proceeding to cart of course shows "No items in the cart".

*Investigation and Solution*

Investigating the issue, we found that during checkout as logged in user, the `paypal-express-abstract.js` code correctly invalidates the `cart` `customerData` component. However, it is almost immediately afterwards reloaded, and of course, as this is before we pass out to PayPal, the cart is reloaded with the same contents. Upon then proceeding to PayPal and returning, there is no further invalidation and nothing is reloaded.

This does not occur for guests.

I discovered this is due to a `sections.xml` entry existing for the AJAX request that `set-payment-method.js` makes for logged in users. No such entry exists for guests. This entry includes `cart` and as such invalidates and reloads `cart`, whereas the desired behaviour is to only invalidate, and not reload until success page is reached. I determined that there are two modules providing API for setting payment information, `Magento_Quote` and `Magento_Checkout`. The former, `Magento_Quote` has entries in `sections.xml` to invalidate the `cart` data. It seems in the PayPal JS code it is using `Magento_Checkout` for guests and `Magento_Quote` for logged in users. By modifying this to use `Magento_Checkout` APIs for both (as one would likely expect) the issue is resolved, as there are no `sections.xml` entries for these APIs.
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jun 20, 2017

CLA assistant check
All committers have signed the CLA.

@driskell
Copy link
Contributor Author

CLA signed

@ishakhsuvarov ishakhsuvarov self-assigned this Jun 20, 2017
@ishakhsuvarov ishakhsuvarov added this to the June 2017 milestone Jun 21, 2017
@magento-team magento-team merged commit 4e11c0c into magento:develop Jun 21, 2017
magento-team pushed a commit that referenced this pull request Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants