Can't create custom attribute for order_addressLoading a customer address by a custom attributeError during upgrade to Magento 2.1 from 2.0.7main.CRITICAL: Plugin class doesn't existMagento 2.1.5 How to create Module which can use Eav functionalities (addAttribute in my case)Set default value for attribute in Setup Script in Magento 2I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.3 Can't view module's front end page output?Magento 2 How to upgrade existing custom customer address attribute?Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?cannot save my custom attribut product before save event magento 2

What Armor Optimization applies to a Mithral full plate?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Count all vowels in string

Why does this if statement return true

My players want to grind XP but we're using milestone advancement

Natural Armour and Weapons

Security vulnerabilities of POST over SSL

Why did Jon Snow do this immoral act if he is so honorable?

How to patch glass cuts in a bicycle tire?

Why do Russians almost not use verbs of possession akin to "have"?

Time complexity of an algorithm: Is it important to state the base of the logarithm?

Did this character show any indication of wanting to rule before S8E6?

Must a warlock replace spells with new spells of exactly their Pact Magic spell slot level?

What weight should be given to writers groups critiques?

Does French have the English "short i" vowel?

Drums and punctuation

On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?

What does kpsewhich stand for?

Why did the person in charge of a principality not just declare themself king?

Are runways booked by airlines to land their planes?

Gravitational effects of a single human body on the motion of planets

Are black holes spherical during merger?

How can I make an argument that my time is valuable?

Python program to take in two strings and print the larger string



Can't create custom attribute for order_address


Loading a customer address by a custom attributeError during upgrade to Magento 2.1 from 2.0.7main.CRITICAL: Plugin class doesn't existMagento 2.1.5 How to create Module which can use Eav functionalities (addAttribute in my case)Set default value for attribute in Setup Script in Magento 2I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.3 Can't view module's front end page output?Magento 2 How to upgrade existing custom customer address attribute?Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?cannot save my custom attribut product before save event magento 2






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








0















I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose.



I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see the input appeared in the admin panel but the file in the log folder is created.



<?php

namespace Maru3lSyncOrchestraSetup;

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

class InstallData implements InstallDataInterface

/**
* Attribute Code of the Orchestra ID attribute
*/
const ORECHESTRA_ID_ATTRIBUTE_CODE = 'orchestra_id';

/**
* @var EavSetupFactory
*/
protected $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory)

$this->eavSetupFactory = $eavSetupFactory;


/**
* Install Orchestra id attribute
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

$setup->startSetup();

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

$eavSetup->addAttribute(
'customer_address',
self::ORECHESTRA_ID_ATTRIBUTE_CODE,
[
'label' => 'Orchestra ID',
'input' => 'text',
'visible' => true,
'position' => 100,
'unique' => true,
'required' => false,
'system' => false
]
);

$dumpFile = fopen('/var/www/vhosts/store-api.silverwax.ca/httpdocs/var/log/dataDump', 'w+');
fwrite($dumpFile, 'Install eav n');

$setup->endSetup();




I've also created the Maru3l/SyncOrchestra/etc/extension_attributes.xml:



<?xml version="1.0"?>
<!--
/**
* Copyright © Mageside. All rights reserved.
* See MS-LICENSE.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="MagentoSalesApiDataOrderAddressInterface">
<attribute code="orchestra_id" type="string" />
</extension_attributes>
</config>


My other concern is how can I get or set the value programmatically.










share|improve this question




























    0















    I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose.



    I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see the input appeared in the admin panel but the file in the log folder is created.



    <?php

    namespace Maru3lSyncOrchestraSetup;

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

    class InstallData implements InstallDataInterface

    /**
    * Attribute Code of the Orchestra ID attribute
    */
    const ORECHESTRA_ID_ATTRIBUTE_CODE = 'orchestra_id';

    /**
    * @var EavSetupFactory
    */
    protected $eavSetupFactory;

    public function __construct(EavSetupFactory $eavSetupFactory)

    $this->eavSetupFactory = $eavSetupFactory;


    /**
    * Install Orchestra id attribute
    *
    * @param ModuleDataSetupInterface $setup
    * @param ModuleContextInterface $context
    * @return void
    */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

    $setup->startSetup();

    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    $eavSetup->addAttribute(
    'customer_address',
    self::ORECHESTRA_ID_ATTRIBUTE_CODE,
    [
    'label' => 'Orchestra ID',
    'input' => 'text',
    'visible' => true,
    'position' => 100,
    'unique' => true,
    'required' => false,
    'system' => false
    ]
    );

    $dumpFile = fopen('/var/www/vhosts/store-api.silverwax.ca/httpdocs/var/log/dataDump', 'w+');
    fwrite($dumpFile, 'Install eav n');

    $setup->endSetup();




    I've also created the Maru3l/SyncOrchestra/etc/extension_attributes.xml:



    <?xml version="1.0"?>
    <!--
    /**
    * Copyright © Mageside. All rights reserved.
    * See MS-LICENSE.txt for license details.
    */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="MagentoSalesApiDataOrderAddressInterface">
    <attribute code="orchestra_id" type="string" />
    </extension_attributes>
    </config>


    My other concern is how can I get or set the value programmatically.










    share|improve this question
























      0












      0








      0








      I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose.



      I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see the input appeared in the admin panel but the file in the log folder is created.



      <?php

      namespace Maru3lSyncOrchestraSetup;

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

      class InstallData implements InstallDataInterface

      /**
      * Attribute Code of the Orchestra ID attribute
      */
      const ORECHESTRA_ID_ATTRIBUTE_CODE = 'orchestra_id';

      /**
      * @var EavSetupFactory
      */
      protected $eavSetupFactory;

      public function __construct(EavSetupFactory $eavSetupFactory)

      $this->eavSetupFactory = $eavSetupFactory;


      /**
      * Install Orchestra id attribute
      *
      * @param ModuleDataSetupInterface $setup
      * @param ModuleContextInterface $context
      * @return void
      */
      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

      $setup->startSetup();

      $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

      $eavSetup->addAttribute(
      'customer_address',
      self::ORECHESTRA_ID_ATTRIBUTE_CODE,
      [
      'label' => 'Orchestra ID',
      'input' => 'text',
      'visible' => true,
      'position' => 100,
      'unique' => true,
      'required' => false,
      'system' => false
      ]
      );

      $dumpFile = fopen('/var/www/vhosts/store-api.silverwax.ca/httpdocs/var/log/dataDump', 'w+');
      fwrite($dumpFile, 'Install eav n');

      $setup->endSetup();




      I've also created the Maru3l/SyncOrchestra/etc/extension_attributes.xml:



      <?xml version="1.0"?>
      <!--
      /**
      * Copyright © Mageside. All rights reserved.
      * See MS-LICENSE.txt for license details.
      */
      -->
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
      <extension_attributes for="MagentoSalesApiDataOrderAddressInterface">
      <attribute code="orchestra_id" type="string" />
      </extension_attributes>
      </config>


      My other concern is how can I get or set the value programmatically.










      share|improve this question














      I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose.



      I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see the input appeared in the admin panel but the file in the log folder is created.



      <?php

      namespace Maru3lSyncOrchestraSetup;

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

      class InstallData implements InstallDataInterface

      /**
      * Attribute Code of the Orchestra ID attribute
      */
      const ORECHESTRA_ID_ATTRIBUTE_CODE = 'orchestra_id';

      /**
      * @var EavSetupFactory
      */
      protected $eavSetupFactory;

      public function __construct(EavSetupFactory $eavSetupFactory)

      $this->eavSetupFactory = $eavSetupFactory;


      /**
      * Install Orchestra id attribute
      *
      * @param ModuleDataSetupInterface $setup
      * @param ModuleContextInterface $context
      * @return void
      */
      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

      $setup->startSetup();

      $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

      $eavSetup->addAttribute(
      'customer_address',
      self::ORECHESTRA_ID_ATTRIBUTE_CODE,
      [
      'label' => 'Orchestra ID',
      'input' => 'text',
      'visible' => true,
      'position' => 100,
      'unique' => true,
      'required' => false,
      'system' => false
      ]
      );

      $dumpFile = fopen('/var/www/vhosts/store-api.silverwax.ca/httpdocs/var/log/dataDump', 'w+');
      fwrite($dumpFile, 'Install eav n');

      $setup->endSetup();




      I've also created the Maru3l/SyncOrchestra/etc/extension_attributes.xml:



      <?xml version="1.0"?>
      <!--
      /**
      * Copyright © Mageside. All rights reserved.
      * See MS-LICENSE.txt for license details.
      */
      -->
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
      <extension_attributes for="MagentoSalesApiDataOrderAddressInterface">
      <attribute code="orchestra_id" type="string" />
      </extension_attributes>
      </config>


      My other concern is how can I get or set the value programmatically.







      magento2 shipping-address eav programmatically






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 17 at 21:37









      maru3lmaru3l

      436




      436




















          1 Answer
          1






          active

          oldest

          votes


















          1














          I recently covered loading address by custom attribute in question. I created a extension to test the theory. Setup is included within it. But here it is



          <?php
          namespace XigenAddressSetup;
          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', 'backoffice_id', [
          'type' => 'int',
          'label' => 'Backoffice Id',
          'input' => 'text',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 50,
          'position' => 50,
          'system' => 0,
          ]);
          $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'backoffice_id')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => [
          'adminhtml_customer_address',
          'customer_address_edit',
          'customer_register_address',
          ],
          ]);
          $attribute->save();




          Here you go



          https://github.com/DominicWatts/Magento-2-Custom-Address



          Here is my original question



          Loading a customer address by a custom attribute



          You can save in admin. Or load address using getById and set it.



          /**
          * @var MagentoCustomerApiAddressRepositoryInterface
          */
          protected $addressRepository;

          /**
          * Sync constructor.
          * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
          */
          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $addressRepository
          )
          $this->addressRepository = $addressRepository;


          public function changeAddress($addressId)

          /** @var MagentoCustomerApiDataAddressInterface $address */
          $address = $this->addressRepository->getById($addressId);
          // whatever
          $this->addressRepository->save($address);






          share|improve this answer























            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%2f275087%2fcant-create-custom-attribute-for-order-address%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I recently covered loading address by custom attribute in question. I created a extension to test the theory. Setup is included within it. But here it is



            <?php
            namespace XigenAddressSetup;
            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', 'backoffice_id', [
            'type' => 'int',
            'label' => 'Backoffice Id',
            'input' => 'text',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 50,
            'position' => 50,
            'system' => 0,
            ]);
            $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'backoffice_id')
            ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => [
            'adminhtml_customer_address',
            'customer_address_edit',
            'customer_register_address',
            ],
            ]);
            $attribute->save();




            Here you go



            https://github.com/DominicWatts/Magento-2-Custom-Address



            Here is my original question



            Loading a customer address by a custom attribute



            You can save in admin. Or load address using getById and set it.



            /**
            * @var MagentoCustomerApiAddressRepositoryInterface
            */
            protected $addressRepository;

            /**
            * Sync constructor.
            * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
            */
            public function __construct(
            MagentoCustomerApiAddressRepositoryInterface $addressRepository
            )
            $this->addressRepository = $addressRepository;


            public function changeAddress($addressId)

            /** @var MagentoCustomerApiDataAddressInterface $address */
            $address = $this->addressRepository->getById($addressId);
            // whatever
            $this->addressRepository->save($address);






            share|improve this answer



























              1














              I recently covered loading address by custom attribute in question. I created a extension to test the theory. Setup is included within it. But here it is



              <?php
              namespace XigenAddressSetup;
              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', 'backoffice_id', [
              'type' => 'int',
              'label' => 'Backoffice Id',
              'input' => 'text',
              'required' => false,
              'visible' => true,
              'user_defined' => true,
              'sort_order' => 50,
              'position' => 50,
              'system' => 0,
              ]);
              $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'backoffice_id')
              ->addData([
              'attribute_set_id' => $attributeSetId,
              'attribute_group_id' => $attributeGroupId,
              'used_in_forms' => [
              'adminhtml_customer_address',
              'customer_address_edit',
              'customer_register_address',
              ],
              ]);
              $attribute->save();




              Here you go



              https://github.com/DominicWatts/Magento-2-Custom-Address



              Here is my original question



              Loading a customer address by a custom attribute



              You can save in admin. Or load address using getById and set it.



              /**
              * @var MagentoCustomerApiAddressRepositoryInterface
              */
              protected $addressRepository;

              /**
              * Sync constructor.
              * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
              */
              public function __construct(
              MagentoCustomerApiAddressRepositoryInterface $addressRepository
              )
              $this->addressRepository = $addressRepository;


              public function changeAddress($addressId)

              /** @var MagentoCustomerApiDataAddressInterface $address */
              $address = $this->addressRepository->getById($addressId);
              // whatever
              $this->addressRepository->save($address);






              share|improve this answer

























                1












                1








                1







                I recently covered loading address by custom attribute in question. I created a extension to test the theory. Setup is included within it. But here it is



                <?php
                namespace XigenAddressSetup;
                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', 'backoffice_id', [
                'type' => 'int',
                'label' => 'Backoffice Id',
                'input' => 'text',
                'required' => false,
                'visible' => true,
                'user_defined' => true,
                'sort_order' => 50,
                'position' => 50,
                'system' => 0,
                ]);
                $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'backoffice_id')
                ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => [
                'adminhtml_customer_address',
                'customer_address_edit',
                'customer_register_address',
                ],
                ]);
                $attribute->save();




                Here you go



                https://github.com/DominicWatts/Magento-2-Custom-Address



                Here is my original question



                Loading a customer address by a custom attribute



                You can save in admin. Or load address using getById and set it.



                /**
                * @var MagentoCustomerApiAddressRepositoryInterface
                */
                protected $addressRepository;

                /**
                * Sync constructor.
                * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
                */
                public function __construct(
                MagentoCustomerApiAddressRepositoryInterface $addressRepository
                )
                $this->addressRepository = $addressRepository;


                public function changeAddress($addressId)

                /** @var MagentoCustomerApiDataAddressInterface $address */
                $address = $this->addressRepository->getById($addressId);
                // whatever
                $this->addressRepository->save($address);






                share|improve this answer













                I recently covered loading address by custom attribute in question. I created a extension to test the theory. Setup is included within it. But here it is



                <?php
                namespace XigenAddressSetup;
                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', 'backoffice_id', [
                'type' => 'int',
                'label' => 'Backoffice Id',
                'input' => 'text',
                'required' => false,
                'visible' => true,
                'user_defined' => true,
                'sort_order' => 50,
                'position' => 50,
                'system' => 0,
                ]);
                $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'backoffice_id')
                ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => [
                'adminhtml_customer_address',
                'customer_address_edit',
                'customer_register_address',
                ],
                ]);
                $attribute->save();




                Here you go



                https://github.com/DominicWatts/Magento-2-Custom-Address



                Here is my original question



                Loading a customer address by a custom attribute



                You can save in admin. Or load address using getById and set it.



                /**
                * @var MagentoCustomerApiAddressRepositoryInterface
                */
                protected $addressRepository;

                /**
                * Sync constructor.
                * @param MagentoCustomerApiAddressRepositoryInterface $addressRepository
                */
                public function __construct(
                MagentoCustomerApiAddressRepositoryInterface $addressRepository
                )
                $this->addressRepository = $addressRepository;


                public function changeAddress($addressId)

                /** @var MagentoCustomerApiDataAddressInterface $address */
                $address = $this->addressRepository->getById($addressId);
                // whatever
                $this->addressRepository->save($address);







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 17 at 23:16









                Dominic XigenDominic Xigen

                49610




                49610



























                    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%2f275087%2fcant-create-custom-attribute-for-order-address%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?