php - Mageto - Filter Category Navigation in tree like state -
i created code filter product collection categories. making own left side block using following code.
i have work perfect filtering, having hard time rendering display.
the level 2 categories work fine , show
- top level category 1
- top level category 2
once selected shows sub categories , sub categories..
- sub category of 1
- sub sub category of ^^^
- sub sub category of ^^^
- sub sub category of ^^^
- sub sub sub category of ^^^
- sub category of 1
- sub sub category of ^^^
- sub sub category of ^^^
- sub sub category of ^^^
- sub sub sub category of ^^^
i need break down first level did. best method?
<?php $root_category_id = mage::app()->getstore()->getrootcategoryid(); $filtercategoryid = mage::app()->getrequest()->getparam('cat'); $products = mage::getsingleton('catalogsearch/advanced')->getproductcollection(); $catids = array(); if (isset($products)) foreach ($products $product) { if ($product->issaleable()) { $ids = $product->getcategoryids(); foreach ($ids $id) $catids[$id] = 1; } } if (!isset($catids)) return false; $categories = array(); // filters rest of categories if ($filtercategoryid) { $filtercategory = mage::getmodel('catalog/category')->load($filtercategoryid); $filterchildren = $filtercategory->getallchildren(true); foreach ($catids $id => $x) { $category = mage::getmodel('catalog/category')->load($id); if (in_array($root_category_id, $category->getparentids()) && in_array($id, $filterchildren) && $id != $filtercategoryid) { $categories[$id] = $category->getname(); } else { unset($catids[$id]); } } } else { // filters first level categoires foreach ($catids $id => $x) { $category = mage::getmodel('catalog/category')->load($id); if (in_array($root_category_id, $category->getparentids()) && $category->getlevel() == 2) { $categories[$id] = $category->getname(); } else { unset($catids[$id]); } } } if(isset($categories) && sizeof($categories) > 0): $url = mage::app()->getrequest()->getrequesturi(); $url = mage::helper("core/url")->removerequestparam($url, 'cat'); ?> <div class="page-subtitle" style="margin:6px auto 14px 6px;"><h2>shop category</h2></div> <ul class="brandsnav"> <?php foreach($categories $id=>$name): ?> <li class="cf"> <span class="subnav_trigger"></span> <a href="<?php echo mage::helper("core/url")->addrequestparam($url, array("cat"=>$id)); ?>"><?php echo $name;?></a> </li> <?php endforeach; ?> </ul> <?php endif; ?>
i had add conditions foreach statements. got working.
Comments
Post a Comment