How To

Magento 2: How to Observe the Multi-shipping Order Creation Event

Hello Magento Friends,

Magento 2 provides a robust event-driven architecture that allows developers to observe and respond to various system activities. One such event is the multi-shipping order creation event, triggered when a customer places an order using the multi-shipping checkout method. This method is ideal for stores with customers who ship items to multiple addresses in a single checkout process. By observing this event, you can implement custom actions or modifications to the order creation process.

In this guide, we’ll walk you through observing the multi-shipping order creation event in Magento 2.

Steps to Observe the Multi-shipping Order Creation Event in Magento 2:

Step 1: First, we need to create an “event.xml” file inside our extension at the following path:

app/code/Vendor/Extension/etc/event.xml

Now add code as follows

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_type_multishipping_create_orders_single">
        <observer name="multishipping_create_ordersdata" instance="Vendor\Extension\Observer\GetOrderData"/>
    </event>
</config>

Step 2: First, we need to create a “GetOrderData.php” file inside our extension at the following path.

app/code/Vendor/Extension/Observer/GetOrderData.php

Then add the code as below

<?php
namespace Vendor\Extension\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class GetOrderData implements ObserverInterface
{
    public function execute(Observer $observer)
    {

        $order = $observer->getOrder();
        
        $orderData = $order->getData();   

        return $this;
    }
}

Conclusion:

Observing the multi-shipping order creation event in Magento 2 provides a powerful way to add custom functionality to your store’s multi-shipping checkout process. By leveraging Magento’s event-driven architecture, you can enhance the customer experience and improve your store’s operational workflows seamlessly.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

16 hours ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

1 day ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

3 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

6 days ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

6 days ago

Best Beginners Guide to Shopify Balance Account

If you are a Shopify admin, using a Shopify Balance Account for your business revenue…

6 days ago