Reputation: 509
I have an extension that uses the products list block to show the products grid filter by an attribute (the extension is Attribute Info Pages).
In the "_prepareLayout" function of this extension block the extension sets the page's title and description using this code :
$head = $this->getLayout()->getBlock('head');
.
.
.
$head->setTitle($title);
head->setDescription($des);
I want to add text to the title and description in this format :
$page_info = "Page A of B for ";
$title = $page_info . title;
$items_info = "Listings X-Y (out of Z) ";
$des = items_info . $des;
I've tried this code it order to get the current page, last page, number and items and so on :
$html_pager = Mage::getBlockSingleton('page/html_pager');
$html_pager->setCollection($product_collection);
$limit = Mage::getSingleton('core/app')->getRequest()->getParam('limit');
if(empty($limit))
{
$limit = 8;
}
$html_pager->setLimit($limit);
$LastPageNumber = $html_pager->getLastPageNum();
$current_page = $html_pager->getCurrentPage();
$page_info = "";
if($current_page > 1)
{
$page_info = "Page " . $current_page . " of $LastPageNumber for ";
}
$FirstNum = $html_pager->getFirstNum();
$LastNum = $html_pager->getLastNum();
$TotalNum = $html_pager->getTotalNum();
$items_info = "Listings " . $FirstNum . "-" . $LastNum . " (out of ". $TotalNum . ") ";
The code gives me the correct information but it causes a problem in the products grid - it always shows 10 products in the products grid (no matter what I choose in "Show per page").
Any ideas how to get the information without breaking the grid functionality?
Upvotes: 1
Views: 5622
Reputation: 150
$pager = Mage::getBlockSingleton('page/html_pager');
$productCollection = Mage::getSingleton('catalog/layer')->getProductCollection();
$pager->setCollection($productCollection);
After that, you have got all the block's method available (Mage_Page_Block_Html_Pager) :
$pager->getCurrentPage();
$pager->getLastPageNum();
Upvotes: 0
Reputation: 509
I found a solution that works for me:
$product_collection = clone Mage::getSingleton('catalog/layer')->getProductCollection();
$total = count($product_collection);
$current_page = Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
$limit = Mage::getSingleton('core/app')->getRequest()->getParam('limit');
if(empty($limit))
{
$limit = Mage::getStoreConfig('catalog/frontend/grid_per_page');
}
$pages = $total / $limit;
$pages = ceil($pages);
if($current_page > 1)
{
$page_info = "Page " . $current_page . " of $pages for ";
}
$FirstNum = $limit*($current_page-1)+1;
if($current_page == $pages)
{
$LastNum = $total;
}
else
{
$LastNum = $limit + ($FirstNum - 1);
}
$items_info = "Listings " . $FirstNum . "-" . $LastNum . " (out of ". $total . ") ";
Upvotes: 6