I want to override product collection in Magento product grid in admin side.
Please let me know which file I need to override for collection filter
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou can use Plugin and add below code in your admin's di.xml file
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
<plugin name="product-collection-sorting" type="[Vendor]\[Module]\Plugin\ProductDataProvider" sortOrder="999"/>
</type>
Now create file [Vendor][Module]\Plugin\ProductDataProvider
<?php
namespace [Vendor]\[Module]\Plugin;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider as RelatedProductDataProvider;
class ProductDataProvider extends RelatedProductDataProvider
{
public function afterGetData(
\Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject,
$result
)
{
$subject->getCollection()->clear();
$subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->load();
$items = $subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->toArray();
$totalRecords = $subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->load()->getSize();
}
}
Recently i did similar by using prefernce
<preference for="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider" type="vendor\Module\Ui\DataProvider\Product\ProductDataProvider" />