0

I am using Magento CE 1.9.2.2 what I am trying to do is I have category structure like the below

- Party
     - Balloons
     - Bags
     - Streamers

Now if you click on the category "party" on the left side Magento shows the "browse by" category/sub category list. However if I click on Balloons I want the same browser by block to be displayed so that even when you are on a sub category page you will be able to see the links to the other sub categories in the left side column in a browser by box.

Hope this is clear what I want to achieve because I am not able to get anything to be displayed on the sub categories? So what I have done is in Magento manage categories I went to the "balloons" category and changed Display Mode to static block and products. I then changed the drop down CMS Block and selected the block I made called Sub Category Listing.

Then in my Sub category listing block I added the below in code view {{block type="catalog/navigation" template="catalog/navigation/subcategory_listing.phtml"}}

I then opened ftp and created the subcategory_listing.phtml and added the below code

       $layer = Mage::getSingleton('catalog/layer');
       $_category   = $layer->getCurrentCategory();
       $_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
           ->addAttributeToFilter('is_active', 1)
           ->addIdFilter($_category->getChildren())
           ->setOrder('position', 'ASC')
           ->joinUrlRewrite();
     ?>

     <div class="listing-type-list catalog-listing">
          <ul id="subcats" class="clear">
                <?php foreach ($_categories as $_category): ?>
                <?php if($_category->getIsActive()): ?>
                <?php Mage::log($_category->debug(), null, 'mylogfile.log'); ?>
                <li>
                    <div class="subcat clearfix">
                        <a class="now-from-container" href="<?php echo $_category->getURL() ?>"></a>
                        <div class="subcat-image">
                            <a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
                                <img src="<?php echo $this->htmlEscape($_category->getImageUrl()) ?>" width="190" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
                            </a>
                        </div>
                        <div class="subcat-title-container">
                            <h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h2>
                        </div>
                    </div>
                </li>
            <?php endif; ?>
        <?php endforeach; ?>
     </ul>
</div>
1

In your code to get the children categories from current category, which looks like this :

<?php
    $layer = Mage::getSingleton('catalog/layer');
    $_category   = $layer->getCurrentCategory();
    $_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($_category->getChildren())
        ->setOrder('position', 'ASC')
        ->joinUrlRewrite();
?>

Try with this code instead :

<?php
    $layer = Mage::getSingleton('catalog/layer');
    $_category   = $layer->getCurrentCategory();
    $_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($_category->getAllChildren(true))
        ->setOrder('position', 'ASC')
        ->joinUrlRewrite();
?>

Difference is, your call to method getChildren returns a comma separated list of IDs, not an array, while the method addIdFilter expects an array to be passed. When you pass true to the method getAllChildren, it will return the list as an array.

  • Thank you Prateek, I tried the change you listed but that did not do anything? – Jayreis Jan 3 '16 at 2:50
  • @user1739740, check with var_dumo($_category), if it contains anything at all. – Prateek Jan 4 '16 at 9:43
  • I did a var_dump($_category) as well as var_dump($_categories) and both do not display anything to the page. So not sure where to go from here? – Jayreis Jan 5 '16 at 2:43
  • Well, then either you are not on a category page or that category is not set as anchor in admin. Check both of these. – Prateek Jan 5 '16 at 6:33

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.