Magento order split through observer

Magento order split through observer

October 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento order split through observer

Splitting Magento Orders via Observer: A Comprehensive Guide

Dear developer,

You’re on the right track! Splitting an order during onepage checkout using an observer is indeed possible in Magento. I’ve encountered this requirement many times while working with clients and have developed a robust solution. Let me guide you through the process step-by-step.

Understanding the Magento Event System

Magento has a powerful event system that allows us to intercept and modify certain actions, including order placement. The key event for your use case is sales_order_place_before. This event fires right before an order is placed, giving us the perfect opportunity to split it.

Setting Up the Observer

First, ensure you have created an observer under etc/events.xml. Your configuration should look something like this:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  <event name="sales_order_place_before">
    <observer name="split_orders" instance="[Vendor]\[Module]\Observer\SplitOrders" />
  </event>
</config>

Replace [Vendor] and [Module] with your actual vendor and module names. This observer will be triggered whenever the sales_order_place_before event is fired.

Implementing the Observer

Now, let’s implement the SplitOrders class in your Observer directory:

namespace [Vendor]\[Module]\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Quote\Address\RateRequest;
use Magento\Sales\Model\Service\Quote\PaymentApprover;
use Magento\Sales\Model\Service\Quote\SubmitFailureException;
use Magento\Sales\Model\OrderFactory;

class SplitOrders implements ObserverInterface
{
    protected $orderFactory;

    public function __construct(OrderFactory $orderFactory)
    {
        $this->orderFactory = $orderFactory;
    }

    public function execute(EventObserver $observer)
    {
        // Your order splitting logic goes here

        return $this;
    }
}

Splitting the Order Logic

In the execute method, you can now implement your order splitting logic. Here’s a high-level overview of what needs to be done:

  1. Get the current quote from the observer.
  2. Loop through the items in the quote and split them based on your criteria (e.g., product type, quantity).
  3. For each subset of items:
    • Create a new quote with relevant customer information.
    • Add the subset of products to this new quote.
    • Set shipping and payment methods for this new quote.
    • Collect totals and save the quote.
  4. Submit each new quote as an order.

Remember, you’ll need to handle shipping rates, taxes, discounts, and other Magento-specific calculations correctly during this process.

Handling Multiple Orders

To ensure a smooth user experience, it’s crucial to handle multiple orders gracefully. You can use the following techniques:

  1. Redirect: After successfully splitting and submitting all orders, redirect the customer to a custom “Thank You” page that displays a summary of their orders instead of showing them only one order confirmation.

  2. Email Confirmations: Make sure each order receives its own confirmation email, containing relevant information about the split items and their respective order IDs.

Conclusion

Splitting Magento orders through an observer requires careful implementation to ensure data consistency and correct processing. By following this guide, you should have a solid foundation for handling this complex task in your projects.

Remember to test thoroughly, especially around edge cases like empty quotes or invalid products, to avoid any unexpected behavior.

For more advanced techniques like async order splitting or custom payment methods integration, I recommend exploring the Magento 2 API documentation and considering a headless approach for increased flexibility.

Happy coding! If you have any other questions or need further assistance, feel free to reach out.

Best, [Your Name] Senior Developer at Laravel Company

Checkout Extensions Configuration Orders

Our network