Question

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?

Was it helpful?

Solution

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');
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top