1
votes

Hi I have assign 12 product to category Phone(id=12), and

{{block type="catalog/product_list" category_id="12" template="catalog/product/list2.phtml"}}

in a CMS page, I have placed

<?php
$_productCollection=$this->getLoadedProductCollection();
echo $_productCollection->count()
?>

to list2.phtml

Why it get 9 instead of 12?

I set "Products per Page on Grid Default Value=9" in backend, is this affecting the result above, and how to fix it?

Thanks you

1
set a breakpoint in the _getProductCollection() method of the Mage_Catalog_Block_Product_List and debug using for instance xdebug with PDT . Note that it is VERY hard to do anything on Magento without a proper debugging environment.greg0ire
Thanks for the advice, sorry that Magento API is badCharles Yeung

1 Answers

2
votes

Instead of...

echo $_productCollection->count()

...try this method:

echo $_productCollection->getSize()

Internally getSize() uses getSelectCountSql() which takes the original select statement, strips off page limitations and queries the database directly. So it returns the correct answer even after the shorter, paginated, list has been loaded. Whereas count() returns the actual number of items in the loaded list.