You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix mini-cart not emptied for logged out users checking out with PayPal 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.
0 commit comments