Read More
Read More
Menu Close

    How to work with sectionData in Hyvä

    In Hyvä to work with the sectionData is a lot simpler and easy to understand as compared to Magento. In this blog we will learn how to work with sectionData in Hyvä.

    Note: – We use the terms “private section data”, “section data”, “private data” and “private content” interchangeably.

    Important : – In hyva it is not possible to subscribe to specific sections. All sections i s combined in to one data object

    How to Initialize section data

    In hyva initialize of section data is trigger in the footer of every page. In case the data is empty in the LocalStorage then after one hour passed or the private_content_version cookie changed then fresh section data requested from “/customer/section/load” and stored in LocalStorage.

    At the time of data load then the event “private-content-loaded” is also trigger.

    Searching for an experienced
    Magento 2 Company ?
    Read More

    In the hyvä theme, to receive customer data in Alpine.js or alpine component by listening to the “private-content-loaded” event on the window:

    Reloading / Invalidating section data

    There are two Methods 1) Client Side and 2) Server side :-

    Client Side

    To reload the customer-section-data use the global reload-customer-section-data event.

    If the section data expired and the private content version is changed then the private-content-loaded event will be triggered again or else will cause the section data to be reloaded by dispatching the reload-customer-section-data event.

    To reload the sectionData forcefully by removing the mage-cache-sessid before dispatching the reload-customer-section-data event:

    The private-content-loaded event will always trigger after reloading the sectionData. In any case, If it was request from the server or read from local storage.

    Server side

    To force the frontend to refresh the section data from the backend, either the mage-cache-sessid cookie or the private_content_version cookie should delete.

    To do the same in custom PHP code during any POST request, inject

    The latter is done by Magento on any frontend or GraphQL POST request (but not for the REST api).

    Force the refresh in a GET request, copy the code from Version::process.
    (keep in mind that GET request responses are usually cached in the FPC).

    Previous blog : – Working with View Models in Hyvä

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top