1

I have a custom payment gateway module.
When you click on the Place Order button on checkout, it redirects you to an external payment page & after that you return to a custom controller on that module.
This controller handles the payment response & if it's all good - it converts the current quote to an order using placeOrder() from Magento\Quote\Api\CartManagementInterface. Then it redirects you to the normal success page ('checkout/onepage/success/').
The problem is, although the order has been placed & it all worked as it should - the minicart on the header is not empty (You get to the success page, see a link to the order details, but the mini cart stays full).
I tested other payment methods like checkmo, etc... & they always clear the carts somehow, it only happens with this payment method.
*I know that I can use customerData.invalidate(['cart']); on the success page as a workaround (that's my current solution actually, and it works), but I don't like it. I assume that there's something that happens on the other methods/flows that triggers the minicart refresh.
What am I missng here?
Any idea?

  • Which Magento2 version you are using? – Amit Naraniwal Feb 12 at 7:46
  • It happens on 2.2.5 – Pini Feb 12 at 7:47
-1

Try to add below script in the vendor\magento\module-checkout\view\frontend\templates\success.phtml

<script>
     require([
         'Magento_Customer/js/customer-data'
     ], function (customerData) {
         var sections = ['cart'];
         customerData.invalidate(sections);
         customerData.reload(sections, true);
     });
 </script>
  • I already wrote that that's what I'm doing at the moment. I'm looking for a real solution. What causes the problem & why it doesn't happen on other payment methods? – Pini Feb 12 at 7:57
  • you tried customerData.reload(sections, true) as well? – Amit Naraniwal Feb 12 at 7:59
  • Yes, customerData.invalidate(['cart']); does the job. but it's just a workaround. I don't like this solution. I'm trying to understand how Magento does that on other payment methods & do the same. – Pini Feb 12 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.