0
votes

We're currently working on our category pages within Magento and have the following code to provide a list of child categories for the category we are in.

We have the following setup:

Store - Cat 1 - Gloss Colours (Parent) -- Sub cat 1 - Zurfiz (Child) -- Sub cat 2 - Parapan (Child)

Screenshot of dropdown: http://awesomescreenshot.com/048kga35a

We are looking to modify the code to show a option of "Show All" and link to the parent category within the dropdown menu as well as the child categories, does anyone know what code we should pull up for this?

From app\design\frontend\default[our template]\template\catalog\navigation\left.phtml

<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories=$this->getCurrentChildCategories() ?>
<?php 
    $oLayer = null;
    $oCat = $this->getCurrentCategory();
    # level 3 categories display their category siblings
    if (3 === (int)$oCat->getData('level')) {
        # get the layer object
        $oLayer = Mage::getSingleton('catalog/layer');
        $oParentCategory = $oCat->getParentCategory();
        # set the parent category as the current category
        $oLayer->setData('current_category',$oParentCategory);
        # load the child categories
        $_categories = $this->getCurrentChildCategories();
    }
?>
<?php if($_categories->count()): ?>
<div class="box layered-nav">
    <?php
        # switch back the current category
        if (null !== $oLayer) $oLayer->setData('current_category',$oCat);
    ?>

<script language="javascript" type="text/javascript" >
function jumpto(x){
if (document.form1.jumpmenu.value != "null") {
document.location.href = x
}
}
</script>
<div class="cat-dropdown">
      <form name="catlist">
        <select name="jumpmenu" onChange="jumpto(document.catlist.jumpmenu.options[document.catlist.jumpmenu.options.selectedIndex].value)">
        <option value="#">Choose a brand</option>
                <?php foreach ($_categories as $_category): ?>
                    <?php if($_category->getIsActive()): ?>
          <option value="<?php echo $this->getCategoryUrl($_category) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> (<?php echo $_category->getProductCount() ?>)</option>
                              <?php endif; ?>
                <?php endforeach ?>
        </select>
      </form>
</div>
</div>
<?php endif; ?>
1
We are looking to modify the code to show a option of "Show All" and link to the parent category within the dropdown menu as well as the child categories, does anyone know what code we should pull up for this? - Vince Pettit

1 Answers

1
votes

Use this code..

<?php
//$id = whatever
$subcats  = Mage::getModel('catalog/category')->load($id)->getAllChildren();
?>

<select name="jumpmenu">
<option value="#">Choose a brand</option>
<?php
foreach(explode(',',$subcats) as $subCatid)
{
   $_category = Mage::getModel('catalog/category')->load($subCatid);
       //print_r($_category);
 ?>
   <option value="<?php echo $_category->getCategoryUrl() ?>"><?php echo htmlEscape($_category->getName()) ?></option>

<?php } ?>

</select>