I have created a preference to add my custom filter to the collection.
di.xml
This is my ListProductPot.php file
< ?php
namespace VendorModuleBlockRewriteProduct;
use MagentoCatalogApiCategoryRepositoryInterface;
use MagentoCatalogBlockProductContext;
use MagentoCatalogModelLayerResolver;
use MagentoFrameworkDataHelperPostHelper;
use MagentoFrameworkUrlHelperData;
class ListProductPot extends MagentoCatalogBlockProductListProduct
{
public $featuredProduct;
public function __construct(
Context $context,
PostHelper $postDataHelper,
MagentoFrameworkStdlibDateTimeDateTime $dateTime,
VendorPotHelperData $potHelper,
VendorPotBlockFeaturedProducts $featuredProductList,
Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
Data $urlHelper,
array $data = []
) {
$this->featuredProduct = $featuredProductList;
$this->data = $potHelper;
$this->datetime = $dateTime;
parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
}
public function getLoadedProductCollection()
{
$collectionArray[]='';
$objDate = $this->datetime;
$helperPot= $this->data;
$currentDate = $helperPot->getCurrentstoreDate();
$products = parent::_getProductCollection();
$collection = $products->addAttributeToFilter('sku', ['in' => array_filter($collectionArray)]);
return $collection;
}
}
But it is not working on listing page.
I am getting product collection every time same.
Any help will be appreciated .