如何在magento中进行第二个根类别导航?

时间:2012-11-17 22:34:06

标签: magento

除了我将子类别添加到主根类别时获得的常规导航,我希望能够创建新的根类别,为其分配子类别并将其显示为单独的菜单。

这可能吗?

2 个答案:

答案 0 :(得分:0)

这可以帮到你:
Link 1
Link 2

检索另一个根类别

<?php 
echo '<pre>';
$id=9; 
    $catagory_model = Mage::getModel('catalog/category');
    $categories = $catagory_model->load($id); // where $id will be the known category id
    if(!empty($categories))
    {
        echo 'category name->'.$categories->getName(); //get category name
        echo '<br>';
        echo 'category image url->'.$categories->getImageUrl(); //get category image url
        echo '<br>';
        echo 'category url path->'.$categories->getUrlPath(); //get category url path
        echo '<br>'; 
    }
    ?>

现在$id=9;是我的新根类别ID 要检索以下新根类别($id=9;)的子类别,请参阅以下参考代码。
根据您的要求进行自定义。

<?php $helper = $this->helper('catalog/category') ?>
 <?php $categories = $this->getStoreCategories() ?>
  <?php foreach($categories as $category): ?>
    <?php $subcategories = $category->getChildren() ?>
      <?php foreach($subcategories as $subcategory): ?>
        <?php $subsubcategories = $subcategory->getChildren() ?>
         <?php foreach($subsubcategories as $subsubcategory): ?>
         <?php endforeach; ?><!-- end foreach subsubcategories -->
      <?php endforeach; ?><!-- end foreach subcategories -->
  <?php endforeach; ?><!-- end foreach categories -->

答案 1 :(得分:0)

在一个理想的世界里,你现在已经找到了答案,但是如果你没有修改Nikhil的答案,那么我基本上可以完成你所描述的工作,减去任何便利。 ..

$id=9; 
$catagory_model = Mage::getModel('catalog/category');
$categories = $catagory_model->load($id);
if(!empty($categories))
{
    $cats = explode(",", $categories->getChildren());
    foreach($cats AS $c)
    {
        $cat = $catagory_model->load(trim($c));
        echo '<a href="/'.$cat->getUrlKey().'">'.$cat->getName().'</a>';
    }
}

我只是粘贴我用过的东西。现实情况是你必须构建html,以便做到你想做的任何事情。如果循环中有子类别,则必须在foreach部分中运行另一个fetch。 我不熟悉magento足以知道你可以在$ cat对象上运行什么方法。我做了一个print_r($cat)检查对象,并且幸运地猜到了getUrlKey可用。

Magento ...... pfft!你认为ebay会有比这更高的标准。

相关问题