I want to filter Sales Order query based on request parameter passed in querystring like following:

so when there is vendorname=CFM in request parameter i want to filter order grid query with vendorname in where clause, for this i have done all necessary code, but request parameter not working with filter so i am not getting proper results, can anyone help me i am stuck from 2 days for this task but didn't find any solution. please find attached screenshots for reference what i have done so far. di.xml Model

2 Answers 2


create di.xml file in app/code/Vendor/Module/etc/adminhtml/di.xml and add below code

<?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\Reporting">
        <plugin name="sales_grid_collection" type="Vendor\Module\Model\Plugin\Sales\Order\Grid"/>

create Grid.php file in app/code/Vendor/Module/Model/Plugin/Sales/Order/Grid.php and add below code

namespace Vendor\Module\Model\Plugin\Sales\Order;

class Grid {

    public static $table = 'sales_order_grid';

    protected $orderCollectionFactory;

    public function __construct(

        \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
    ) {

        $this->orderCollectionFactory = $orderCollectionFactory;


    public function afterSearch($intercepter, $collection) {
        //first you must check same function call or not with exit;
        //echo "call function";exit;

        if ($collection->getMainTable() === $collection->getConnection()->getTableName(self::$table)) {

            $collection->addFieldToFilter('vendorname', array('eq' => 'CFM'));
        return $collection;


  • i have tried this way also but in both the methods vendorname getting reset that is coming dynamically from url parameter, its not static text, actually if i put static as CFM than its working but if i fetch value from request parameter its not working. Feb 21, 2019 at 8:56
  • can we talk in chat room if possible so we can share actual things. Feb 21, 2019 at 9:39
  • May I know which you used parameter in url is it admin username or different?? Feb 21, 2019 at 13:28
  • its depend on dropdown option value selected Feb 21, 2019 at 14:31
  • @bhargavshastri I have checked your concern in detail it's seems two time call afterSearch function so first time system will get value which you passed in url then call second time same function which not get your parameter value. you can check using log so you will get clear idea about that.now you can use cookie or session for save value. Feb 22, 2019 at 9:47

I have resolved this by using session

Your Answer

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

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