0

There,

I used the method which joining table when adding new column to order grid. A new column is for company name and its information is from sales_order_address, not sales_order. I succeeded to bring company data but it is way too slow to load totally and filter function disappears (it appear again when i scroll down tho). Could you check my code,please?

CODE

app\code\Kbethos\CompanyColumn\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="sales_order_additional_columns" type="Kbethos\CompanyColumn\Plugins\AddColumnsSalesOrderGridCollection" sortOrder="20" disabled="false" />
</type>
</config>

app\code\Kbethos\CompanyColumn\Plugins\AddColumnsSalesOrderGridCollection.php

<?php namespace Kbethos\CompanyColumn\Plugins;

use Magento\Framework\Message\ManagerInterface as MessageManager;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as SalesOrderGridCollection;

class AddColumnsSalesOrderGridCollection
{
    private $messageManager;
    private $collection;

    public function __construct(MessageManager $messageManager,
        SalesOrderGridCollection $collection
    ) {

        $this->messageManager = $messageManager;
        $this->collection = $collection;
    }

    public function aroundGetReport(
        \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject,
        \Closure $proceed,
        $requestName
    ) {
        $result = $proceed($requestName);

        if ($requestName === "sales_order_grid_data_source") {
            $select = $result->getSelect();

            $select->join(
                ["soa" => "sales_order_address"],
                'main_table.entity_id = soa.parent_id AND soa.address_type="shipping"',
                array('company')
            )
                ->distinct();
        }

        return $result;
    }
}

app\code\Kbethos\CompanyColumn\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">

        <!-- sales_order_address company -->
        <column name="company">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Company</item>
                    <item name="sortOrder" xsi:type="number">200</item>
                    <item name="align" xsi:type="string">right</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <!--<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>-->
                </item>
            </argument>
        </column>
    </columns>
</listing>

ISSUES

My Problem is

  1. It spent a huge of times to bring company information totally because our order items counts 216,894 right away and it will be larger in the future. So my question is that there is another way to bring an information under the database table whose prefix is sales_,not sales_order table

  2. After adding my module, the filtering function disappear. i mean my module makes the layout crushed. How can i handle this problem? enter image description here enter image description here

1 Answer 1

0

Ad.2 You must add sequence field into module field in module.xml file.

<sequence>
        <module name="Magento_Sales" />
</sequence>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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