【问题标题】:Product count for anchored category in MagentoMagento 中锚定类别的产品数量
【发布时间】:2012-09-26 10:34:56
【问题描述】:

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

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

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
    )

....

【问题讨论】:

    标签: php magento


    【解决方案1】:

    如果您想要某个锚类别的所有产品,请使用此

    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; ?>
    

    【讨论】:

      【解决方案2】:

      Mage_Catalog_Model_Category 上的 getProductCount 函数应返回您所追求的信息。

      【讨论】:

      • getProductCount from Mage_Catalog_Model_Category 将对单个类别的产品进行计数,但我希望将子类别中的产品包含在产品计数中。
      • @user739696 伙计。可能您想深入了解后端的类别管理代码。您可以注意到,magento 显示了一个类别中的产品总数,其中还包括子产品。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多