I have an extension attribute on quote address called "subdistrict". The data is successfuly saved to quote_address. But when completing the order, these data are not saved to sales_order_address.

below is my 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_quote_address">
        <field name="subdistrict">
            <aspect name="to_order_address" />

and my extensions_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\Quote\Api\Data\AddressInterface">
    <attribute code="subdistrict" type="string" />
<extension_attributes for="Magento\Sales\Api\Data\OrderAddressInterface">
    <attribute code="subdistrict" type="string" />

right now i am getting an error:

"Error occurred during "shipping_address" processing. Error occurred during "extension_attributes" processing. Error occurred during "subdistrict" processing. Invalid type for value: "array". Expected Type: "string"."

and here is some part of the quote content:

  string(14) "Kab. Tangerang"
  string(7) "Yohanes"
  string(7) "Pradono"
  array(1) {
    array(2) {
      string(11) "subdistrict"
      string(8) "Balaraja"
  array(1) {
    array(2) {
      string(11) "subdistrict"
      string(8) "Balaraja"

and my mixin.js

], function ($, wrapper, quote) {
    'use strict';

    return function (setShippingInformationAction) {

        return wrapper.wrap(setShippingInformationAction, function (originalAction) {
            var shippingAddress = quote.shippingAddress();
            if (shippingAddress['extension_attributes'] === undefined) {
                shippingAddress['extension_attributes'] = {};

            // you can extract value of extension attribute from any place (in this example I use custom_attributes approach)
            // Don: the actual data to be sent to Magento backend is inside 'extension_attributes'
            shippingAddress['extension_attributes']['subdistrict'] = shippingAddress.customAttributes['subdistrict'];
            // pass execution to original action ('Magento_Checkout/js/action/set-shipping-information')
            return originalAction();

I finally be able to convert the subdistrict to order address. Aparantly, some tutorials out there put wrong information on the mixin js content. it should be likethis

    if (shippingAddress.customAttributes != undefined) {
        $.each(shippingAddress.customAttributes , function( key, value ) {

                value = value['value'];

            shippingAddress['customAttributes'][key] = value;
            shippingAddress['extension_attributes'][key] = value;


And I also have to manually convert quote address subdistrict to order address using Observer on event sales_model_service_quote_submit_before

    public function execute(\Magento\Framework\Event\Observer $observer)
    // copy shipping address subdistrict
    $quoteShippingAdress = $observer->getQuote()->getShippingAddress();
    $subdistrict = $quoteShippingAdress->getSubdistrict();
    $orderShippingAdress = $observer->getOrder()->getShippingAddress();

    // copy billing address subdistrict
    $quoteBillingAddress = $observer->getQuote()->getBillingAddress();
    $subdistrict = $quoteBillingAddress->getSubdistrict();
    $orderBillingAddress = $observer->getOrder()->getBillingAddress();


as additional info, Magento 2.1 fieldset.xml doesn't support extension_attributes fields so they have to be converted manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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