0

I am using welpixel quick view extension for quick view on product listing, but due to some customizations I am unable to use it as it is. So I just used its url to get html and appended data using jQuery as:

$('#'+appendDiv).html('<object type="text/html" data='+quickUrl+' ></object>');

Now everything works fine except one thing that on add to cart I am unable to refresh customer min cart section.

Approaches tried:

Approach 1:

<action name="frontname/controller/action">
    <section name="cart"/>
</action>

Approach 2:

require(['jquery','Magento_Customer/js/customer-data'], function                                            
($,customerData) { 
  var sections = ['cart'];
    customerData.invalidate(sections);
    customerData.reload(sections, true);

 });

In WeltPixel QuickView I found a JS on which after addtocart I am in. I also did console log and got output there successfully then I used the second approach as

require('Magento_Customer/js/customer-data').reload(['cart'], false)

On doing so in Network I can see my section GET ajax is called and which contains correct cart data, but unfortunately, it is not been reflected in the frontend. There is no error in the console as well at this moment.

I think to do with In JS i.e. Approach 2 should work but unfortunately, it is not. Also cleared cache, var/*, generated, incognito but no luck.

Any idea how I can do this?

1

Create sections.xml under etc folder and add your custom action url in that to get cart data updated:

etc/frontend/sections.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="your/custom/action">
        <section name="cart"/>
    </action>
</config>

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.