How to use sales_model_service_quote_submit_before event Magento 2?

When you want to save data to the sales_order from the quote table or before place an order you want to save data to the sales order table you can achieve this via the event observer approach.

You can save custom field value to the Order table before the order placed. The given event will also useful to copy quote data to the sales order table.

Event Name: sales_model_service_quote_submit_before

You can find the definition for the event from the Quote Module.

I have just used this event for the customization of the Extra Custom fee to the Grand total.

The event will be useful like, Adding extra Custom_Fee to the order total and saves the custom_fee value to the Sales_order table once successfully order placed.

I hope you have created an entry for the custom_fee in the quote and sales_order total.

Define Events in the events.xml file,

Now Create an Observer file to Handle Logic once trigger an action for the event,

I haven’t added logic to save custom_fee value to the quote table that will be depend based on your requirements.

Before place an order, We are checking for the Get Quote Object using $quote and checking like the custom fee is set or not in the quote table.

If the Custom fee is available in the quote table, We can get it using, $quote->getCustomFee() and set it to the $order object.

Given code snippet automatically saved custom fee value to the custom_fee column the Order table.

You can use this event whenever you need to save data to the sales order table from the quote table.