2

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

http://127.0.0.1/website/admin/sales/order/index/key/b42c90e9ca2c5bb07e616df1140b07770910383e85e83f878d7f37b65e548b41/?vendorname=CFM

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

1

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

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

<?php
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. – bhargav shastri Feb 21 at 8:56
  • can we talk in chat room if possible so we can share actual things. – bhargav shastri Feb 21 at 9:39
  • May I know which you used parameter in url is it admin username or different?? – Sagar Dobariya Feb 21 at 13:28
  • its depend on dropdown option value selected – bhargav shastri Feb 21 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. – Sagar Dobariya Feb 22 at 9:47
0

I have resolved this by using session

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.