I am trying to customise admin sale order grid collection. I have created an custom sale_order attribute store_manager. These store managers are admin users eg: 'manager1', 'manager2'.

1) Orders are manually assigned to 'manager1' or 'manager2' -- this part is done

2) Now I am trying to set filter on sale order grid collection, so when manager logged in to there system they can only see there orders.

In Magento 1 we have sales_order_grid_collection_load_before, sales_order_grid_collection_load_after for this requirement .

Is tried to such event for Magento 2 but didn't get any success.

My Queries :

Is there any such event like (sales_order_grid_collection_load_after) in magento 1 which full fill my requirement?

Is there any other way where I can set filter to sale order grid collection?

Note : I already search for this on google but didn't get any perfect solution.

  • Any Solution about filter Order grid collection by admin user id? – mahmoudismail Jul 2 '18 at 10:00

override with your module Mage_Sales by writing in module.xml smth like

<module name="----" setup_version="1.0.0">
        <module name="Magento_Sales"/>

Create in your module view/adminhtml/ui_component/sales_order_grid.xml

in sales_order_grid do smth like

<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="attribute_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">Attribute Name</item>
                <item name="sortOrder" xsi:type="string">3</item>


Create your custom module or already exit its not issue. In etc folder di.xml created plugin

        <type name="Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter">
                <plugin name="bindStoreManagerSearch" type="Namespace\Module_name\Plugin\Grid\Search\StoreManagerSearch" sortOrder="1" />

Create StoreManagerSearch.php file in plugin folder


            namespace Namespace\Module_name\Plugin\Grid\Search;

            class StoreManagerSearch {

                public function aroundApply(
                    \Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter $subject, 
                    callable $proceed, 
                    \Magento\Framework\Data\Collection $collection, 
                    \Magento\Framework\Api\Filter $filter
                    $result = $proceed($collection, $filter);

                    if($collection->getConnection()->tableColumnExists($collection->getMainTable(), 'store_manager')) {

                        $collection->getSelect()->orWhere('`main_table`.store_manager = ?', $filter->getValue()); 

                        $parentTable = null;

                        if($collection->getMainTable() == 'sales_order_grid') {

                            $parentTable = 'sales_order';

                        } else if($collection->getMainTable() == 'sales_invoice_grid') {

                            $parentTable = 'sales_invoice';

                        } else if($collection->getMainTable() == 'sales_shipment_grid') {

                            $parentTable = 'sales_shipment';

                        } else if($collection->getMainTable() == 'sales_creditmemo_grid') {

                            $parentTable = 'sales_creditmemo';
                        } else {

                            $parentTable = 'sales_order';

                        if($parentTable && $collection->getConnection()->tableColumnExists($parentTable, 'store_manager')) {

                                ['sm' => $parentTable],
                                "sm.entity_id = main_table.entity_id",

                            $collection->getSelect()->orWhere('`sm`.store_manager = ?', $filter->getValue());  

                    return $result;

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.