2011-09-15 57 views
0

我们目前正在对内部的Magento我们的类别页,并具有以下代码为类别,我们在提供儿童的类别列表Magento的 - 显示父和子类别的下拉菜单

我们有。以下设置:

商店 - 猫1 - 光泽颜色(家长) - 子猫1 - Zurfiz(儿童) - 子猫2 - Parapan(儿童)

截图下拉菜单中:http://awesomescreenshot.com/048kga35a

我们正在修改代码以显示“显示全部”选项并链接到下拉菜单中的父类别以及子类别,有人知道我们应该为此提供哪些代码?

从应用程序\设计\前台\ DEFAULT [我们的模板] \模板\目录\导航\ 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

和你的问题是什么? –

+0

我们正在修改代码以显示“显示全部”选项并链接到下拉菜单中的父类别以及子类别,有人知道我们应该为此提供哪些代码? –

回答

1

使用此代码..

<?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> 
相关问题