1

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

0
4

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:

2
  • i am using same way but not working for me ! <fieldset id="sales_convert_quote"> <field name="custom_attribute"> <aspect name="to_order" /> </field> </fieldset> – Manish Maheshwari Oct 3 '18 at 11:38
  • I want copy data 'quote_item' table filed 'test' to 'sales_order_item' field 'test' so how is it possible ? – Pratik Mehta Oct 6 '18 at 6:23
5

On 2.1.3 at least, doing it through fieldset.xml does not work.

I had to use the event sales_model_service_quote_submit_before , which is fired in function submitQuote of Magento\Quote\Model\QuoteManagement

$order->setCustomerLastname($quote->getCustomerLastname());

$this->eventManager->dispatch(
                'sales_model_service_quote_submit_before',
                [
                    'order' => $order,
                    'quote' => $quote
                ]
            );

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.