Magento provides so many default fields but If we need custom information in customer address then we can create a new customer_address type attribute.
In this article, I will share how we can add text type attribute in Customer Address,
You need to create InstallData.php file in your existing module or you can create a new module as well as,
If you are creating in your existing module: app/code/[Vendor Name]/[Module Name]/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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php namespace [Vendor Name]/[Module Name]\Setup; use Magento\Customer\Setup\CustomerSetupFactory; 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; class InstallData implements InstallDataInterface { /** * @var CustomerSetupFactory */ private $customersetupFactory; /** * @var AttributeSetFactory */ private $attributesetFactory; /** * @param CustomerSetupFactory $customersetupFactory * @param AttributeSetFactory $attributesetFactory */ public function __construct( CustomerSetupFactory $customersetupFactory, AttributeSetFactory $attributesetFactory ) { $this->customersetupFactory = $customersetupFactory; $this->attributesetFactory = $attributesetFactory; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $customerSetup = $this->customersetupFactory->create(['setup' => $setup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); $attributeSet = $this->attributesetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->addAttribute('customer_address', 'job_title', [ 'type' => 'varchar', 'label' => 'Job Title', 'input' => 'text', //You can change your input type as per your requirement 'required' => false, //If You need this field is required in customer address area then you can just set "true" in stand of "false" 'visible' => true, 'user_defined' => true, 'sort_order' => 1000, 'position' => 1000, 'system' => 0, ]); $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'job_title') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer_address'], //Other list of forms: customer_address_edit, customer_register_address where you want to display the custom attribute ]); $attribute->save(); } } |
After creating the above file you have to run below commands:
1 2 |
php bin/magento setup:upgrade php bin/magento cache:clean |
Now you can check in the customer section in the admin area.
Our newly created attribute shown in the customer address form.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-6284615d3addc597719885/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...