I'm using Magento EE Lite (1.11.02) and I'm trying to load a collection of products by one single category. The following code functions as you would expect:
public function getProductList()
{
$products = Mage::getModel('catalog/category');
$productslist = $products->getProductCollection()->addAttributeToSelect('*');
foreach($productslist as $product)
{
echo 'name: ' . $product->getName() . '<br/>';
}
}
It outputs the name of every product in the catalog (including the products in the category I'm trying to select in future examples). But as soon as I try to add any kind of category filter:
public function getProductList()
{
$products = Mage::getModel('catalog/category')->load(3);
$productslist = $products->getProductCollection()->addAttributeToSelect('*');
foreach($productslist as $product)
{
echo 'name: ' . $product->getName() . '<br/>';
}
}
or:
public function getProductList()
{
$products = Mage::getModel('catalog/category');
$productslist = $products->getProductCollection()->addAttributeToSelect('*')
->addCategoryFilter(3);
foreach($productslist as $product)
{
echo 'name: ' . $product->getName() . '<br/>';
}
}
It doesn't output anything. No errors, it just acts the way it would if zero products were loaded.
The products are in a subcategory of a root category. I've tried different categories, creating new categories, populating them with new items, I've checked their visibility, their status, I've tried a dozen different code snippets, nothing ever works.
Is there something wrong with my code? Is there some setting in categories that could cause it to be unfilterable? I'm running out of ideas, any help is very appreciated.