You can achieve this in many ways. I will show you two ways how you can achieve this.
Via Layout Updation
I think this is the fastest and cleanest way to achieve this. You need to set page size for individual cateogories. For each category, Magento generates a unique layout handle. It looks like CATEGORY_{id}
(where id stands for category id).
With that in mind, suppose you want to change page size of category with id 13 to 15 and category with id 7 to 30. For this layout updation file looks like this.
File :app/design/frontend/<your_package>/<your_theme>/layout/local.xml
<layout>
<CATEGORY_13>
<reference name="product_list_toolbar">
<action method="addPagerLimit"><mode>grid</mode><limit>15</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>15</limit></action>
</reference>
</CATEGORY_13>
<CATEGORY_7>
<reference name="product_list_toolbar">
<action method="addPagerLimit"><mode>grid</mode><limit>30</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>30</limit></action>
</reference>
</CATEGORY_7>
</layout>
You are done. If you now load those category pages, you can see that their page size get changed. You can refer my answer on this thread for more details.
Programmatic Way
We are going to do exactly same thing that we do through layout updation here. For this first we need to observe the event controller_action_layout_generate_blocks_after
. This event is a perfect place to observe, since it will allow us to change any block properties. That is what we need to do here. (Basically if you look the code above, we are actually change a property of a block with name product_list_toolbar
). So our observer class should looks like this
<?php
class Namepace_Modulename_Model_Observer {
/**
*
* Holds Categoy ids
*
* @var array
*
*/
protected $_categoryIds = array(13,7) ;
/**
*
* Holds page Sizes
*
* @var array
*
*/
protected $_pageSize = array(
13 => 15
7 => 30
) ;
/**
*
* Use to set Page Size
*
* @param Varint Object | $observer
*
*
*/
public function setPageSizeForCategory($observer)
{
$controller = $observer->getAction();
$fullActionName = $controller->getFullActionName();
$id = (int)$controller->getRequest()->getParam('id');
//check whether current page is correspond to our special category. If not, returns
if ($fullActionName == "catalog_category_view" && $id == in_array($this->_categoryIds)) {
//check whether toolbar block exist or not
$toolbar = $controller->getLayout()->getBlock('product_list_toolbar');
if($toolbar) {
//sets page size to corresponding mode
$listMode = $toolbar->getCurrentMode();
$toolbar = $toolbar->addPagerLimit($listMode , $this->_pageSize[$id]);
}
}
return;
}
}
For more details, you can refer my blog post
Hope that helps