Magento Load Category Product Collection


Magento Load Category Product Collection: Category Product Collection in magento is loaded using the model catalog/product_collection. It requires the category as resource to load the products.


Syntax for Magento Load Category Product Collection

Here is the syntax to load the magento category products.

$layer = Mage::getSingleton('catalog/layer');
$Category = $layer->getCurrentCategory();
$currentCatId= $Category->getId(); //will give current categeory id
$category = Mage::getModel('catalog/category')->load($categoryId);

$collection = Mage::getResourceModel('catalog/product_collection')
                                 ->addCategoryFilter($category);
foreach ($collection as $product){
   echo $product->getId().'</br>';
   echo $product->getName().'</br>';
}

The above collection will return the magento products in the selected category. You can use the above code in the phtml you want to display. You can add your own filter to load the products.


Advertisements

Add Comment

📖 Read More