1

Where do I change the column shipping address format in the Sales => Order => Grid in Magento 2.4.2? I need to have the post code/zip code in front of the city. "Stan" and "99999" should swap position and be on a new line.

Also, I want to remove the order grid linking, we only want to use the "View" link.

Thank you very much,

Update! Image describing the sales grid row linking issue. Is it possible to remove the row linking in sales => orders in Magento 2, and only use the action "View" link instead? Update!

Image Grid Row Linking Issue

Grid Row Linking

Address Formatting Issue

Address formatting issue

Update #2 @Prince

Should i remove the following whole part ...

<settings>
<childDefaults>
<param name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">sales_order_grid.sales_order_grid.sales_order_columns.actions</item>
<item name="target" xsi:type="string">applyAction</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">view</item>
<item name="1" xsi:type="string">${ $.$data.rowIndex }</item>
</item>
</param>
</childDefaults>
</settings>

... and replace with:

<settings>
<childDefaults>
<param name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">false</item>
</param>
</childDefaults>
</settings>

... to remove sales order grid linking?

1
+100

As per your requirement you need to create four new columns for the city, street, zip, and phone.

1. So first of all create sales_order_grid.xml in your custom module

app/code/Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml

<?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>

2. Create plugin for order collection data provider

app/code/Vendor/Module/etc/di.xml

<?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="mageprince_custom_orders_grid" type="Vendor\Module\Plugin\OrdersGrid" sortOrder="10"/>
    </type>
</config>

app/code/Vendor/Module/Plugin/OrdersGrid.php

<?php

namespace Vendor\Module\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 now you can see these columns in order grid as below

enter image description here

EDIT:

I have removed datasource class and updated the answer because datasource class not working with filters.

12
  • Thank you for your input Prince! This is also a good and working solution.
    – Alldo
    Apr 29 at 6:40
  • 1
    @Alldo To remove the link to the order grid you need to false to the provider in fieldAction param. Check file app/code/Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml in my updated answer Apr 29 at 7:10
  • 1
    @Alldo Yes remove the whole <settings> and replace it with my answer's one. Apr 29 at 8:16
  • 1
    @Alldo This is a working solution and also tested by me. Please check other third-party modules which use the same sales_order_grid.xml and have fiedaction. If found then you need to remove it from there also. Apr 29 at 8:43
  • 1
    @Alldo Datasource class not working with filters. Check my answer on your new question for the solution about filter: magento.stackexchange.com/a/336544/35758 May 2 at 11:25
1

The screen you show us is reliant on an order observer. When the order is successfully placed,

the event below is triggered and this will record the shipping address value as it appears in your order grid.

<event name="sales_order_process_relation">
        <observer name="sales_grid_order_sync_insert" instance="SalesOrderIndexGridSyncInsert" />
    </event>

For this observer to use a different format, you may create a custom module and in etc folder create a di.xml with the following content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="ShippingAddressAggregatorPostCodeBeforeCity" type="Magento\Framework\DB\Sql\ConcatExpression">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="company" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">sales_shipping_address</item>
                    <item name="columnName" xsi:type="string">company</item>
                </item>
                <item name="street" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">sales_shipping_address</item>
                    <item name="columnName" xsi:type="string">street</item>
                </item>
                <item name="postcode" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">sales_shipping_address</item>
                    <item name="columnName" xsi:type="string">postcode</item>
                </item>
                <item name="city" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">sales_shipping_address</item>
                    <item name="columnName" xsi:type="string">city</item>
                </item>
                <item name="region" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">sales_shipping_address</item>
                    <item name="columnName" xsi:type="string">region</item>
                </item>
            </argument>
            <argument name="separator" xsi:type="string">, </argument>
        </arguments>
    </virtualType>
    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="shipping_address" xsi:type="object">ShippingAddressAggregatorPostCodeBeforeCity</item>
            </argument>
        </arguments>
    </virtualType>
</config>

finally, install the custom module. The orders that you will place after your new module is working will use the new format. The previous orders will remain with the previous format.

If you need the previous orders to be formatted correctly, it would be possible to use a command-line and apply a similar process

repository

9
  • Thank you for your solution, it works perfect! Great job! Do you also have a quick fix for removing the row linking in the sales orders grid, as asked in my post? Thanks again!
    – Alldo
    Apr 29 at 6:39
  • 1
    there is no hand on default Magento install, so my guess is your link is here because of a customisation that of course I can't advise unless I see the codebase. I can explain how to remove the view link, is it what you are after? I would not mind being a different question if I may Apr 29 at 8:27
  • Yes that's right, please see update number 2 in my post. We use Amasty Order Grid and Amasty Order Action, but the support staff at Amasty says that grid row linking is standard Magento behaviour, and not related to their extension. Beats me!
    – Alldo
    Apr 29 at 8:34
  • 1
    I admit I am at lost with the query now, best of luck. PLease do try @prince patel answer and if it helps you, that is a great outcome for you Apr 29 at 8:44
  • 1
    yes, it is possible indeed. But it will have to be another question @alido Apr 29 at 11:16
0

try https://docs.magento.com/user-guide/customers/address-templates.html

If doesn't help you need to do it trough custom code

1
  • No I'm sorry that doesn't do the trick.
    – Alldo
    Apr 27 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.