Let’s initiate a discussion!!
Create setup file InstallData.php
File: app/code/Magemonkeys/Customer/Setup/InstallData.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<?php namespace Magemonkeys\Customer\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; use Magento\Customer\Model\Customer; class InstallData implements InstallDataInterface { private $eavSetupFactory; 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, 'sample_attribute', [ 'type' => 'varchar', 'label' => 'Sample Attribute', 'input' => 'text', 'required' => false, 'visible' => true, 'user_defined' => true, 'position' => 999, 'system' => 0, ] ); $sampleAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'sample_attribute'); // more used_in_forms ['adminhtml_checkout','adminhtml_customer','adminhtml_customer_address','customer_account_edit','customer_address_edit','customer_register_address'] $sampleAttribute->setData( 'used_in_forms', ['adminhtml_customer'] ); $sampleAttribute->save(); } } |
Run command line to install the module: php bin/magento setup:upgrade and php bin/magento setup:static-content:deploy
Then check the result. It will show like this:
The search box is the most underrated functionality that is...
Managing and customizing Magento site can be a daunting task,...
Having an in-house eCommerce developer is very costly, and it...
Have you wonder why your conversions are less compare to...
According to a research, around 68% of eCommerce stores are...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.