0

I am working a lot lately with the client side interactions and mage-cache-storage using the customerData. When the user clicks some button, I send information to the customerData and store it there for future use in the same session.

For example

storeCustomData: function(data){ 
    customSection = customerData.get('custom-section')();
    customSection['data'] = data; 
    customerData.set('custom-section', customSection); 
};

All of this while working on the CMS page side, Category/Catalog side, but is not working while on the Product View page.

If I set the values of that customerData custom section from the Product View page, every time that I refresh the page, the value is there stored on the Browser (tested on Chrome, Safari, and Firefox), but If I tried to get the data with customerData.get('custom-section')() from it at page load always response with an empty object. 10-20 times refreshes without cleaning cache, and no luck.

Any ideas why?

Curious behavior: If I change from the Product view (while having the data stored on my mage-cache-storage) to the Category view, the response is correct, I can get the object and render my template correctly, so if I get back to Product again, works! (weird), so apparently there is something else going on while interacting from the Product view side and reloading inside that instance over and over.

Preconditions PHP 7.0.30 Magento 2.2.3

Steps to reproduce First of all, you have to be on the Product View page.

  1. Declare the custom section on the di.xml inside your custom module with this:

    <type name="Magento\Customer\Block\SectionConfig"> 
         <arguments> 
          <argument name="clientSideSections" xsi:type="array"> 
          <item name="custom-section" xsi:type="string">custom-section</item> 
          </argument> 
         </arguments> 
    </type>
    

    ```

  2. Setup a user click interaction like open/close and inside the click function retrieve data from the HTML and store it on the customerData using the example function from the code above. Then execute this function like a widget with the data-mage-init when one of the product view templates renders, for example, form.phtml.

  3. Refresh the page, product view, and try to retrieve that data at load with

    getCustomData: function() { 
         customSection = customerData.get('custom-section')(); 
         data = customSection['data']; 
         return data; 
    };
    
  4. Response is "undefined" cause of an empty object. But the custom-section is still there with all the information from before.

If I work from Catalog page, it works. It gets the object correctly and renders the information at refresh.

Expected result

  1. Get the information correctly in the Product view page from the customerData custom section as every other page from Magento.

  2. The mage-cache-storage doesn't refresh my custom-section in the product view, like catalog or cms views works. The object is not empty as a response from the function.

Your Answer

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

Browse other questions tagged or ask your own question.