0

I have to override the file ProductCollection.php from vendor/magento/module-catalog/Ui/DataProvider/Product.

I have read many posts but still not getting to override the file.

Can anyone please explain it to me step by step?

Your help is greatly appreciated.

3

In order to override

First create di.xml in your module Namespace/Module/etc/di.xml

<type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
    <plugin name="product-collection-sorting" type="Namespace\Module\Plugin\Product\Collection" sortOrder="1"/>
</type>

Create Namespace\Module\Plugin\Product\Collection.php and pasted below code in your file:

<?php
namespace Namespace\Module\Plugin\Product;

class Collection
{

    //do stuff here like override functions
}

I hope this will help

  • I have tried it but it's not working. Please guide me – Siva Jul 31 at 13:36
3

Instead of overriding the Product collection you can create a plugin on the public function of ProductCollection.php. It is a recommended way for doing any modification to core files.

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.