I am using Magento 2.1.0, and i created two customer attribute, it succefully created in backend, and i am that in database, customer grid and customer information page.
but when i enter any value in that, it is not save.
<?php
namespace xxxxxx\CustomerAttr\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\Config;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Customer setup factory
*
* @var CustomerSetupFactory
*/
private $eavSetupFactory;
/**
* Init
*
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory, Config $eavConfig)
{
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Customer\Model\Customer::ENTITY,
'city',
[
'type' => 'varchar',
'label' => 'city',
'input' => 'text',
'required' => false,
'sort_order' => 100,
'system' => false,
'position' => 100,
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'is_searchable_in_grid' => true,
]
);
$eavSetup->addAttribute(
\Magento\Customer\Model\Customer::ENTITY,
'area',
[
'type' => 'varchar',
'label' => 'area',
'input' => 'text',
'required' => false,
'sort_order' => 100,
'system' => false,
'position' => 100,
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'is_searchable_in_grid' => true,
]
);
$sampleAttribute = $this->eavConfig->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'city');
$sampleAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address' ,'customer_account_create']
);
$sampleAttribute->save();
$sampleAttribute = $this->eavConfig->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'area');
$sampleAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address', 'customer_account_create']
);
$sampleAttribute->save();
}
}
even, i have two field on registration page, and i want this attribute take data from field, how to make relation between this???