Magento - Saving data in to order during adminhtml_sales_order_create_process_data event

Magento - Saving data in to order during adminhtml_sales_order_create_process_data event

August 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Saving data in to order during adminhtml_sales_order_create_process_data event

Magento: Saving Data to an Order During adminhtml_sales_order_create_process_data Event

In Magento, saving data directly into an order during the “adminhtml_sales_order_create_process_data” event can be challenging due to the timing of the event relative to the actual order creation. This post will guide you through a step-by-step approach to accomplishing this task.

Understanding the adminhtml_sales_order_create_process_data Event

The adminhtml_sales_order_create_process_data event is triggered before an order is saved in the admin panel. At this point, Magento doesn’t have a stable order_id, and you won’t be able to access it directly. This is why you’re facing difficulty in saving data against the order.

Step 1: Capture the Custom Field Data

You’ve already set up your observer correctly to capture the custom field from the admin create order form:

$orderRequest = $data->getEvent()->getRequest('order');
$customField = $orderRequest['customfield'];

Saving Data Before Order Creation

Since you can’t save data directly against the order at this point, your best approach is to store the data temporarily and then link it once the actual order is created.

Step 2: Create a Temporary Storage Table

Create a new table in your database with fields for custom_field_value, order_id, and any other necessary details. You can use Magento’s core storage engine or create your own custom setup.

CREATE TABLE temporary_order_data (
    id INT PRIMARY KEY AUTO_INCREMENT,
    order_id INT,
    custom_field_value VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step 3: Save Data to the Temporary Table

In your observer, save the $customField value into this temporary table.

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "INSERT INTO temporary_order_data (order_id, custom_field_value) VALUES ('0', '$customField')";
$write->query($sql);

Note that you’re using 0 as the order ID for now, which is a placeholder since the actual order hasn’t been created yet.

Linking Data to the Order Upon Creation

Step 4: Create an Observer for Sales Model Service Quote Save After Event

Create another observer for the “sales_model_service_quote_save_after” event. This event triggers after a quote (which will become an order) is saved, but before it’s converted into an actual order.

<events>
    <sales_model_service_quote_save_after>
        <observers>
            <your_module_observer>
                <type>singleton</type>
                <class>Your_Module_Model_Observer</class>
                <method>saveCustomFieldToOrder</method>
            </your_module_observer>
        </observers>
    </sales_model_service_quote_save_after>
</events>

Step 5: Update the Temporary Data with the Real Order ID

In your saveCustomFieldToOrder method, retrieve the last inserted row from the temporary table:

$write = Mage::getSingleton('core/resource')->getConnection('core_write');

// Get the last inserted id
$sql = "SELECT LAST_INSERT_ID()";
$id = $write->fetchOne($sql);

// Retrieve the row with that ID
$sql = "SELECT * FROM temporary_order_data WHERE id = '$id'";
$row = $write->fetchRow($sql);

Now, you have access to the order_id field from the quote object:

$quoteId = Mage::getSingleton('sales/quote')->getId();

Update your temporary data with this real order ID:

$sql = "UPDATE temporary_order_data SET order_id = '$quoteId' WHERE id = '$id'";
$write->query($sql);

Conclusion

By following these steps, you can successfully save custom field data during the adminhtml_sales_order_create_process_data event and link it to the actual order once it’s created. This approach ensures that your data is correctly associated with the order even though you couldn’t access the order_id directly in the initial observer.

Remember to clear the temporary table periodically to avoid accumulating useless data, especially if your site has a high volume of orders.

For more advanced implementation techniques and best practices in Magento 2 development, feel free to explore our guides at Laravel Company.

Database Extensions Admin Orders

Our network