2013-06-26 54 views
0

如何在彈出窗口中顯示樹狀結構中的所有類別,即。)如果我點擊我的頁面中的選擇類別按鈕,它應該顯示彈出窗口,樹狀結構爲 結構化categories.i試過這樣它會顯示在下拉列表中所有的類別不好看如何在樹狀結構中顯示類別

<?php                    

    $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter(); 
    $allcatid = array(); 
    $k=0; 
    foreach ($categories as $c) { 
    $allcatid[$k] = $c->getId(); 
    $k++; 
    } 
    $finalcat=array_shift($allcatid); 
    $root= Mage::app()->getStore()->getRootCategoryId(); 
?> 

<select id="category" class="myinput-text required-entry widthinput" name="category" > 
    <?php foreach($allcatid as $keycat){?> 
     <option value="<?php echo $keycat;?>"><?php echo Mage::getModel("catalog/category")->load($keycat)->getName(); ?></option> 
    <?php } ?> 
+0

如果你發現我的答案有幫助,然後接受我的回答 –

回答

1

這將幫助你把你接類別樹

<?php 
$rootcatId= Mage::app()->getStore()->getRootCategoryId(); 
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId); 
function get_categories($categories) { 
    $array= '<ul>'; 
    foreach($categories as $category) { 
     $cat = Mage::getModel('catalog/category')->load($category->getId()); 
     $count = $cat->getProductCount(); 
     $array .= '<li>'.'<a href="'.Mage::getUrl($cat->getUrlPath()). '">'.   $category->getName() . "(".$count.")</a>\n"; 
     if($category->hasChildren()) { 
      $children = Mage::getModel('catalog/category')->getCategories($category->getId()); 
      $array .= get_categories($children); 
      } 
     $array .= '</li>'; 
    } 
    return $array . '</ul>'; 
} 
echo get_categories($categories); ?> 
+0

謝謝德赫你幫了我很多,但我想顯示所有的類別和子類別和sububcategories ...在樹結構中)如果我點擊+意味着它應該顯示子類別並且意味着它應該隱藏子類別(展開和摺疊模型) – Balram

+0

如果它幫助你比接受答案並且贊成它並且如果你想擴大和崩潰,那麼你必須編寫自定義原型/ jQuery,我已經實現了,但這將很複雜,在這裏解釋.. – DepH

+0

對不起,這個人,我沒有足夠的聲譽,我現在只加入這個組..所以只有不能upvote你。 – Balram

0
enter code here 
<?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> 
       <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> 
        <?php echo $_category->getName() ?> 
       </a> 
       <?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> 
           <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> 
            <?php echo $_subcategory->getName() ?> 
           </a> 
          </li> 
         <?php endforeach; ?> 
        </ul> 
       <?php endif; ?> 
      </li> 
     <?php endforeach; ?> 
    </ul> 
<?php endif; ?> 

這將取所有catgory和子類別,,,希望這會幫助你