Skip to content

Commit 4e11c0c

Browse files
authored
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.
1 parent 1aaa2fc commit 4e11c0c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ define([
1717
return function (messageContainer) {
1818
var serviceUrl,
1919
payload,
20-
method = 'put',
2120
paymentData = quote.paymentMethod();
2221

2322
/**
@@ -32,17 +31,16 @@ define([
3231
email: quote.guestEmail,
3332
paymentMethod: paymentData
3433
};
35-
method = 'post';
3634
} else {
37-
serviceUrl = urlBuilder.createUrl('/carts/mine/selected-payment-method', {});
35+
serviceUrl = urlBuilder.createUrl('/carts/mine/set-payment-information', {});
3836
payload = {
3937
cartId: quote.getQuoteId(),
40-
method: paymentData
38+
paymentMethod: paymentData
4139
};
4240
}
4341
fullScreenLoader.startLoader();
4442

45-
return storage[method](
43+
return storage.post(
4644
serviceUrl, JSON.stringify(payload)
4745
).fail(function (response) {
4846
errorProcessor.process(response, messageContainer);

0 commit comments

Comments
 (0)