How To

How to Add Shipping Address Details in Order Grid in Magento 2

Hello Magento Friends,

Today’s Magento 2 Tutorial is on How to Add Shipping Address Details in Order Grid in Magento 2.

Admin Order Grid in Magento 2 helps store admin to view order details, manage orders and create new orders. With Magento 2, the admin is able to customize the order grid according to the requirements. Sometimes, the admin needs shipping address details like street, city, Pincode, phone column in the order grid. Go ahead with the article to fulfill these requirements. Also checkout Magento Development Services to customize your requirement.

Here are the steps for How to Add Shipping Address Details in Order Grid in Magento 2

Steps to Add Shipping Address Details in Order Grid in Magento 2:

Step 1: First, we need to create a sales_order_grid.xml file inside our extension at the following path

app\code\Vendor\Extension\view\adminhtml\ui_component\

And add the code as mentioned below

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="sales_order_columns">
        <settings>
            <childDefaults>
                <param name="fieldAction" xsi:type="array">
                    <item name="provider" xsi:type="string">false</item>
                </param>
            </childDefaults>
        </settings>
        <column name="street">
            <settings>
                <filter>text</filter>
                <label translate="true">Street</label>
                <bodyTmpl>ui/grid/cells/html</bodyTmpl>
                <visible>true</visible>
            </settings>
        </column>
        <column name="postcode">
            <settings>
                <filter>text</filter>
                <label translate="true">Zip</label>
                <bodyTmpl>ui/grid/cells/html</bodyTmpl>
                <visible>true</visible>
            </settings>
        </column>
        <column name="city">
            <settings>
                <filter>text</filter>
                <label translate="true">City</label>
                <bodyTmpl>ui/grid/cells/html</bodyTmpl>
                <visible>true</visible>
            </settings>
        </column>
        <column name="telephone">
            <settings>
                <filter>text</filter>
                <label translate="true">Phone</label>
                <bodyTmpl>ui/grid/cells/html</bodyTmpl>
                <visible>true</visible>
            </settings>
        </column>
    </columns>
</listing>

Step 2: After that, we need to create a di.xml file inside the extension folder at the below-given path:

app\code\Vendor\Extension\etc\

Now, add the below code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <plugin name="custom_orders_grid" type="Vendor\Extension\Plugin\OrdersGrid" sortOrder="10"/>
    </type>
</config>

Step 3: After that, we need to create the OrdersGrid.php file inside the below path folder to add the file to the module.

 app\code\Vendor\Extension\Plugin\

Now, add the below code

<?php
namespace Vendor\Extension\Plugin;

class OrdersGrid
{
    public function afterGetReport($subject, $collection, $requestName)
    {
        if ($requestName !== 'sales_order_grid_data_source')
        {
            return $collection;
        }

        if ($collection->getMainTable() === $collection->getResource()->getTable('sales_order_grid'))
        {
            $orderAddressTable  = $collection->getResource()->getTable('sales_order_address');

            $collection->getSelect()->joinLeft(
                ['oat' => $orderAddressTable],
                'oat.parent_id = main_table.entity_id AND oat.address_type = \'shipping\'',
                ['telephone', 'city', 'postcode', 'street']
            );
        }

        return $collection;
    }
}

That’s it!

Once you have completed the above steps, check the results in the Magento 2 store backend. Shipping Address detail columns like Street, Zip code, City, Phone has been added in the order grid of Magento 2.

Conclusion:

Hence, this way you can Add Shipping Address Details in Order Grid in Magento 2. If you face any issues, mention them in the comment box. I will be quick to solve it. Do share the articles with your fellow Magento developers. Stay in touch with us for more tutorials.

Happy Coding!

Click to rate this post!
[Total: 8 Average: 4.5]
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.🏏

View Comments

  • what are the changes in JOIN if I want to add both billing and shipping telephone show in the sales order grid?

Recent Posts

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

2 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

2 days ago

Magento 2: How to Add Header and Footer in Checkout

Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…

3 days ago

Understanding Flexbox Layout in React Native

Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…

5 days ago

HYVÄ Themes Releases: 1.3.6 & 1.3.7 – What’s New

We have brought exciting news for Magento store owners. Hyvä Themes recently released 1.3.6 and…

5 days ago

How Modern E-Commerce Platforms Leverage Docker & Kubernetes for Scalability

Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…

6 days ago