1

I am overriding getLoadedProductCollection() in my block where performing some custom query

     public function getLoadedProductCollection()
        {
            $myCategory = $this->_coreRegistry->registry('category_details');

            if ($myCategory['category_id'] === '96') {

     $collection = $this->collectionFactory; // dont forget to inject the product factory in your constructor
                        $collection = $collection->create()->getCollection();
                        $collection = $collection->addFieldToFilter(
                            'entity_id',
                            ['in' => $array]
                        );
                        $collection = $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())
                            ->addMinimalPrice()
                            ->addFinalPrice()
                            ->addTaxPercents()
                            ->addUrlRewrite($myCategory);
                        return $collection;
           }
else {
             return parent::getLoadedProductCollection();
    }

But the problem is when my category id is 96 its run the upper query and show but in with in second it fired

return parent::getLoadedProductCollection();

and then return null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.