TransWikia.com

How to recognize order before saving in the backend ? - Magento 2

Magento Asked by Marceli Po on December 30, 2021

I would like to post some data in admin order create form and check if it exists and is set if not throw an exception.

I was thinking about adminhtml_sales_order_create_process_data event, but it is called several times. I think it would be nice to have some sort of event before the admin order is saved and check if this data exists.

One Answer

Create a plugin for Sales/Model/Order by putting smth like this in your module, in di.xml

<type name="MagentoSalesModelOrder">
    <plugin name="YOUR NAME" type="Your-ModuleSalesPluginSalesModelOrder" sortOrder="10" disabled="false"/>
</type>

Then, in Order.php create

public function beforeSave(MagentoSalesModelOrder $subject)
{
$subject->getData() 
// this is your order Data before saving it
}

Answered by Andrei Dinu on December 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP