0

I'm trying to show newly added 30 products on the category list page for a specific category. it has more than 1k products. I have tried to modify temporarily the code in the following file but it never works:

Magento\Catalog\Block\Product\ListProduct;

Original code:

protected function _getProductCollection()
    {
        if ($this->_productCollection === null) {
            $this->_productCollection = $this->initializeProductCollection();
        }

        return $this->_productCollection;
    }

Updated code:

 protected function _getProductCollection()
    {
        if ($this->_productCollection === null) {
            $this->_productCollection = $this->initializeProductCollection();
        }

        return $this->_productCollection->setPageSize(30);
    }

1 Answer 1

0

You should not update core files of magento. This is not a good practice.

I would suggest creating a new class, ideally in your Model folder which would do this for you.

can you try this code to see that only 30 records are returned?

$this->_productCollection->setCurPage(1);
$this->_productCollection->setPageSize(30);
return $this->_productCollection;
1
  • Did you read the post carefully? I am doing this temporarily, If the code will work then will create a plugin
    – Arunendra
    Sep 18, 2020 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.