0

I am looking for solution for multiple sales order Grid as per order status. One grid will have all pending order and another grid for Processing orders.

Please have a look attached screenshot.

enter image description here

how is this possible?Please give me an idea for that.

4
  • Have you use any third party extension for Order related? Then try to disable and then check. Jan 11, 2020 at 7:04
  • @DhirenVasoya,search on forums but not found such type of extension.
    – akgola
    Jan 11, 2020 at 7:09
  • No I am asking currenlty if you use any third party extension related to any order related functionlity then try to disable and then check, does it working fine or not. Jan 11, 2020 at 7:12
  • @DhirenVasoya,no,just Magento2 default.There is not any issue just I want to implement that functionality as per screenshot
    – akgola
    Jan 11, 2020 at 7:12

1 Answer 1

2

Hi if your need multiple Order Grid based on status then you need to create module for that Create below file for your module as usual create

registration.php
etc/module.xml

Create your module namespace for Admin area in etc/adminhtml/routes.xml file as below

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="multiordergrid" frontName="multiordergrid">
            <module name="Vendor_Multiordergrid" before="Vendor_Multiordergrid" />
        </route>
    </router>
</config>

Now create menu for seprate Grid show in etc/adminhtml/menu.xml as follow

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Vendor_Multiordergrid::manager" title="Multi Order Grid" module="Vendor_Multiordergrid" sortOrder="10" resource="Vendor_Multiordergrid::manager"/>
        <add id="Vendor_Multiordergrid::pending" title="Pending Order" module="Vendor_Multiordergrid" sortOrder="0" parent="Vendor_Multiordergrid::manager"
                action="multiordergrid/sales/pending" resource="Vendor_Multiordergrid::pending"/>
    </menu>
</config>

Create Controller file for pending action of your module in Controller/adminhtml/Sales/Pending.php

<?php

namespace Vendor\Multiordergrid\Controller\Adminhtml\Sales;

use Magento\Backend\App\Action;

class Index extends \Magento\Framework\App\Action\Action {
    protected $_pageFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory) {
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);
    }

    public function execute() {
        return $this->_pageFactory->create();
    }
}

Create your pending Action layout file in view/adminhtml/layout/multiordergrid_sales_pending.xml as below

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
       <referenceContainer name="content">
            <uiComponent name="sales_order_grid"/>
        </referenceContainer>
    </body>
</page>

Now you can see the order grid in your Layout, Now we need to filter the order collection for the our Layout Grid for that create etc/di.xml file and override the order Grid collection file

<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\Multiordergrid\Model\ResourceModel\Order\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

Now create Collection.php file as below file Vendor\Multiordergrid\Model\ResourceModel\Order\Grid

<?php
namespace Vendor\Multiordergrid\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;
use Psr\Log\LoggerInterface as Logger;

class Collection extends OriginalCollection {
    protected $_authSession;
    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger,
        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        \Magento\Backend\Model\Auth\Session $authSession
    ) {
        $this->_authSession = $authSession;
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager);
    }

    protected function _renderFiltersBefore() {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $request = $objectManager->get("\Magento\Framework\App\Request\Http");

        $moduleName = $request->getModuleName();
        $controller = $request->getControllerName();
        $action = $request->getActionName();

        $url = $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        if ($moduleName == "mui" && $controller == "index" && $action == "render") {
            $url = $_COOKIE["current_url"];
        }

        if (strpos($url, 'multiordergrid/sales/pending') !== false) {
            setcookie("current_url", $url, time() + (86400 * 30), "/");
            $this->getSelect()->where("status = 'pending'");
        }

        parent::_renderFiltersBefore();
    }
}

now run Magento basic command and check your pending grid it will show only order with pending status

Please follow above steps for all Magento order status.

Thank you

3
  • thanks for your effort.I will check and share you.
    – akgola
    Jan 11, 2020 at 7:10
  • does it resolved or not ? Jan 11, 2020 at 19:14
  • this is creating new menu grid while I need the same sales order grid exactly same attached screenshot.
    – akgola
    Jan 14, 2020 at 6:55

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.