Magento - 类别和子类别页面上的不同记录

时间:2011-06-01 06:44:17

标签: magento categories product

我有2个类别级别(顶级和次级类别)。在顶级类别页面上,我需要显示所有子类别,每个子类别的子类别产品很少。还需要在顶级类别页面上显示一些其他详细信息。

在子类别页面上,需要显示子类别产品。

因为我们有一个类别和子类别产品页面的模板页面。

如何处理。

2 个答案:

答案 0 :(得分:1)

$currCat = Mage::registry('current_category');

/**
 * get sub categories of current category
 */
$collection = Mage::getModel('catalog/category')
                   ->getCategories($currCat->getEntityId());

/** 
 * only showing active sub categories
 */
foreach($collection as $cat) {
    if($cat->getIsActive()) {
        $category = Mage::getModel('catalog/category')
                         ->load($cat->getEntityId());

        $prodCollection = Mage::getResourceModel('catalog/product_collection')
                               ->addCategoryFilter($category);

        Mage::getSingleton('catalog/product_status')
             ->addVisibleFilterToCollection($prodCollection);

        Mage::getSingleton('catalog/product_visibility')
             ->addVisibleInCatalogFilterToCollection($prodCollection);

        ?>

        <a href="<?php echo $category->getUrl() ?>">
           <?php echo $category->getName() ?>
        </a> (<?php echo $prodCollection->count() ?>)<br/>

        <?php
    }
}

来源:Get Sub Categories & Product Count

答案 1 :(得分:1)

也许此链接有助于显示子类别。 http://fishpig.co.uk/display-categories-and-subcategories-in-magento/

对于产品,您可以看到作为锚的用途是否适合您或您尝试 http://oggettoweb.com/blog/news/magento-extension-product-blocks/ 或者您修改模板以拉出某些具有某些属性的产品

相关问题