unfortunately it doesn't work because in the _getProductCollection()
method the Collection has been already initialized with a page size.
A more flexible solution could be that of observing the catalog_product_collection_load_before
event which, as the name suggests, is dispatched before the collection is loaded.
Here follows an example (assuming to write a yourmodule
extension under yourpackage
):
STEP 1: Define your observer in config.xml
in the global
section of your config.xml
extension file insert something like:
<events>
<catalog_product_collection_load_before>
<observers>
<yourpackage_yourmodule_catalog_observer>
<type>singleton</type>
<class>yourpackage_yourmodule/catalog_observer</class>
<method>limitPageSize</method>
</yourpackage_yourmodule_catalog_observer>
</observers>
</catalog_product_collection_load_before>
</events>
STEP 2: Define your Observer class under the Model\Catalog
folder:
<?php
class Yourpackage_Yourmodule_Model_Catalog_Observer
{
public function limitPageSize($observer)
{
#TODO: Insert the logic you need to differentiate when to apply the following
$event = $observer->getEvent();
$collection = $event->getCollection();
$collection->setPageSize(3);
return $this;
}
}
Hope it helps.
Sincerely,
Alessandro Ronchi