1

While i am using same code for filter it's working but i have break other grid like customer,invoice,cms page and get error "Not registered handle cms_page_listing_data_source"

While i have moved di.xml file in etc/ folder grid filter not working. any have idea about.

I have created di.xml file in etc/adminhtml/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\Module\Model\ResourceModel\Order\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

FIlter collection in

<?php
namespace Vendor\Module\Model\ResourceModel\Order\Grid;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;


class Collection extends OriginalCollection {
    protected $_authSession;
    public function __construct(
        EntityFactory $entityFactory,

        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        \Magento\Backend\Model\Auth\Session $authSession
    ) {
        $this->_authSession = $authSession;
        parent::__construct($entityFactory, $fetchStrategy, $eventManager);
    }

    protected function _renderFiltersBefore() {
        $user = $this->_authSession->getUser();
        $joinTable = $this->getTable('sales_order');
        $this->getSelect()->where('stockist_id = ' . $user->getId());
        parent::_renderFiltersBefore();
    }
}
  • Hi Sagar, Not registered handle cms_page_listing_data_source Can you send me code of CMS grid – Sourav Jan 4 at 1:28
0

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" />
        </type>

Create StoreManagerSearch.php file in plugin folder

        <?php

            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`.stockist_id = ?', "your_custom_id"); 

                        $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')) {

                            $collection->getSelect()->join(
                                ['sm' => $parentTable],
                                "sm.entity_id = main_table.entity_id",
                                []
                            ); 

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

                    return $result;
                }
            }
  • i have tried your solution but StoreManagerSearch.php file not called. – Sagar Dobariya Dec 24 '18 at 10:34

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.