Skip to content

My custom magento section doesn’t appear local storage

In my understanding, magento store private customer data in a local storage under the mage-cache-storage key. Therefore, I’m trying to create a custom section in the local storage to store my own defined data. I have followed some instruction i found online, however, when i inspect my website to see the mage-cache-storage, i didn’t see my custom section at all.

This is how i did:

I had an existing module so i added an di.xml in the /etc/frontend folder

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="MagentoCustomerCustomerDataSectionPoolInterface">
       <arguments>
           <argument name="mage-cache-storage" xsi:type="array">
               <item name="custom_section" xsi:type="string">UetCalendarCustomerDataCustomSection</item>
           </argument>
       </arguments>
   </type>
</config>

Then i created a file to retrieve the section data in the path app/code/<Vendor>/<Module>/CustomerData/CustomerSection.php

<?php
namespace UetCalendarCustomerData;
use MagentoCustomerCustomerDataSectionSourceInterface;

class CustomSection implements SectionSourceInterface
{   

    public function getSectionData()
    {
        return [
            'occasions' => 'test',
            'categories' => 'test',
        ];
    }
}

And use the magento js library to retrive the data

require(['Magento_Customer/js/customer-data', 'domReady!'], function (customerData) {
        var customSection = customerData.get('custom_section');
        console.log(customSection);
    });

I have clean the cache and all but I still no where to see my custom_section in local storage

Edit: So i have solved this by adding the sections.xml and changed the tag name like the following comment

<?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="/calendar/index/index/">
        <section name="custom_section"/>
    </action>
</config>