<?php namespace Magenticians\CustomerAttribute\Setup; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Customer\Model\Customer; use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet; use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; /** * @codeCoverageIgnore */ class InstallData implements InstallDataInterface { /** * @var CustomerSetupFactory */ protected $customerSetupFactory; /** * @var AttributeSetFactory */ private $attributeSetFactory; /** * @param CustomerSetupFactory $customerSetupFactory * @param AttributeSetFactory $attributeSetFactory */ public function __construct( CustomerSetupFactory $customerSetupFactory, AttributeSetFactory $attributeSetFactory ) { $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * {@inheritdoc} */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet AttributeSet */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->addAttribute(Customer::ENTITY, 'birth', [ 'type' => 'datetime', 'label' => 'Birth', 'input' => 'date', 'required' => false, 'visible' => true, 'user_defined' => true, 'sort_order' => 1000, 'position' => 1000, 'system' => 0, ]); $customerSetup->addAttribute(Customer::ENTITY, 'adresse', [ 'type' => 'varchar', 'label' => 'Adresse', 'input' => 'text', 'required' => false, 'visible' => true, 'is_used_in_grid' => true, 'user_defined' => true, 'sort_order' => 1001, 'position' => 1001, 'system' => 0, ]); $customerSetup->addAttribute(Customer::ENTITY, 'phone', [ 'type' => 'varchar', 'label' => 'Phone Number', 'input' => 'text', 'required' => false, 'visible' => true, 'is_used_in_grid' => true, 'user_defined' => true, 'validate_rules' => '{"max_text_length":255,"min_text_length":1}', 'sort_order' => 1002, 'position' => 1002, 'system' => 0, ]); $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'birth') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['customer_account_create', 'adminhtml_customer','customer_account_edit'], ]); $secondattribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'adresse') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['customer_account_create', 'adminhtml_customer','customer_account_edit'], ]); $thirdattribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'phone') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['customer_account_create', 'adminhtml_customer','customer_account_edit'], ]); $attribute->save(); $secondattribute->save(); $thirdattribute->save(); } }
http://127.0.0.1/magento/customer/account/edit/