Magento 2 custom address fields not saving to database from checkout
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
add a comment |
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
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
add a comment |
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
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
magento2 checkout customer-address
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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();
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
}
}
add a comment |
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();
}
}
add a comment |
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();
}
}
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();
}
}
answered Oct 16 '18 at 11:27
Nikita AbrashnevNikita Abrashnev
819
819
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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