Magento EE 1.13 – List All Products in Category, Including Disabled

blocksee-1.13product-collectionproduct-list

How can I show all products in a category, regardless of its status? I have a category that I want to show all products in the category, even it is disabled, invisible, out of stock, or whatever. I've made a new product/list.phtml template for this specific category and am overriding the Mage_Catalog_Block_Product_List to add a new method to accomplish this. In that method is this code

$catId = 432;  //for simplicity
$category = Mage::getModel('catalog/category')->load($catId);

return $category->getProductCollection()
    ->addAttributeToSelect('sku');

It is only retrieving enabled products. However, if I run the same code in a testing script (outside of catalog module) that loads Magento, I get all products that I'm looking for, enabled and disabled. How can I accomplish this?

Best Answer

Please use this code

$productCollection = Mage::getResourceModel('catalog/product_collection')

                        ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
                        ->addAttributeToFilter('category_id', 3);
                       $productCollection->getSelect()->group('product_id')->distinct(true);
echo '<pre>'; print_r($productCollection->getData());

Definitely this work for you.

Related Topic