7

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...

Purushotam Sharma
1,6772 gold badges28 silver badges62 bronze badges
asked Dec 2, 2016 at 7:59
2

1 Answer 1

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 Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Model\Customer;
...
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', 0)
 ->save();
 }
}
answered Oct 16, 2018 at 11:27
2
  • The example does the opposite to the suggestion? Commented Feb 2, 2022 at 13:08
  • @Tisch In this example I'm just showing how to change the value of 'system'. You can either set it to 1 or to 0, whatever you need in your specific situation. Commented Feb 22, 2022 at 19:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.