Como acessar os dados do Cliente por Javascript no Magento 2

Você precisa criar um para salvar o e-mail do cliente no armazenamento local. Então, adicione uma configuração de de em 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\Customer">
        <plugin name="additional_section_data" type="Your\Module\Plugin\AddCustomerEmail" />
    </type>
</config>

E o plugin ficará assim:

<?php

namespace Your\Module\Plugin;

use Magento\Customer\Helper\Session\CurrentCustomer;

class AddCustomerEmail
{
    /**
     * @var CurrentCustomer
     */
    private $currentCustomer;

    public function __construct(
        CurrentCustomer $currentCustomer
    ) {
        $this->currentCustomer = $currentCustomer;
    }

    public function afterGetSectionData(\Magento\Customer\CustomerData\Customer $subject, $result)
    {
        if ($this->currentCustomer->getCustomerId()) {
            $customer = $this->currentCustomer->getCustomer();
            $result['email'] = $customer->getEmail();
        }

        return $result;
    }
}

Dúvidas? Faça um comentário logo abaixo ou envie uma mensagem clicando aqui.

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *