For some reason, using $collection->getLastPageNumber()
is returning the wrong number of pages.
For example:
$collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$collection->getSelect()->joinLeft(array('link_table' => 'catalog_product_super_link'),'link_table.product_id = e.entity_id',
array('product_id','parent_id')
);
$collection->getSelect()->group('link_table.parent_id');
I'm not quite sure what the issue might be. I'm using joinLeft and group on my collection, as seen above. As far as I can tell, it's the only thing 'out of the ordinary' that I'm doing.
When I debugged the query, it returned, for example, 625 rows. But, using a pagelimit of 10, and then calling getLastPageNumber()
returns a total of 325 pages, instead of 62 pages!
What might be causing such an issue?
EDIT: The query is:
SELECT
e
.*, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) ASvisibility
,link_table
.product_id
,link_table
.parent_id
,color_t1
.attribute_id
,color_t1
.value
,color_t1
.store_id
,at_stock_status
.stock_status
,price_index
.price
,price_index
.tax_class_id
,price_index
.final_price
, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) ASminimal_price
,price_index
.min_price
,price_index
.max_price
,price_index
.tier_price
FROMcatalog_product_entity
ASe
INNER JOINcatalog_product_entity_int
ASat_visibility_default
ON (at_visibility_default
.entity_id
=e
.entity_id
) AND (at_visibility_default
.attribute_id
= '102') ANDat_visibility_default
.store_id
= 0 LEFT JOINcatalog_product_entity_int
ASat_visibility
ON (at_visibility
.entity_id
=e
.entity_id
) AND (at_visibility
.attribute_id
= '102') AND (at_visibility
.store_id
= 1) LEFT JOINcatalog_product_super_link
ASlink_table
ON link_table.product_id = e.entity_id LEFT JOINcatalog_product_entity_int
AScolor_t1
ON color_t1.entity_id = e.entity_id AND color_t1.store_id = 0 AND color_t1.attribute_id = 92 LEFT JOINcataloginventory_stock_status
ASat_stock_status
ON (at_stock_status.product_id
=e.entity_id) AND (at_stock_status.stock_id=1) INNER JOINcatalog_product_index_price
ASprice_index
ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = '1' WHERE (IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) = '1') GROUP BYlink_table
.parent_id
,color_t1
.value
$collection->getSelect()->__toString();