How can I get a products list by category ID? I need to display them with products name or ID.

My code so far:

$productCollection = Mage::getModel('catalog/product')->load($currentctid)
                    ->addAttributeToFilter('status', array('eq' => 1))
                    ->joinTable('pdp/productstatus', 'product_id=entity_id', array('*'));
  • $productCollection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToSelect('*') ->addAttributeToFilter('category_id', array('in' => $currentctid)); – Allamsetti Oct 28 '15 at 14:21

This should do the trick. It retrieves the active category. If that is not set it gets the first category the product is assigned to. The collection holds all products for that category

$category = Mage::registry('current_category');
if (empty($category)) {
   $product = Mage::registry('current_product');
   $categoryId = reset($product->getCategoryIds());
   $category = Mage::getModel('catalog/category')->load($categoryId);

$collection = Mage::getResourceModel('catalog/product_collection')
  • @Ramesh if it worked for you please accept the answer :) – Sander Mangel Nov 9 '15 at 8:00
  • @Ramesh can you accept this as the answer? It has a check under the vote buttons – Sander Mangel Nov 10 '15 at 9:42

Your Answer

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

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