Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Magento from caching query strings, such as limit param

The behavior

I what to display only 3 products per page. So in my catalog.xml I have

<action method="setDefaultGridPerPage"><limit>3</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>3</limit></action>

If I go to /category.html I will see only 3 products. It works, great!

But also I want to be able to show all products at once, so I add to the catalog.xml the following:

<action method="addPagerLimit"><mode>grid</mode><limit>999</limit></action>

Now, if I navigate to /category.html?limit=999 I can see all the categories products, as expected.

The problem:

When I come back to /category.html, with no limit params, it displays all the products instead of the 3 I wish it did. It happends because Magento caches the limit preference.

The question:

Is there a configuration that prevents magento from caching listing options?

Thank you in advance.

like image 249
Marcelo Avatar asked Dec 31 '25 17:12

Marcelo


1 Answers

In the toolbar block there is a method called disableParamsMemorizing. This should disable the storing of parameters in session.
Try to add this in the toolbar block.

<action method="disableParamsMemorizing" />

or you can override the Mage_Catalog_Block_Product_List class and make the getToolbarBlock method look like this:

public function getToolbarBlock()
{
    if ($blockName = $this->getToolbarBlockName()) {
        if ($block = $this->getLayout()->getBlock($blockName)) {
            $block->disableParamsMemorizing();
            return $block;
        }
    }
    $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
    $block->disableParamsMemorizing();
    return $block;
} 
like image 152
Marius Avatar answered Jan 05 '26 02:01

Marius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!