Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Can Magento 2 Customer Attribute support multi-language / storeview

I following this link to try adding a new Customer Attribute in Magento 2.2.6. The Attribute is added successfully but seems it doesn't support multi-language / storeview? As I cannot find way to switch the language / store view in Edit Customer page.

Can anyone confirm if Customer Attribute support multi-language / storeview?

If really cannot support any suggestion on how can I achieve this?

Thanks a lot.

Code for adding customer attribute

<?php

namespace CoolBlueWeb\Example\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class InstallData implements InstallDataInterface {

    private $_eavSetupFactory;
    private $_attributeRepository;

    public function __construct(
        \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory,
        \Magento\Eav\Model\AttributeRepository $attributeRepository,
    )
    {
        $this->_eavSetupFactory = $eavSetupFactory;
        $this->_attributeRepository = $attributeRepository;
    }

    public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context )
    {

        $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);

        // add customer_attribute to customer
        $eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'customer_attribute');
        $eavSetup->addAttribute(
        \Magento\Customer\Model\Customer::ENTITY, 'customer_attribute', [
            'type' => 'varchar',
            'label' => 'Customer Attribute',
            'input' => 'text',
            'required' => false,
            'system' => 0,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'sort_order' => '200'
        ]
    );

    // allow customer_attribute attribute to be saved in the specific areas
    $attribute = $this->_attributeRepository->get('customer', 'customer_attribute');
    $setup->getConnection()
    ->insertOnDuplicate(
        $setup->getTable('customer_form_attribute'),
        [
            ['form_code' => 'adminhtml_customer', 'attribute_id' => $attribute->getId()],
            ['form_code' => 'customer_account_create', 'attribute_id' => $attribute->getId()],
            ['form_code' => 'customer_account_edit', 'attribute_id' => $attribute->getId()],
        ]
    );
    }
}

Comments