0

I am trying to create a custom section with private content to not cached. I follow this article:

https://webkul.com/blog/sections-magento-2/

I did the first two steps:

di.xml

<?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="Magento\Customer\CustomerData\SectionPoolInterface">
        <arguments>
            <argument name="sectionSourceMap" xsi:type="array">
                <item name="custom_price_region" xsi:type="string">Morwi\PrecioRegional\CustomerData\CustomPriceRegion</item>
            </argument>
        </arguments>
    </type>
</config>

CustomPriceRegion.php

<?php
namespace Morwi\PrecioRegional\CustomerData;

use Magento\Customer\CustomerData\SectionSourceInterface;

class CustomPriceRegion implements SectionSourceInterface
{
   /**
    * {@inheritdoc}
    */
    public function getSectionData(){
        return [
            'msg' =>'Data from section',
        ];
    }
}
?>

After that, the article said I should see the new section of the local storage of the browser, but I don´t see it. How is it set? Is something additional to do?

Thanks.

0

I was able to see customsection from example link after adding to module etc/frontend/di.xml and CustomSection.php

I also check your example and its working only when I change your class CustomPriceRegion to CustomSection (filename also and logout everywhere to check)

even when I stay with name custom_price_region its showing customsection in browser.

Maybe try to finish rest of steps in tutorial.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.