We are working on Magento 2.2 create custom attribute seller_id for customer,this attribute is created successfully.
But we can not display this attribute when loading the customer data.
<?php
namespace Kh\Hello\Setup;
use Magento\Customer\Model\Customer;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
class InstallData implements InstallDataInterface
{
private $customerSetupFactory;
/**
* Constructor
*
* @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
*/
public function __construct(
CustomerSetupFactory $customerSetupFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
}
/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'seller_id', [
'type' => 'varchar',
'label' => 'Seller Id',
'input' => 'text',
'source' => '',
'required' => false,
'visible' => true,
'position' => 333,
'system' => false,
'backend' => ''
]);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'seller_id')
->addData(['used_in_forms' => [
'adminhtml_customer'
]
]);
$attribute->save();
}
}
when load customer collection this attribute is not display.
$collection = $this->_customerFactory->create()->getCollection()
->addAttributeToSelect("*")
->addAttributeToFilter("email", array("eq" => "[email protected]"));
Also loading customer and accessing this attribute data not display.