0

I've added a custom shipping and billing address input field on checkout via layoutProcessor. The field shows up fine but when I submit the order the value of the custom attribute is not saved as the actual field value but rather as a attribute_code⏎value which is wrong.

I'm saving the custom attribute in quote_address, sales_order_address and customer_address_entity tabels.

extension_attributes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Customer\Api\Data\AddressInterface">
        <attribute code="custom_foo" type="string"/>
    </extension_attributes>
    <extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
        <attribute code="custom_foo" type="string"/>
    </extension_attributes>
    <extension_attributes for="Magento\Sales\Api\Data\OrderAddressInterface">
        <attribute code="custom_foo" type="string"/>
    </extension_attributes>
    <extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
        <attribute code="custom_foo" type="string"/>
    </extension_attributes>
</config>

fieldset.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
    <scope id="global">
        <fieldset id="sales_convert_order_address">
            <field name="custom_foo">
                <aspect name="to_quote_address"/>
            </field>
        </fieldset>
        <fieldset id="sales_convert_quote_address">
            <field name="custom_foo">
                <aspect name="to_customer_address"/>
                <aspect name="to_order_address"/>
            </field>
        </fieldset>
        <fieldset id="sales_copy_order_billing_address">
            <field name="custom_foo">
                <aspect name="to_order"/>
            </field>
        </fieldset>
        <fieldset id="order_address">
            <field name="custom_foo">
                <aspect name="to_customer_address"/>
            </field>
        </fieldset>
    </scope>
</config>

LayoutProcessor.php (an example for shippingAddress field config)

$customFooConfig = array(
    'config'            => [
        'customScope' => 'shippingAddress.custom_attributes',
        'customEntry' => null,
        'template'    => 'ui/form/field',
        'elementTmpl' => 'ui/form/element/input',
        'id'          => 'custom-foo',
    ],
    'label'             => 'Custom Foo',
    'value'             => '',
    'dataScope'         => 'shippingAddress.custom_attributes.custom-foo',
    'provider'          => 'checkoutProvider',
    'id'                => 'custom-foo',
    'sortOrder'         => 1,
    'customEntry'       => null,
    'visible'           => true,
    'validation'        => [
        'required-entry' => true,
    ],
);

db_schema.xml

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="customer_address_entity">
        <column xsi:type="varchar" name="custom_foo" nullable="true" length="255" comment="Custom Foo"/>
    <table name="quote_address">
        <column xsi:type="varchar" name="custom_foo" nullable="true" length="255" comment="Custom Foo"/>
    </table>
    <table name="sales_order_address">
        <column xsi:type="varchar" name="custom_foo" nullable="true" length="255" comment="Custom Foo"/>
    </table>
</schema>

I have followed Magento 2 Guide - Adding New Checkout Filed step by step and the field is posting custom and extension attributes correctly. I've also created a new customer address attribute for editing the custom_foo attribute on customer account/addresses page which is working fine.

The only issue is that on order submit the custom_foo value is being saved as a key/par value which is the structure of customAttributes property. Am I missing something in the xml configuration(s) or should I parse the custom or extension attributes on quote/order submit and set the to address each time?

2
  • please check in all 3 tables. check first value in quote table or not? Jul 23, 2021 at 7:26
  • The attribute is saved in all 3 tables. But it is saved as custom_foo⏎someValuePassedFromCheckoutField.
    – s21x
    Jul 23, 2021 at 7:27

1 Answer 1

1

Issue was resolved with Magento 2.4.3-p1. What caused it is still unknown but it works as expected with the newer version of Magento.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.