Magento Save Order function where it is?

Magento Save Order function where it is?

July 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Save Order function where it is?

Magento Save Order Function: Where Is It?

If you’re new to Magento development, finding specific functions can be a challenge, especially when dealing with AJAX calls like the saveOrder action in the onepage checkout process.

Understanding the Onepage Checkout Process

The onepage checkout in Magento is designed to streamline the shopping cart and checkout experience for customers. It handles multiple steps—like shipping information, payment method selection, and order review—in a single page using AJAX calls.

The saveOrder Action

In your provided code snippet from /checkout/onepage/reviews/info.phtml, you’re seeing an initialization of a new JavaScript object called review. This object is used to handle the final order submission process.

The saveOrder URL is generated dynamically using Magento’s core sessions and form key management. The form key is a security feature that ensures only legitimate forms can be processed, preventing Cross-Site Request Forgeries (CSRF attacks).

The AJAX call is made to this saveOrder URL when the customer submits their order.

Finding the saveOrder Function

To locate the actual saveOrder function in your Magento installation, you’ll need to follow a breadcrumb trail through the core files and modules.

  1. The initial call is routed via the onepageController.php file located at /app/code/core/Mage/Checkout/controllers/OnepageController.php.

  2. In this controller, look for the saveOrderAction() method. This is where the order data is processed before being saved to the database.

  3. The order saving process involves several steps:

    • It first retrieves the quote (shopping cart) object.
    • Then it calls the prepareQuoteForSubmit method on the Mage_Sales_Model_Service_Quote object to finalize the order data and set the order status to ‘pending’.
    • The prepared quote is then converted into an order using the submitAll() method.
    • Finally, the customer’s session is updated with the new order ID.

Modifying the Redirect Behavior

If you want to modify the redirect behavior after a successful order submission—for example, to direct the customer to a payment gateway instead of the success page—you’ll need to extend the core functionality. Here are some best practices:

  1. Create a custom module following Magento’s extension development guidelines.

  2. Override the OnepageController.php file in your custom module using the app/etc/modules/YourCompany_YourModule.xml configuration file.

  3. In your overridden controller, you can modify the redirect logic after the order has been successfully submitted. You might want to use Magento’s customer redirection feature or a custom redirection method.

Remember that modifying core files directly is not recommended in Magento development. Always try to extend the functionality through modules and observers for better maintainability and upgrade compatibility.

Conclusion

In summary, the saveOrder function is part of the core Magento checkout process, handled by the OnepageController.php file. It’s a critical part of the order submission flow that ensures secure and correct data handling.

When extending this functionality, always follow best practices for Magento development to ensure your customization works correctly across different versions and updates.

For more detailed information on Magento extension development and module creation, feel free to explore our comprehensive guides at Laravel Company.

Happy coding!

Checkout Security Extensions Themes

Our network