Skip to main content

To modify product collection before rendering category page follow these steps:

  1. Override Magento\Catalog\Block\Product\ListProduct

  2. In function _getProductCollection after if statement insert your code:

    $collection = $this->_productCollection; foreach ($collection as $k => $product){ // Here goes your code to modify product // For example:

    $collection->removeItemByKey($k);// Remove original item from collection } $collection->setOrder('position','ASC');// Reorder collection as you want return $collection;

  1. Override Magento\Catalog\Block\Product\ListProduct 2. In function _getProductCollection after if statement insert your code:
$collection = $this->_productCollection;
foreach ($collection as $k => $product){
 // Here goes your code to modify product
 // For example:

$collection->removeItemByKey($k);// Remove original item from collection 
}
$collection->setOrder('position','ASC');// Reorder collection as you want
return $collection;

To modify product collection before rendering category page follow these steps:

  1. Override Magento\Catalog\Block\Product\ListProduct

  2. In function _getProductCollection after if statement insert your code:

    $collection = $this->_productCollection; foreach ($collection as $k => $product){ // Here goes your code to modify product // For example:

    $collection->removeItemByKey($k);// Remove original item from collection } $collection->setOrder('position','ASC');// Reorder collection as you want return $collection;

To modify product collection before rendering category page follow these steps:

  1. Override Magento\Catalog\Block\Product\ListProduct 2. In function _getProductCollection after if statement insert your code:
$collection = $this->_productCollection;
foreach ($collection as $k => $product){
 // Here goes your code to modify product
 // For example:

$collection->removeItemByKey($k);// Remove original item from collection 
}
$collection->setOrder('position','ASC');// Reorder collection as you want
return $collection;
Source Link

To modify product collection before rendering category page follow these steps:

  1. Override Magento\Catalog\Block\Product\ListProduct

  2. In function _getProductCollection after if statement insert your code:

    $collection = $this->_productCollection; foreach ($collection as $k => $product){ // Here goes your code to modify product // For example:

    $collection->removeItemByKey($k);// Remove original item from collection } $collection->setOrder('position','ASC');// Reorder collection as you want return $collection;