I want to hide order from sales order grid with status like 'pending_payment'. How can I do in Magento 2?

有帮助吗?

解决方案

I have tried to hide orders which have status 'canceled'. I have used plugin method for it.

In your custom module please create files as per mentioned below

Step 1 : Please create di.xml file under PackageName/Hideorders/etc/adminhtml/

<?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="PackageName\Hideorders\Model\Plugin\Sales\Order\Grid"/>
    </type>
</config>

Step 2: Please create file Grid.php file under PackageName/Hideorders/Model/Plugin/Sales/Order/

<?php

namespace PackageName\Hideorders\Model\Plugin\Sales\Order;

class Grid {

    public static $table = 'sales_order_grid';

    public function afterSearch($intercepter, $collection) {
        if ($collection->getMainTable() === $collection->getConnection()->getTableName(self::$table)) {
            $collection->addFieldToFilter('status',array('neq' => 'canceled'));//You can write your status here
        }
        return $collection;
    }
}
许可以下: CC-BY-SA归因
scroll top