0

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

我尝试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
    )

……

4

2 回答 2

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; ?>
于 2015-08-24T18:29:43.043 回答
0

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

于 2012-09-26T10:48:32.220 回答