Reputation: 21
First of all, i didn't create custom module to handle this product collection, so, i just put model inside phtml file, i know it's bad implementation, i'm new in magento and i have to do small customization in loading product collection to the extension that bought by client.
This product collection is only showing up in specific category, so inside custom design tab in category management, i put this code :
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/list_all.phtml</template></action>
And here is my query to load product collection, this query is inside list_all.phtml file :
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addStoreFilter()
->addUrlRewrite()
->addAttributeToFilter('groupdeal_status', Devinc_Groupdeals_Model_Source_Status::STATUS_RUNNING)
->joinField('groupdeals_id','groupdeals/groupdeals','groupdeals_id','product_id=entity_id',null,'left');
$collection->getSelect()->limit(2);
i've used this code to generate the pagination :
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($collection);
echo $toolbar->toHtml();
the code above only showing the products count and show per-page options, not 1,2,3..., links, i've also tried to use the code below :
<?php
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($collection);
echo $toolbar->getCollection()->getSize().'------'.var_dump($toolbar->getPages());
?>
but, the var_dump returning NULL values. Should i create custom module to do this? or is there any ways to do this way, without creating custom module??
Upvotes: 2
Views: 3553
Reputation: 420
Try adding setCurPage()
to your collection filters, then update it based on URL parameters via $_GET
when needed:
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addStoreFilter()
->addUrlRewrite()
->addAttributeToFilter('groupdeal_status', Devinc_Groupdeals_Model_Source_Status::STATUS_RUNNING)
-> joinField('groupdeals_id','groupdeals/groupdeals','groupdeals_id','product_id=entity_id',null,'left');
$collection->getSelect()->limit(2)->setCurPage(1);
if ($_GET["p"] <= $_productCollection->getLastPageNumber()){
$_productCollection->setCurPage($_GET["p"]);
}
Upvotes: 1