Magento 2 How to add custom attribute to customer address and how to insert value in that attribute?Magento 2 : Display custom field (customer attribute) in “checkout register” formhow to generate and save unique value for customer attribute in magentohow to get value of custom attribute of customer in sales_orde_ place_afterHow to add custom field before place order button and get that value in observer?Get custom category attribute valueMagento 2 Save customer attribute value while customer registerSet value to created customer custom attribute in magento 2M1.9 set value for custom product attributeM2 observer: get custom customer attribute value (drop down)Magento2 : user define customer attribute not save value while create / save from adminMagento 2 How to upgrade existing custom customer address attribute?

Can the Kraus decomposition always be chosen to be a statistical mixture of unitary evolutions?

Can attackers change the public key of certificate during the SSL handshake

Changing Row Keys into Normal Rows

Which pronoun to replace an infinitive?

What's going on with an item that starts with an hbox?

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

Is there a way to improve my grade after graduation?

Can you take actions after being healed at 0hp?

Why am I not getting stuck in the loop

How to touch up scratches on a black anodized aluminum flashlight?

Does the length of a password for Wi-Fi affect speed?

I am considering a visit to a Nevada brothel. What should I say at the US border?

How to check a file was encrypted (really & correctly)

Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?

New workplace asking for bank pin and account number

Examples of hyperbolic groups

split large formula in align

Is charge point-like or a smear?

Based on what criteria do you add/not add icons to labels within a toolbar?

Did Apollo leave poop on the moon?

If the interviewer says "We have other interviews to conduct and then back to you in few days", is it a bad sign to not get the job?

I was contacted by a private bank overseas to get my inheritance

How does LIDAR avoid getting confused in an environment being scanned by hundreds of other LIDAR?

How to make attic easier to traverse?



Magento 2 How to add custom attribute to customer address and how to insert value in that attribute?


Magento 2 : Display custom field (customer attribute) in “checkout register” formhow to generate and save unique value for customer attribute in magentohow to get value of custom attribute of customer in sales_orde_ place_afterHow to add custom field before place order button and get that value in observer?Get custom category attribute valueMagento 2 Save customer attribute value while customer registerSet value to created customer custom attribute in magento 2M1.9 set value for custom product attributeM2 observer: get custom customer attribute value (drop down)Magento2 : user define customer attribute not save value while create / save from adminMagento 2 How to upgrade existing custom customer address attribute?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to add a new custom attribute to "customer_address" that I did with an attribute installer script, now I am able to see that field in "eav_attribute" table. I have created a module and I have one observer for "custmer_save_after" in that. Now I want to set a custom value for that custom attribute which I created from the script.



how can I achieve this functionality?










share|improve this question
































    1















    I want to add a new custom attribute to "customer_address" that I did with an attribute installer script, now I am able to see that field in "eav_attribute" table. I have created a module and I have one observer for "custmer_save_after" in that. Now I want to set a custom value for that custom attribute which I created from the script.



    how can I achieve this functionality?










    share|improve this question




























      1












      1








      1








      I want to add a new custom attribute to "customer_address" that I did with an attribute installer script, now I am able to see that field in "eav_attribute" table. I have created a module and I have one observer for "custmer_save_after" in that. Now I want to set a custom value for that custom attribute which I created from the script.



      how can I achieve this functionality?










      share|improve this question
















      I want to add a new custom attribute to "customer_address" that I did with an attribute installer script, now I am able to see that field in "eav_attribute" table. I have created a module and I have one observer for "custmer_save_after" in that. Now I want to set a custom value for that custom attribute which I created from the script.



      how can I achieve this functionality?







      magento2 event-observer customer eav address






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 17 '18 at 9:55









      Abdul Samad

      113 bronze badges




      113 bronze badges










      asked Dec 17 '18 at 9:28









      Utsav GuptaUtsav Gupta

      5472 silver badges16 bronze badges




      5472 silver badges16 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          1














          I have created it with below code in InstallData.php file.





          namespace ModuleNameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @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)

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute('customer_address', 'location_id', [
          'type' => 'int',
          'label' => 'Location Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 13,
          'position' => 13,
          'system' => 0,
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'location_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          //'adminhtml_customer_address',
          //'customer_address_edit',
          //'customer_register_address'
          ],
          ]);

          $attribute->save();




          then run the below commands:



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer



























          • I have one issue is, now the "location_id" is showing in each address. How can i remove it?

            – Utsav Gupta
            Dec 26 '18 at 13:37











          • I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

            – Utsav Gupta
            Dec 27 '18 at 11:34


















          0














          ------- CREATE CUSTOMER ADDRESS ATTRIBUTE --------



          Step 1 : create app/code/Dckap/CustomerAddressAttribute



          Step 2 : Create app/code/Dckap/CustomerAddressAttribute/etc/module.xml



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
          <module name="Dckap_CustomerAddressAttribute" setup_version="1.0.0">
          </module>
          </config>


          Step 3 : Create app/code/Dckap/CustomerAddressAttribute/registration.php



           <?php

          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          'Dckap_CustomerAddressAttribute',
          __DIR__
          );


          Step 4 : Create app/code/Dckap/CustomerAddressAttribute/Setup/InstallData.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavSetupEavSetup;
          use MagentoEavSetupEavSetupFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * EAV setup factory
          *
          * @var EavSetupFactory
          */
          private $eavSetupFactory;

          /**
          * Init
          *
          * @param EavSetupFactory $eavSetupFactory
          */
          public function __construct(EavSetupFactory $eavSetupFactory)

          $this->eavSetupFactory = $eavSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

          /** @var EavSetup $eavSetup */
          $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
          if (version_compare($context->getVersion(), '1.0.0') < 0)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSetup = $objectManager->create('DckapCustomerAddressAttributeSetupCustomerSetup');
          $customerSetup->installAttributes($customerSetup);









          Step 5 : Create app/code/Dckap/CustomerAddressAttribute/Setup/CustomerSetup.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavModelConfig;
          use MagentoEavModelEntitySetupContext;
          use MagentoEavSetupEavSetup;
          use MagentoFrameworkAppCacheInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;

          class CustomerSetup extends EavSetup

          protected $eavConfig;

          public function __construct(
          ModuleDataSetupInterface $setup,
          Context $context,
          CacheInterface $cache,
          CollectionFactory $attrGroupCollectionFactory,
          Config $eavConfig
          )
          $this -> eavConfig = $eavConfig;
          parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);


          public function installAttributes($customerSetup)
          $this -> installCustomerAttributes($customerSetup);
          $this -> installCustomerAddressAttributes($customerSetup);


          public function installCustomerAttributes($customerSetup)



          public function installCustomerAddressAttributes($customerSetup)


          $customerSetup -> addAttribute('customer_address',
          'custom_address_attribute',
          [
          'label' => 'Customer Address Attribute',
          'system' => 0,
          'user_defined' => true,
          'position' => 100,
          'sort_order' =>100,
          'visible' => true,
          'default_value' => '',
          'note' => '',
          'type' => 'varchar',
          'input' => 'text',

          ]
          );

          $customerSetup -> getEavConfig() -> getAttribute('customer_address', 'custom_address_attribute')->setData('is_user_defined',1)->setData('default_value','')-> setData('used_in_forms', ['adminhtml_customer_address', 'customer_register_address', 'customer_address_edit']) -> save();




          public function getEavConfig()
          return $this -> eavConfig;




          Finaly run command



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer

























          • Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

            – Utsav Gupta
            Dec 17 '18 at 9:58











          • I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

            – Utsav Gupta
            Dec 26 '18 at 13:31













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254856%2fmagento-2-how-to-add-custom-attribute-to-customer-address-and-how-to-insert-valu%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I have created it with below code in InstallData.php file.





          namespace ModuleNameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @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)

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute('customer_address', 'location_id', [
          'type' => 'int',
          'label' => 'Location Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 13,
          'position' => 13,
          'system' => 0,
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'location_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          //'adminhtml_customer_address',
          //'customer_address_edit',
          //'customer_register_address'
          ],
          ]);

          $attribute->save();




          then run the below commands:



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer



























          • I have one issue is, now the "location_id" is showing in each address. How can i remove it?

            – Utsav Gupta
            Dec 26 '18 at 13:37











          • I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

            – Utsav Gupta
            Dec 27 '18 at 11:34















          1














          I have created it with below code in InstallData.php file.





          namespace ModuleNameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @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)

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute('customer_address', 'location_id', [
          'type' => 'int',
          'label' => 'Location Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 13,
          'position' => 13,
          'system' => 0,
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'location_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          //'adminhtml_customer_address',
          //'customer_address_edit',
          //'customer_register_address'
          ],
          ]);

          $attribute->save();




          then run the below commands:



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer



























          • I have one issue is, now the "location_id" is showing in each address. How can i remove it?

            – Utsav Gupta
            Dec 26 '18 at 13:37











          • I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

            – Utsav Gupta
            Dec 27 '18 at 11:34













          1












          1








          1







          I have created it with below code in InstallData.php file.





          namespace ModuleNameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @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)

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute('customer_address', 'location_id', [
          'type' => 'int',
          'label' => 'Location Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 13,
          'position' => 13,
          'system' => 0,
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'location_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          //'adminhtml_customer_address',
          //'customer_address_edit',
          //'customer_register_address'
          ],
          ]);

          $attribute->save();




          then run the below commands:



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer















          I have created it with below code in InstallData.php file.





          namespace ModuleNameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @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)

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute('customer_address', 'location_id', [
          'type' => 'int',
          'label' => 'Location Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 13,
          'position' => 13,
          'system' => 0,
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'location_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          //'adminhtml_customer_address',
          //'customer_address_edit',
          //'customer_register_address'
          ],
          ]);

          $attribute->save();




          then run the below commands:



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 26 at 23:13









          coderGeek

          1279 bronze badges




          1279 bronze badges










          answered Dec 26 '18 at 13:36









          Utsav GuptaUtsav Gupta

          5472 silver badges16 bronze badges




          5472 silver badges16 bronze badges















          • I have one issue is, now the "location_id" is showing in each address. How can i remove it?

            – Utsav Gupta
            Dec 26 '18 at 13:37











          • I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

            – Utsav Gupta
            Dec 27 '18 at 11:34

















          • I have one issue is, now the "location_id" is showing in each address. How can i remove it?

            – Utsav Gupta
            Dec 26 '18 at 13:37











          • I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

            – Utsav Gupta
            Dec 27 '18 at 11:34
















          I have one issue is, now the "location_id" is showing in each address. How can i remove it?

          – Utsav Gupta
          Dec 26 '18 at 13:37





          I have one issue is, now the "location_id" is showing in each address. How can i remove it?

          – Utsav Gupta
          Dec 26 '18 at 13:37













          I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

          – Utsav Gupta
          Dec 27 '18 at 11:34





          I got the issue, I have "'visible' => true," in addAttribute. we need to set it as FALSE.

          – Utsav Gupta
          Dec 27 '18 at 11:34













          0














          ------- CREATE CUSTOMER ADDRESS ATTRIBUTE --------



          Step 1 : create app/code/Dckap/CustomerAddressAttribute



          Step 2 : Create app/code/Dckap/CustomerAddressAttribute/etc/module.xml



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
          <module name="Dckap_CustomerAddressAttribute" setup_version="1.0.0">
          </module>
          </config>


          Step 3 : Create app/code/Dckap/CustomerAddressAttribute/registration.php



           <?php

          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          'Dckap_CustomerAddressAttribute',
          __DIR__
          );


          Step 4 : Create app/code/Dckap/CustomerAddressAttribute/Setup/InstallData.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavSetupEavSetup;
          use MagentoEavSetupEavSetupFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * EAV setup factory
          *
          * @var EavSetupFactory
          */
          private $eavSetupFactory;

          /**
          * Init
          *
          * @param EavSetupFactory $eavSetupFactory
          */
          public function __construct(EavSetupFactory $eavSetupFactory)

          $this->eavSetupFactory = $eavSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

          /** @var EavSetup $eavSetup */
          $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
          if (version_compare($context->getVersion(), '1.0.0') < 0)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSetup = $objectManager->create('DckapCustomerAddressAttributeSetupCustomerSetup');
          $customerSetup->installAttributes($customerSetup);









          Step 5 : Create app/code/Dckap/CustomerAddressAttribute/Setup/CustomerSetup.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavModelConfig;
          use MagentoEavModelEntitySetupContext;
          use MagentoEavSetupEavSetup;
          use MagentoFrameworkAppCacheInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;

          class CustomerSetup extends EavSetup

          protected $eavConfig;

          public function __construct(
          ModuleDataSetupInterface $setup,
          Context $context,
          CacheInterface $cache,
          CollectionFactory $attrGroupCollectionFactory,
          Config $eavConfig
          )
          $this -> eavConfig = $eavConfig;
          parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);


          public function installAttributes($customerSetup)
          $this -> installCustomerAttributes($customerSetup);
          $this -> installCustomerAddressAttributes($customerSetup);


          public function installCustomerAttributes($customerSetup)



          public function installCustomerAddressAttributes($customerSetup)


          $customerSetup -> addAttribute('customer_address',
          'custom_address_attribute',
          [
          'label' => 'Customer Address Attribute',
          'system' => 0,
          'user_defined' => true,
          'position' => 100,
          'sort_order' =>100,
          'visible' => true,
          'default_value' => '',
          'note' => '',
          'type' => 'varchar',
          'input' => 'text',

          ]
          );

          $customerSetup -> getEavConfig() -> getAttribute('customer_address', 'custom_address_attribute')->setData('is_user_defined',1)->setData('default_value','')-> setData('used_in_forms', ['adminhtml_customer_address', 'customer_register_address', 'customer_address_edit']) -> save();




          public function getEavConfig()
          return $this -> eavConfig;




          Finaly run command



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer

























          • Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

            – Utsav Gupta
            Dec 17 '18 at 9:58











          • I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

            – Utsav Gupta
            Dec 26 '18 at 13:31















          0














          ------- CREATE CUSTOMER ADDRESS ATTRIBUTE --------



          Step 1 : create app/code/Dckap/CustomerAddressAttribute



          Step 2 : Create app/code/Dckap/CustomerAddressAttribute/etc/module.xml



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
          <module name="Dckap_CustomerAddressAttribute" setup_version="1.0.0">
          </module>
          </config>


          Step 3 : Create app/code/Dckap/CustomerAddressAttribute/registration.php



           <?php

          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          'Dckap_CustomerAddressAttribute',
          __DIR__
          );


          Step 4 : Create app/code/Dckap/CustomerAddressAttribute/Setup/InstallData.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavSetupEavSetup;
          use MagentoEavSetupEavSetupFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * EAV setup factory
          *
          * @var EavSetupFactory
          */
          private $eavSetupFactory;

          /**
          * Init
          *
          * @param EavSetupFactory $eavSetupFactory
          */
          public function __construct(EavSetupFactory $eavSetupFactory)

          $this->eavSetupFactory = $eavSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

          /** @var EavSetup $eavSetup */
          $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
          if (version_compare($context->getVersion(), '1.0.0') < 0)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSetup = $objectManager->create('DckapCustomerAddressAttributeSetupCustomerSetup');
          $customerSetup->installAttributes($customerSetup);









          Step 5 : Create app/code/Dckap/CustomerAddressAttribute/Setup/CustomerSetup.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavModelConfig;
          use MagentoEavModelEntitySetupContext;
          use MagentoEavSetupEavSetup;
          use MagentoFrameworkAppCacheInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;

          class CustomerSetup extends EavSetup

          protected $eavConfig;

          public function __construct(
          ModuleDataSetupInterface $setup,
          Context $context,
          CacheInterface $cache,
          CollectionFactory $attrGroupCollectionFactory,
          Config $eavConfig
          )
          $this -> eavConfig = $eavConfig;
          parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);


          public function installAttributes($customerSetup)
          $this -> installCustomerAttributes($customerSetup);
          $this -> installCustomerAddressAttributes($customerSetup);


          public function installCustomerAttributes($customerSetup)



          public function installCustomerAddressAttributes($customerSetup)


          $customerSetup -> addAttribute('customer_address',
          'custom_address_attribute',
          [
          'label' => 'Customer Address Attribute',
          'system' => 0,
          'user_defined' => true,
          'position' => 100,
          'sort_order' =>100,
          'visible' => true,
          'default_value' => '',
          'note' => '',
          'type' => 'varchar',
          'input' => 'text',

          ]
          );

          $customerSetup -> getEavConfig() -> getAttribute('customer_address', 'custom_address_attribute')->setData('is_user_defined',1)->setData('default_value','')-> setData('used_in_forms', ['adminhtml_customer_address', 'customer_register_address', 'customer_address_edit']) -> save();




          public function getEavConfig()
          return $this -> eavConfig;




          Finaly run command



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer

























          • Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

            – Utsav Gupta
            Dec 17 '18 at 9:58











          • I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

            – Utsav Gupta
            Dec 26 '18 at 13:31













          0












          0








          0







          ------- CREATE CUSTOMER ADDRESS ATTRIBUTE --------



          Step 1 : create app/code/Dckap/CustomerAddressAttribute



          Step 2 : Create app/code/Dckap/CustomerAddressAttribute/etc/module.xml



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
          <module name="Dckap_CustomerAddressAttribute" setup_version="1.0.0">
          </module>
          </config>


          Step 3 : Create app/code/Dckap/CustomerAddressAttribute/registration.php



           <?php

          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          'Dckap_CustomerAddressAttribute',
          __DIR__
          );


          Step 4 : Create app/code/Dckap/CustomerAddressAttribute/Setup/InstallData.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavSetupEavSetup;
          use MagentoEavSetupEavSetupFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * EAV setup factory
          *
          * @var EavSetupFactory
          */
          private $eavSetupFactory;

          /**
          * Init
          *
          * @param EavSetupFactory $eavSetupFactory
          */
          public function __construct(EavSetupFactory $eavSetupFactory)

          $this->eavSetupFactory = $eavSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

          /** @var EavSetup $eavSetup */
          $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
          if (version_compare($context->getVersion(), '1.0.0') < 0)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSetup = $objectManager->create('DckapCustomerAddressAttributeSetupCustomerSetup');
          $customerSetup->installAttributes($customerSetup);









          Step 5 : Create app/code/Dckap/CustomerAddressAttribute/Setup/CustomerSetup.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavModelConfig;
          use MagentoEavModelEntitySetupContext;
          use MagentoEavSetupEavSetup;
          use MagentoFrameworkAppCacheInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;

          class CustomerSetup extends EavSetup

          protected $eavConfig;

          public function __construct(
          ModuleDataSetupInterface $setup,
          Context $context,
          CacheInterface $cache,
          CollectionFactory $attrGroupCollectionFactory,
          Config $eavConfig
          )
          $this -> eavConfig = $eavConfig;
          parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);


          public function installAttributes($customerSetup)
          $this -> installCustomerAttributes($customerSetup);
          $this -> installCustomerAddressAttributes($customerSetup);


          public function installCustomerAttributes($customerSetup)



          public function installCustomerAddressAttributes($customerSetup)


          $customerSetup -> addAttribute('customer_address',
          'custom_address_attribute',
          [
          'label' => 'Customer Address Attribute',
          'system' => 0,
          'user_defined' => true,
          'position' => 100,
          'sort_order' =>100,
          'visible' => true,
          'default_value' => '',
          'note' => '',
          'type' => 'varchar',
          'input' => 'text',

          ]
          );

          $customerSetup -> getEavConfig() -> getAttribute('customer_address', 'custom_address_attribute')->setData('is_user_defined',1)->setData('default_value','')-> setData('used_in_forms', ['adminhtml_customer_address', 'customer_register_address', 'customer_address_edit']) -> save();




          public function getEavConfig()
          return $this -> eavConfig;




          Finaly run command



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush





          share|improve this answer













          ------- CREATE CUSTOMER ADDRESS ATTRIBUTE --------



          Step 1 : create app/code/Dckap/CustomerAddressAttribute



          Step 2 : Create app/code/Dckap/CustomerAddressAttribute/etc/module.xml



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
          <module name="Dckap_CustomerAddressAttribute" setup_version="1.0.0">
          </module>
          </config>


          Step 3 : Create app/code/Dckap/CustomerAddressAttribute/registration.php



           <?php

          MagentoFrameworkComponentComponentRegistrar::register(
          MagentoFrameworkComponentComponentRegistrar::MODULE,
          'Dckap_CustomerAddressAttribute',
          __DIR__
          );


          Step 4 : Create app/code/Dckap/CustomerAddressAttribute/Setup/InstallData.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavSetupEavSetup;
          use MagentoEavSetupEavSetupFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * EAV setup factory
          *
          * @var EavSetupFactory
          */
          private $eavSetupFactory;

          /**
          * Init
          *
          * @param EavSetupFactory $eavSetupFactory
          */
          public function __construct(EavSetupFactory $eavSetupFactory)

          $this->eavSetupFactory = $eavSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

          /** @var EavSetup $eavSetup */
          $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
          if (version_compare($context->getVersion(), '1.0.0') < 0)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $customerSetup = $objectManager->create('DckapCustomerAddressAttributeSetupCustomerSetup');
          $customerSetup->installAttributes($customerSetup);









          Step 5 : Create app/code/Dckap/CustomerAddressAttribute/Setup/CustomerSetup.php



           <?php

          namespace DckapCustomerAddressAttributeSetup;

          use MagentoEavModelConfig;
          use MagentoEavModelEntitySetupContext;
          use MagentoEavSetupEavSetup;
          use MagentoFrameworkAppCacheInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;

          class CustomerSetup extends EavSetup

          protected $eavConfig;

          public function __construct(
          ModuleDataSetupInterface $setup,
          Context $context,
          CacheInterface $cache,
          CollectionFactory $attrGroupCollectionFactory,
          Config $eavConfig
          )
          $this -> eavConfig = $eavConfig;
          parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);


          public function installAttributes($customerSetup)
          $this -> installCustomerAttributes($customerSetup);
          $this -> installCustomerAddressAttributes($customerSetup);


          public function installCustomerAttributes($customerSetup)



          public function installCustomerAddressAttributes($customerSetup)


          $customerSetup -> addAttribute('customer_address',
          'custom_address_attribute',
          [
          'label' => 'Customer Address Attribute',
          'system' => 0,
          'user_defined' => true,
          'position' => 100,
          'sort_order' =>100,
          'visible' => true,
          'default_value' => '',
          'note' => '',
          'type' => 'varchar',
          'input' => 'text',

          ]
          );

          $customerSetup -> getEavConfig() -> getAttribute('customer_address', 'custom_address_attribute')->setData('is_user_defined',1)->setData('default_value','')-> setData('used_in_forms', ['adminhtml_customer_address', 'customer_register_address', 'customer_address_edit']) -> save();




          public function getEavConfig()
          return $this -> eavConfig;




          Finaly run command



          php bin/magento setup:upgrade
          php bin/magento setup:static-content:deploy -f
          php bin/magento cache:clean
          php bin/magento cache:flush






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 17 '18 at 9:50









          AjithkumarAjithkumar

          14211 bronze badges




          14211 bronze badges















          • Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

            – Utsav Gupta
            Dec 17 '18 at 9:58











          • I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

            – Utsav Gupta
            Dec 26 '18 at 13:31

















          • Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

            – Utsav Gupta
            Dec 17 '18 at 9:58











          • I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

            – Utsav Gupta
            Dec 26 '18 at 13:31
















          Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

          – Utsav Gupta
          Dec 17 '18 at 9:58





          Thanks for your help but i already added attribute to customer_address. now i want to set custom value for that attribute. please help for that.

          – Utsav Gupta
          Dec 17 '18 at 9:58













          I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

          – Utsav Gupta
          Dec 26 '18 at 13:31





          I have created "location_id" attribute using the same code, now that 'location_id' is showing in checkout address. I don't want to show it anywhere. I used in the code: 'used_in_forms' => [ //'adminhtml_customer_address', //'customer_address_edit', //'customer_register_address' ], is there something wrong?

          – Utsav Gupta
          Dec 26 '18 at 13:31

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254856%2fmagento-2-how-to-add-custom-attribute-to-customer-address-and-how-to-insert-valu%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?