Magento 2 custom address fields not saving to database from checkout












6















Through a setup script I created two new customer address fields for Magento 2. These field show up nicely in the backend and checkout. But, the values are not send from checkout to the api. Now the fields are not saved into the database.



Also, when editing the order address in the backend the values aren't stored. The values are only stored when editing the customer address through the customer itself.



What am I missing!? The Magento docs about adding a shipping field aren't helping me...










share|improve this question

























  • How did you add the fields?

    – LM_Fielding
    Jun 19 '17 at 16:47











  • magento.stackexchange.com/questions/126036/…

    – LM_Fielding
    Jun 29 '17 at 13:08
















6















Through a setup script I created two new customer address fields for Magento 2. These field show up nicely in the backend and checkout. But, the values are not send from checkout to the api. Now the fields are not saved into the database.



Also, when editing the order address in the backend the values aren't stored. The values are only stored when editing the customer address through the customer itself.



What am I missing!? The Magento docs about adding a shipping field aren't helping me...










share|improve this question

























  • How did you add the fields?

    – LM_Fielding
    Jun 19 '17 at 16:47











  • magento.stackexchange.com/questions/126036/…

    – LM_Fielding
    Jun 29 '17 at 13:08














6












6








6








Through a setup script I created two new customer address fields for Magento 2. These field show up nicely in the backend and checkout. But, the values are not send from checkout to the api. Now the fields are not saved into the database.



Also, when editing the order address in the backend the values aren't stored. The values are only stored when editing the customer address through the customer itself.



What am I missing!? The Magento docs about adding a shipping field aren't helping me...










share|improve this question
















Through a setup script I created two new customer address fields for Magento 2. These field show up nicely in the backend and checkout. But, the values are not send from checkout to the api. Now the fields are not saved into the database.



Also, when editing the order address in the backend the values aren't stored. The values are only stored when editing the customer address through the customer itself.



What am I missing!? The Magento docs about adding a shipping field aren't helping me...







magento2 checkout customer-address






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 18 '18 at 5:21









Purushotam Sharma

8581628




8581628










asked Dec 2 '16 at 7:59









RikWRikW

13616




13616













  • How did you add the fields?

    – LM_Fielding
    Jun 19 '17 at 16:47











  • magento.stackexchange.com/questions/126036/…

    – LM_Fielding
    Jun 29 '17 at 13:08



















  • How did you add the fields?

    – LM_Fielding
    Jun 19 '17 at 16:47











  • magento.stackexchange.com/questions/126036/…

    – LM_Fielding
    Jun 29 '17 at 13:08

















How did you add the fields?

– LM_Fielding
Jun 19 '17 at 16:47





How did you add the fields?

– LM_Fielding
Jun 19 '17 at 16:47













magento.stackexchange.com/questions/126036/…

– LM_Fielding
Jun 29 '17 at 13:08





magento.stackexchange.com/questions/126036/…

– LM_Fielding
Jun 29 '17 at 13:08










1 Answer
1






active

oldest

votes


















0














This usually happens when you specify "system" => "1" for the customer attributes. In order to make this working, you may create an upgrade script to set "system" => "0".



Here's an example:



app/code/YourVendor/YourModule/Setup/UpgradeData.php



use MagentoFrameworkSetupUpgradeDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerSetupCustomerSetupFactory
use MagentoCustomerSetupCustomerSetup;
use MagentoCustomerModelCustomer;
...

public function __construct(
CustomerSetupFactory $customerSetupFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
}
...

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
if (version_compare($context->getVersion(), '0.2.0') < 0) {
$customerSetup = $this->customerSetupFactory->create();
$customerSetup->getEavConfig()
->getAttribute(Customer::ENTITY, 'example_attribute_code')
->setData('is_user_defined', 1)
->setData('system', 1)
->save();
}
}





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%2f148552%2fmagento-2-custom-address-fields-not-saving-to-database-from-checkout%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









    0














    This usually happens when you specify "system" => "1" for the customer attributes. In order to make this working, you may create an upgrade script to set "system" => "0".



    Here's an example:



    app/code/YourVendor/YourModule/Setup/UpgradeData.php



    use MagentoFrameworkSetupUpgradeDataInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;
    use MagentoCustomerSetupCustomerSetupFactory
    use MagentoCustomerSetupCustomerSetup;
    use MagentoCustomerModelCustomer;
    ...

    public function __construct(
    CustomerSetupFactory $customerSetupFactory
    ) {
    $this->customerSetupFactory = $customerSetupFactory;
    }
    ...

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
    if (version_compare($context->getVersion(), '0.2.0') < 0) {
    $customerSetup = $this->customerSetupFactory->create();
    $customerSetup->getEavConfig()
    ->getAttribute(Customer::ENTITY, 'example_attribute_code')
    ->setData('is_user_defined', 1)
    ->setData('system', 1)
    ->save();
    }
    }





    share|improve this answer




























      0














      This usually happens when you specify "system" => "1" for the customer attributes. In order to make this working, you may create an upgrade script to set "system" => "0".



      Here's an example:



      app/code/YourVendor/YourModule/Setup/UpgradeData.php



      use MagentoFrameworkSetupUpgradeDataInterface;
      use MagentoFrameworkSetupModuleContextInterface;
      use MagentoFrameworkSetupModuleDataSetupInterface;
      use MagentoCustomerSetupCustomerSetupFactory
      use MagentoCustomerSetupCustomerSetup;
      use MagentoCustomerModelCustomer;
      ...

      public function __construct(
      CustomerSetupFactory $customerSetupFactory
      ) {
      $this->customerSetupFactory = $customerSetupFactory;
      }
      ...

      public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
      {
      if (version_compare($context->getVersion(), '0.2.0') < 0) {
      $customerSetup = $this->customerSetupFactory->create();
      $customerSetup->getEavConfig()
      ->getAttribute(Customer::ENTITY, 'example_attribute_code')
      ->setData('is_user_defined', 1)
      ->setData('system', 1)
      ->save();
      }
      }





      share|improve this answer


























        0












        0








        0







        This usually happens when you specify "system" => "1" for the customer attributes. In order to make this working, you may create an upgrade script to set "system" => "0".



        Here's an example:



        app/code/YourVendor/YourModule/Setup/UpgradeData.php



        use MagentoFrameworkSetupUpgradeDataInterface;
        use MagentoFrameworkSetupModuleContextInterface;
        use MagentoFrameworkSetupModuleDataSetupInterface;
        use MagentoCustomerSetupCustomerSetupFactory
        use MagentoCustomerSetupCustomerSetup;
        use MagentoCustomerModelCustomer;
        ...

        public function __construct(
        CustomerSetupFactory $customerSetupFactory
        ) {
        $this->customerSetupFactory = $customerSetupFactory;
        }
        ...

        public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
        if (version_compare($context->getVersion(), '0.2.0') < 0) {
        $customerSetup = $this->customerSetupFactory->create();
        $customerSetup->getEavConfig()
        ->getAttribute(Customer::ENTITY, 'example_attribute_code')
        ->setData('is_user_defined', 1)
        ->setData('system', 1)
        ->save();
        }
        }





        share|improve this answer













        This usually happens when you specify "system" => "1" for the customer attributes. In order to make this working, you may create an upgrade script to set "system" => "0".



        Here's an example:



        app/code/YourVendor/YourModule/Setup/UpgradeData.php



        use MagentoFrameworkSetupUpgradeDataInterface;
        use MagentoFrameworkSetupModuleContextInterface;
        use MagentoFrameworkSetupModuleDataSetupInterface;
        use MagentoCustomerSetupCustomerSetupFactory
        use MagentoCustomerSetupCustomerSetup;
        use MagentoCustomerModelCustomer;
        ...

        public function __construct(
        CustomerSetupFactory $customerSetupFactory
        ) {
        $this->customerSetupFactory = $customerSetupFactory;
        }
        ...

        public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
        if (version_compare($context->getVersion(), '0.2.0') < 0) {
        $customerSetup = $this->customerSetupFactory->create();
        $customerSetup->getEavConfig()
        ->getAttribute(Customer::ENTITY, 'example_attribute_code')
        ->setData('is_user_defined', 1)
        ->setData('system', 1)
        ->save();
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 16 '18 at 11:27









        Nikita AbrashnevNikita Abrashnev

        819




        819






























            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%2f148552%2fmagento-2-custom-address-fields-not-saving-to-database-from-checkout%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

            1300-talet

            1300-talet

            Display a custom attribute below product name in the front-end Magento 1.9.3.8