Customersectiondata

Creates a Customer(Section) Data

Since private content is specific to individual users, it’s reasonable to handle it on the client (i.e., web browser).

Use our customer-data JS library to store private data in local storage, invalidate private data using customizable rules, and synchronize data with the backend.

Use the snippet in the Magento 2 module creator.

Files

CustomerData/Test.php

<?php
declare(strict_types=1);

namespace Mage2Gen\Module\CustomerData;

class Test
{

    protected $logger;

    /**
     * Constructor
     *
     * @param \Psr\Log\LoggerInterface $logger
     */
    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function getSectionData()
    {
        return [];
    }
}

etc/frontend/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:ObjectManager/etc/config.xsd">
	<type name="Magento\Customer\CustomerData\SectionPoolInterface">
		<arguments>
			<argument name="sectionSourceMap" xsi:type="array">
				<item name="test-data" xsi:type="string">Mage2Gen\Module\CustomerData\Test</item>
			</argument>
		</arguments>
	</type>
</config>