4

I added a new field "management_fee" on table "quote" properly. I add this field on "sales_order" field too. I would like to update this field on sales_order table while quote is converting to order.

I know how to do with quote items using plugin and Magento\Quote\Model\Quote\Item\ToOrderItem class, but I did not find a class for quote to order.

2 Answers 2

7

add the fields to both table quote and sales_order via a setup script in your module.

Then add an event in your module (see below)

 <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="sales_model_service_quote_submit_before">
            <observer name="quote_submit_before" instance="Vendor\Module\Observer\QuoteSubmitBefore" />
        </event>
    </config>

Finally save the quote data against your order

class QuoteSubmitBefore implements ObserverInterface
{

    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
       $quote = $observer->getQuote();
       $order = $observer->getOrder();

       $order->setData('field_custom', $quote->getData('field_custom'));      
    }
}
1
  • 1
    Still the only working way to do this even with 2.4 :/ Commented Oct 22, 2020 at 18:59
2

I am not really aware of this thing but you can give a try I hope it'll work for you. Create a fieldset.xml in your module's etc folder.

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">
            <field name="management_fee">
              <aspect name="to_order" />
           </field>
        </fieldset>
    </scope>
</config> 

You should check below link as well https://devdocs.magento.com/guides/v2.2/ext-best-practices/tutorials/copy-fieldsets.html

4
  • 1
    It does not work.
    – th0r1eif
    Commented Nov 12, 2018 at 8:59
  • have you tried it with the link? Commented Nov 12, 2018 at 9:12
  • have you tried it with the link Commented Nov 12, 2018 at 9:12
  • IT DOES NOT WORK Commented Oct 22, 2020 at 18:58

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.