【问题标题】:How to display shipping country in sales order grid in magento 2如何在magento 2的销售订单网格中显示发货国家
【发布时间】:2018-12-18 08:36:17
【问题描述】:

我尝试在管理销售订单网格中显示发货国家/地区,但没有任何效果。

我确实检查了两次客户地址配置,在那里我可以看到国家变量存在并且应该显示。但在网格中您看不到发货国家/地区。

有什么解决方法吗?

【问题讨论】:

    标签: magento2


    【解决方案1】:

    我找到了解决方案。创建模块并重写类。

    app/code/Vendor/ExtendedAdminGrid/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">
            <arguments>
                <argument name="collections" xsi:type="array">
                    <item name="sales_order_grid_data_source" xsi:type="string">Vendor\ExtendedAdminGrid\Model\ResourceModel\Order\Grid\Collection</item>
                </argument>
            </arguments>
        </type>
    </config>
    

    app/code/Vendor/ExtendedAdminGrid/etc/module.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Vendor_ExtendedAdminGrid" setup_version="2.0.0">
            <sequence>
                <module name="Magento_Sales"/>
                <module name="Magento_Backend"/>
            </sequence>
        </module>
    </config>
    

    app/code/Vendor/ExtendedAdminGrid/Model/ResourceModel/Order/Grid/Collection.php

    <?php
    namespace Vendor\ExtendedAdminGrid\Model\ResourceModel\Order\Grid;
    
    class Collection extends \Magento\Sales\Model\ResourceModel\Order\Grid\Collection
    {
        protected function _renderFiltersBefore()
        {
            $this->getSelect()->joinLeft(
                ["soa" => "sales_order_address"],
                "main_table.entity_id = soa.parent_id and soa.address_type = 'shipping'",
                array('country_id')
            )
            ->distinct();
    
            parent::_renderFiltersBefore();
        }
        protected function _initSelect()
        {
    
            $this->addFilterToMap('created_at', 'main_table.created_at');
            $this->addFilterToMap('base_grand_total', 'main_table.base_grand_total');
            $this->addFilterToMap('grand_total', 'main_table.grand_total');
            $this->addFilterToMap('store_id', 'main_table.store_id');
            $this->addFilterToMap('store_name', 'main_table.store_name');
            $this->addFilterToMap('order_id', 'main_table.order_id');
            $this->addFilterToMap('order_increment_id', 'main_table.order_increment_id');
            $this->addFilterToMap('billing_name', 'main_table.billing_name');
            $this->addFilterToMap('billing_name', 'main_table.shipping_name');
            $this->addFilterToMap('status', 'main_table.status');
    
            parent::_initSelect();
        }
    }
    

    app/code/Vendor/ExtendedAdminGrid/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">
            <column name="country_id">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="filter" xsi:type="string">text</item>
                        <item name="label" xsi:type="string" translate="true">Shipping Country ID</item>
                    </item>
                </argument>
            </column>
        </columns>
    </listing>
    

    app/code/Vendor/ExtendedAdminGrid/registration.php

    <?php
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Vendor_ExtendedAdminGrid',
        __DIR__
    );
    

    感谢 Sergey 的精彩博文Modifying the default magento2 sales order grid — adding a coupon code column

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-08
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多