문제

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

도움이 되었습니까?

해결책

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:

다른 팁

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
                ]
            );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top