Reputation: 158
I want a script or idea by which I can get product count for an anchored category.
I tried loadProductCount()
method from Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
class but it's not returning product count instead it returns an array. Please take a look on the array given below:
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
)
....
Upvotes: 0
Views: 975
Reputation: 121
If you want all the products for an anchor category use this
Mage::registry('current_category')->getProductCollection()->count()
If you for example want to show the product count on product listing page in /template/catalog/category/view.phtml
use this:
<?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; ?>
Upvotes: 2
Reputation: 6186
The getProductCount
function on Mage_Catalog_Model_Category
should return the information you are after.
Upvotes: 0