Getting all children from specified category then pulling products from all the childrens
$_category = Mage::getModel('catalog/category')->load(5);
$lids = $_category->getAllChildren();
$ids = explode(',',$lids);
echo '<pre>';
print_r($ids);
echo '</pre>';
if ($ids)
{
foreach ($ids as $id)
{
$cat = Mage::getModel('catalog/category');
$cat->load($id);
if($cat->getIsActive()==1)
{
$category1 = Mage::getModel('catalog/category')->load($cat->getId());
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('megamenu_category_product')
->addCategoryFilter($category1);
foreach ($products as $product) {
if ($product->getData('megamenu_category_product') == true){
echo "<div>" . $product->getData('name') . " - ". $product->getSku() . "</div>";
break;
}else{
//echo 'FOO<br/>';
}
}
}
}
}
because I used '->addAttributeToSelect("megamenu_category_product")' it won't display product->getName() What am I doing wrong ?