1

I created two new columns in quote_address and sales_order_address as shown below. When I first land on checkout, I manually (in the database using Sequel Pro) added '999' into the quote_address custom column 'custom_module_table_id' and then proceeded to checkout successfully.

Unfortunately, the data '999' wasn't automatically copied over into my new column in sales_order_address. Am I missing something? Do I need to make Magento aware that there's more data for it to copy across, or should the above have worked?

        $installer->getConnection()->addColumn(
        $installer->getTable('quote_address'),
        'custom_module_table_id',
        [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            'unsigned' => true,
            'nullable' => true,
            'default' => null,
            'comment' => 'Custom Table Id'
        ]
    );

    $installer->getConnection()->addColumn(
        $installer->getTable('sales_order_address'),
        'custom_module_table_id',
        [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            'unsigned' => true,
            'nullable' => true,
            'default' => null,
            'comment' => 'Custom Table Id'
        ]
    );
3
  • Have you do any code to copy data from quote_address to sales_order_address? Commented Nov 16, 2017 at 11:20
  • No other code, I presumed Magento automatically copied over the contents of quote_address to sales_order_address?
    – MikeMason
    Commented Nov 16, 2017 at 11:32
  • I post answer, you need to do that things. Commented Nov 16, 2017 at 12:45

2 Answers 2

1

You need to copy manually in plugin on \Magento\Quote\Model\Quote\Address\ToOrderAddress::convert.

For examples, see Magento plugins (EE only unfortunately):

  • \Magento\GiftRegistry\Model\Plugin\ConvertQuoteAddressToOrderAddress::afterConvert
  • \Magento\CustomerCustomAttributes\Model\Plugin\ConvertQuoteAddressToOrderAddress::afterConvert

Reason for this is populateWithArray:

$this->dataObjectHelper->populateWithArray(
    $orderAddress,
    array_merge($orderAddressData, $data),
    \Magento\Sales\Api\Data\OrderAddressInterface::class
);

that looses all data that is not in interface.

public function afterConvert(
    QuoteToOrderAddress $subject,
    OrderAddressInterface $result,
    QuoteAddress $quoteAddress,
    $data = []
) {
    if ($quoteAddress->getData('custom_module_table_id')) {
        $result->setData('custom_module_table_id', $quoteAddress->getData('custom_module_table_id'));
    }

    return $result;
}
0

You need to do code in your custom extension fieldset.xml.

app/code/Vendor/Extension/etc/fieldset.xml

<?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="sales_convert_quote_address">
       <field name="custom_module_table_id">
          <aspect name="to_order"/>
       </field>
      </fieldset>
      </scope>
</config>
2
  • If it help you then accept it, So it will help other in community as well. Commented Nov 16, 2017 at 13:37
  • Unfortunately, that didn't work. I looked online and found the below. Apparently, it no longer works to use the fieldset.xml? magento.stackexchange.com/questions/77016/…
    – MikeMason
    Commented Nov 16, 2017 at 13:47

Your Answer

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

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