Magento 2 – How to Copy Quote Fields to Order Fields

magento2quoteitemsales-order

In Magento2, i want to copy the quote custo fields into order custom fields, i.e.

say, i have created a manufacturer column in quote_item which needs to be copied into sales_order_item table, manufacturer column, during order placed.

In Magento1, it was possible through

Best Answer

To copy quote item fields to sale order item fields, we need to declare these fields in fieldset.xml

app/code/Vendor/Module/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">
        <!-- Copy quote to sale order fields -->
        <fieldset id="sales_convert_quote">
            <field name="custom_attribute">
                <aspect name="to_order" />
            </field>
        </fieldset>
        <!-- Copy quote item to sale order item fields-->
        <fieldset id="quote_convert_item">
            <field name="manufacturer">
                <aspect name="to_order_item" />
            </field>
        </fieldset>
    </scope>
</config>

[EDIT]

Seem that we need to use Observer sales_model_service_quote_submit_before to assign the new fields: