cancel
Showing results for 
Search instead for 
Did you mean: 

Custom collection in the sales invoice grid Admin Magento 2

Custom collection in the sales invoice grid Admin Magento 2

  1. Magento CE 2.4
  2. PHP 7.4
  1. Join the custom table with sales invoice grid collection by overriding the core Magento class Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection to filter custom column ERP invoice number in the sales invoice grid

Note:
The same code is working in Magento 2.3.x. We observed that the class

 

Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection removed from Magento 2.4.x.


In Magento 2.4 use the below code:

 

    <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">Magento\Sales\Model\ResourceModel\Order\Grid\Collection</item>
                <item name="sales_order_invoice_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection</item>
                <item name="sales_order_shipment_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection</item>
                <item name="sales_order_creditmemo_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid\Collection</item>
                <item name="sales_order_view_invoice_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice\Orders\Grid\Collection</item>
                <item name="sales_order_view_shipment_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Shipment\Order\Grid\Collection</item>
                <item name="sales_order_view_creditmemo_grid_data_source" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Creditmemo\Order\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">sales_invoice_grid</argument>
            <argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice</argument>
        </arguments>
    </virtualType>

Please suggest a way for a custom collection in the sales invoice grid in Magento 2.4.x.

Thank you so much for looking into this issue.