1

I have a custom grid, where it gets some data from the shipment table. This is the error message received:

Missing required argument $mainTable of Vendor\Module\Model\ResourceModel\Order\Shipment\Order\Grid\Collection.

This is the code from di.xml:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="vendor_module_grid_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\Order\Shipment\Order\Grid\Collection</item>
        </argument>
    </arguments>
</type>

and my Vendor\Module\Model\ResourceModel\Order\Shipment\Order\Grid\Collection file:

use Magento\Sales\Model\ResourceModel\Order\Shipment\Order\Grid\Collection as ShipmentGridCollection;
class Collection extends ShipmentGridCollection
{
    /**
     * @var ShipmentHelper
     */
    private $shipmentHelper;

    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger, FetchStrategy
        $fetchStrategy,
        EventManager $eventManager,
        $mainTable = 'sales_shipment_grid',
        $resourceModel = Shipment::class,
        ShipmentHelper $shipmentHelper
    ) {
        $this->shipmentHelper = $shipmentHelper;
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $mainTable,
            $resourceModel
        );
    }
    /**
     * Filter the sales_order_grid table
     */
    protected function _renderFiltersBefore()
    {
        $this->getSelect()->join(
            ['sales_shipment' => $this->getTable('sales_shipment')],
            'main_table.increment_id = sales_shipment.increment_id',
            ['sales_shipment.entity_id as shipment_entity_id']
        );
        $this->getSelect()->join(
            ['sales_order' => $this->getTable('sales_order')],
            'sales_shipment.order_id = sales_order.entity_id',
            ['status']
        );
        $this->getSelect()->order('main_table.entity_id ASC');
        parent::_renderFiltersBefore();
    }

}

Does anyone know why exactly I got that error ? Thank you

2
  • please share complete code of yours di.xml file in above question. Jul 8 '20 at 7:41
  • @HiteshBalpande that is all of it, except the <config> tag Jul 8 '20 at 8:59
1

Change di.xml file

 <type name="Vendor\Module\Model\ResourceModel\Deal\Grid\Collection">
<arguments>
    <argument name="mainTable" xsi:type="string">sales_shipment_grid</argument>
    <argument name="resourceModel" xsi:type="string">Vendor\Module\Model\ResourceModel\Deal</argument>
</arguments>
1

please try to change your di.xml code with below one.

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="vendor_module_grid_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\Order\Shipment\Order\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    
    <type name="Vendor\Module\Model\ResourceModel\Order\Shipment\Order\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">your_main_table_name</argument>
            <argument name="eventPrefix" xsi:type="string">Vendor_Module__grid_collection</argument>
            <argument name="eventObject" xsi:type="string">Vendor_Module_collection</argument>
            <argument name="resourceModel" xsi:type="string">Vendor\Module\Model\ResourceModel\Order</argument>
        </arguments>
    </type>

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.