0

I want to show subcategory with its products in list.phtml. I am trying

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
    <?php if (count($_categories) > 0): ?>
        <ul>
            <?php foreach ($_categories as $_category): ?>
                <li>

                    <?php if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?>
                    <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                        <?php $_subcategories = $_category->getChildrenCategories() ?>
                        <?php if (count($_subcategories) > 0): ?>
                        <ul>
                                    <?php foreach ($_subcategories as $_subcategory): ?>
                                <li>
                                <?php echo $_subcategory->getName(); 
                                     $category = Mage::getResourceModel('catalog/category_collection')
                                    ->addFieldToFilter('name', $_subcategory->getName());
                                    print_r($category->getData());

                                ?>
                                    </a>
                                </li>
                        <?php endforeach; ?>
                        </ul>
                <?php endif; ?>
                <?php endif; ?>
                </li>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

it will show all sub category with its details but how can i find subcategory products and details through it.

1 Answer 1

0

Try below script

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())
?>
    <?php foreach ($categories as $category): ?>

         <?php echo "<pre>"; print_r($category->getData());?>

        <?php
           $_helper = $this->helper('catalog/output');
           $products = Mage::getModel('catalog/product')
            ->getCollection()
            ->addCategoryFilter($category)
            ->load();
        ?>

        <?php foreach ($products as $product): ?>
           <?php echo "<pre>"; print_r($product->getData());?>
        <?php endforeach ; ?>

    <?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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