Magento锚定类别的产品数量

时间:2012-09-26 10:34:56

标签: php magento

我想要一个脚本或想法,通过它我可以获得锚定类别的产品计数。

我在loadProductCount()类中尝试了Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection方法,但它没有返回产品计数,而是返回一个数组。请看下面给出的数组:

Array
(
    [0] => Array
        (
            [entity_id] => 1
            [entity_type_id] => 3
            [attribute_set_id] => 0
            [parent_id] => 0
            [created_at] => 0000-00-00 00:00:00
            [updated_at] => 2011-10-31 16:14:51
            [path] => 1
            [position] => 0
            [level] => 0
            [children_count] => 163
        )

    [1] => Array
        (
            [entity_id] => 2
            [entity_type_id] => 3
            [attribute_set_id] => 3
            [parent_id] => 1
            [created_at] => 2011-10-31 16:14:51
            [updated_at] => 2012-09-07 20:51:21
            [path] => 1/2
            [position] => 1
            [level] => 1
            [children_count] => 163
        )

[2] => Array
    (
        [entity_id] => 117
        [entity_type_id] => 3
        [attribute_set_id] => 0
        [parent_id] => 2
        [created_at] => 2012-09-07 16:51:28
        [updated_at] => 2012-09-10 07:55:24
        [path] => 1/2/117
        [position] => 13
        [level] => 2
        [children_count] => 15
    )

....

2 个答案:

答案 0 :(得分:2)

如果您希望锚类别的所有产品都使用此

Mage::registry('current_category')->getProductCollection()->count()

例如,如果您想在/template/catalog/category/view.phtml的产品详情页面上显示产品数量,请使用此选项:

<?php if( $_category->getIsAnchor() ): ?>
    <span class="product-count" ><span class="count"><?php echo $_category->getProductCollection()->count(); ?></span> Artikel</span>
<?php else: ?>
    <span class="product-count" ><span class="count"><?php echo $_category->getProductCount(); ?></span> Artikel</span>
<?php endif; ?>

答案 1 :(得分:0)

getProductCount上的Mage_Catalog_Model_Category功能应该返回您所追求的信息。