1

I have a custom module for ajax layered navigation with multiple filters which has a price slider. I don't want a price slider on the search result page.

my config.xml rewrites block like this

    <blocks>
        <catalog>
            <rewrite>
                <layer_state>Royal_Layerednav_Block_Catalog_Layer_State</layer_state>
                <layer_view>Royal_Layerednav_Block_Catalog_Layer_View</layer_view>
                <product_list_toolbar>Royal_Layerednav_Block_Catalog_Product_List_Toolbar</product_list_toolbar>
                <layer_filter_attribute>Royal_Layerednav_Block_Catalog_Layer_Filter_Attribute</layer_filter_attribute>
                <layer_filter_price>Royal_Layerednav_Block_Catalog_Layer_Filter_Price</layer_filter_price>
            </rewrite>
        </catalog>
        <catalogsearch>
            <rewrite>
                <layer_filter_attribute>Royal_Layerednav_Block_CatalogSearch_Layer_Filter_Attribute</layer_filter_attribute>
                <result>Royal_Layerednav_Block_CatalogSearch_Result</result>
            </rewrite>
        </catalogsearch>

without this price block overriden, everything works fine (ofcourse with no price slider). If I override Price Block Royal_Layerednav_Block_Catalog_Layer_Filter_Price, category listing page works fine, with price slider. But in catalog search page price slider is appearing with wrong values.

I admit that I did not design the Price block to collect prices in search result page. But I don't need to show a price filter on search page.

So My question is: Is there a way, that catalogsearch does not take my overriden price block, instead it should use the default Price block Mage_Catalog_Block_Layer_Filter_Price

I don't know what to do to accomplish this. Can anyone please help?

2

I don't know how your extension is built, so I cannot provide any code but here is an idea on wow you can do it.
In a search page this piece of code will return null always:

Mage::registry('current_category');

In a category page this will return a category instance. You can use this in your own block. So for each method you override you can do the followin check before doing something. Let's say your method is called doSomething(). In your block it could look like this:

public function doSomething($someParam) {
    if (!Mage::registry('current_category')){//not on category page
        //call the default behavior
        return parent::doSomething($someParam);
    }
    //your custom behavior here
}

You can even change the template that renders the block this way:

public function __construct()
{
    parent::__construct();
    //by default the template 'catalog/layer/filter.phtml' will be set
    if (Mage::registry('catalog_category')){//if category page
        //set your custom template with price slider.
        $this->setTemplate('custom/template/here.phtml');
    }
}
  • Actually the extension I used, renders the price slider in Price.php (Block) itself. So, I followed your idea to render it on a phtml, and now I also made some changes to Price.php, to get the correct minimum and maximum prices Woila! now price slider also works on search page. I'm lost with the changes I made. I'll present it as the answer soon. Thank you! – Shathish Jul 26 '13 at 8:17
  • so can't we use custom price block for catalog only and not for catalogsearch? – Shathish Jul 26 '13 at 8:19
  • You can use different block. Just override the method Mage_CatalogSearch_Block_Layer::_initBlocks(). That's how the search uses different blocks for attributes. – Marius Jul 26 '13 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.