0

I need to show only pending order by users I follow this link

They used sales_order_grid_collection_load_before in magento 1, what exact event in magento 2

and

How to Collect only pending Orders from Order collection and Show for specific users.

0

Yes, I achieved this Solution via Plugin.

di.xml:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
      <plugin name="sales_order_pending" type="Vendor\Module\Plugin\CustomSalesOrderGridCollection" sortOrder="100" />
</type>

CustomSalesOrderGridCollection.php

          <?php namespace Vendor\Module\Plugin;

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

    class CustomSalesOrderGridCollection
    {
        private $messageManager;
        private $collection;
        protected  $adminSession;
        protected $logger;

        public function __construct(MessageManager $messageManager,
            SalesOrderGridCollection $collection,
            \Magento\Backend\Model\Auth\Session $adminSession,
            \Psr\Log\LoggerInterface $logger
        ) {

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

        public function aroundGetReport(
            \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject,
            \Closure $proceed,
            $requestName
        ) {
           $current_adminuser =   $this->adminSession->getUser()->getAclRole();
           $this->logger->addDebug("admin user");
           $this->logger->addDebug($current_adminuser);

           if(12 == $current_adminuser){

             $result = $proceed($requestName);
             if ($requestName == 'sales_order_grid_data_source') {
                 if ($result instanceof $this->collection) {

                     $this->collection->addFieldToFilter('status', array('in' => array('pending')));
                 }

             }
           }
            return $this->collection;
        }
    }

After Clear Cache and Login that user, then its will show only pending Order in sale_order_grid.

| improve this answer | |
  • It's working well, but in content->pages grid page page_id column_id not found error showing, when i disable the plugin the content->pages loading without any error – senthil Jun 21 '18 at 12:54
  • Getting error in customer grid, cms page and all module. because it will run in all collection grid. – David Coder Apr 30 at 11:01
0

I was facing same issue and finally I resolved the issue by following code. You can use following code with your customisation.

First you need to create a plugin.

di.xml

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
      <plugin name="sales_order_grid_collection" type="VENDOR\MODULE\Plugin\CustomSalesOrderGridCollection" sortOrder="100" />
     </type>

Create plugin file in VENDOR/MODULE/plugin/CustomSalesOrderGridCollection.php

CustomSalesOrderGridCollection.php

<?php namespace VENDOR\MODULE\Plugin;

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

class CustomSalesOrderGridCollection
{
    private $messageManager;
    private $collection;
    protected  $adminSession;

    public function __construct(MessageManager $messageManager,
        SalesOrderGridCollection $collection,
        \Magento\Backend\Model\Auth\Session $adminSession
    ) {

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

    public function aroundGetReport(
        \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject,
        \Closure $proceed,
        $requestName
    ) {
        $result = $proceed($requestName);
        if ($requestName == 'sales_order_grid_data_source') {
             $current_adminuser =   $this->adminSession->getUser()->getAclRole();
             if(12 == $current_adminuser){
                  if ($result instanceof $this->collection) {
                      $this->collection->addFieldToFilter('status', array('in' => array('pending')));
                  }
              }
             return $this->collection;
        }
        return $result;

    }
}
| improve this answer | |

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.