4

I am trying to add products in wishlist using ajax with phtml + Controller. However, the product gets added to wishlist but the counter of wishlist doesn't change.

Is there a way to trigger an update for wishlist counter.

2 Answers 2

5

Update your js file as

require([
   ....
   'Magento_Customer/js/customer-data'
], function (...,customerData) {
   "use strict";
   ...
   var sections = ['wishlist'];
   customerData.invalidate(sections);
   customerData.reload(sections, true);
   ...
});

Modify above code according to your need and you will get what you need.

1
  • Thanks @user3313626, exactly what I wanted :)
    – Nausif
    Jan 11, 2019 at 9:47
1

Update Wishlist counter

Paste in Your Js file (your custom theme js)

require([                                                           
    'jquery',
    'Magento_Customer/js/customer-data'
], function ($, customerData) {
    "use strict";
     var sections = ['wishlist'];
     customerData.reload(sections, true);
});

This code reload the wishlist item count in every pages...

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.