magento2: Magento 2.1 Customer address attribute is not saved into database
Preconditions
- Magento 2.1.1
Steps to reproduce
-
Add new custom attribute via
InstallData.phpwithinstallfunction content:/** @var \Magento\Customer\Setup\CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $attributesInfo = [ 'company_info' => [ 'label' => 'Company Info', 'type' => 'static', 'input' => 'textarea', 'position' => 65, 'visible' => true, 'system' => false, 'user_defined' => false, 'required' => false, 'validate_rules' => 'a:1:{s:15:"max_text_length";i:500;}' ], 'telephone_secondary' => [ 'label' => 'Secondary Phone Number', 'type' => 'static', 'input' => 'text', 'position' => 125, 'visible' => true, 'system' => false, 'user_defined' => false, 'required' => false, ] ]; $columns = [ 'company_info' => [ 'type' => Table::TYPE_TEXT, 'nullable' => true, 'default' => null, 'comment' => 'Company Info', ], 'telephone_secondary' => [ 'type' => Table::TYPE_TEXT, 'nullable' => true, 'default' => null, 'length' => 255, 'comment' => 'Secondary Phone Number', ] ]; $tableNames = [ 'customer_address_entity', 'quote_address', 'sales_order_address' ]; foreach ($attributesInfo as $attributeCode => $attributeParams) { $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams); $customerSetup->getEavConfig()->getAttribute('customer_address', $attributeCode) ->setData('attribute_set_id', AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS) ->setData('used_in_forms', [ 'customer_address_edit', 'customer_register_address', 'adminhtml_customer_address' ]) ->save(); } $connection = $setup->getConnection(); foreach ($tableNames as $tableName) { foreach ($columns as $name => $definition) { $connection->addColumn($tableName, $name, $definition); } } -
Add
fieldset.xmlwith following content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="customer_address">
<field name="company_info">
<aspect name="create" />
<aspect name="update" />
<aspect name="to_quote_address" />
</field>
<field name="telephone_secondary">
<aspect name="create" />
<aspect name="update" />
<aspect name="to_quote_address" />
</field>
</fieldset>
<fieldset id="sales_convert_order_address">
<field name="company_info">
<aspect name="to_quote_address" />
</field>
<field name="telephone_secondary">
<aspect name="to_quote_address" />
</field>
</fieldset>
<fieldset id="sales_convert_quote_address">
<field name="company_info">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="telephone_secondary">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
</fieldset>
<fieldset id="sales_copy_order_billing_address">
<field name="company_info">
<aspect name="to_order" />
</field>
<field name="telephone_secondary">
<aspect name="to_order" />
</field>
</fieldset>
<fieldset id="order_address">
<field name="company_info">
<aspect name="to_customer_address" />
</field>
<field name="telephone_secondary">
<aspect name="to_customer_address" />
</field>
</fieldset>
</scope>
</config>
- Go to checkout
- Insert data for new address (custom attributes are visible - that is correct)
- Go to billing step
Expected result
- Custom attributes values should be saved into database
Actual result
- Attributes values are not saved
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (11 by maintainers)
Commits related to this issue
- Merge pull request #6575 from magento-engcom/2.4-develop-prs [Magento Community Engineering] Community Contributions - 2.4-develop — committed to magento/magento2 by melnikovi 3 years ago
I retract myself, in EE 2.14 the customers address attributes created in the backend are saved to the database when a address is created in the checkout.
Following the admin save controller used I create this install script for the attribute:
This create the attribute en the eav_attribute table, and add a column in this tables: magento_customercustomattributes_sales_flat_quote_address magento_customercustomattributes_sales_flat_order_address
And probably do other stuff. With this script I did not need to modify any js file
Can this work on the CE ?
@Bartlomiejsz I think my problem is in the InstallData.php. I use this method which is a bit different from your. I post here my code
In my there isn’t the code
@EspertoMagento sorry for not answering for so long. Exactly, I have used extension_attributes. I did it some time ago, but as far as I remember, what I did was:
js/action/place-order.js- only changed section of file:js/action/select-billing-address.jsjs/action/set-billing-address.jsjs/model/new-customer-address.jsjs/model/shipping-save-processor/default.jsjs/model/address-list.jsjs/model/customer-addresses.jsjs/model/customer/address.jsetc/events.xmlObserver/SaveAdditionalFields.php