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.
how is this possible?Please give me an idea for that.
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.
how is this possible?Please give me an idea for that.
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