Magento – Layered Navigation Price Range input form

filterlayered-navigationprice

Is it possible to make a form that allows the user to input to and from price range rather than calculating specific price ranges?

A lot of eCommerce websites are using this including eBay itself, so I'm curious if they plan to make that in the future, and if not, does the layered navigation accept custom values if I were to implement a form?

Best Answer

to filter on a specific price range your category url looks something like http://domain.com/categoryurl?price=65-200. To accomplish this I would suggest creating a new template file that has a form with a minimal and maximal price input with a submit button that when clicked will create an url like previously mentioned.

Here is some untested code that might help you along.

In your local.xml add the following to add a new block under the left layered navigation.

<catalog_category_layered>
    <reference name="left">
        <block type="core/template" name="pricefilter" after="-" template="catalog/layer/pricefilter.phtml"/>
    </reference>
</catalog_category_layered>

The pricefilter.phtml would look something like this

<?php echo $this->__('From');?>: <input type="text" name="minvalue" id="pricefilter-minvalue" value=""/><br/>
<?php echo $this->__('To');?>: <input type="text" name="maxvalue" id="pricefilter-maxvalue" value=""/><br/>
<a href="#" id="pricefilter-submit"><?php echo $this->__('Filter');?></a>

<script type="text/javascript">
$('pricefilter-submit').observe('click',function(){
    var minvalue = $('pricefilter-minvalue').value;
    var maxvalue = $('pricefilter-maxvalue').value;

    var dest = window.location.href;
    dest += (window.location.href.indexOf('?') != -1) ? '&' : '?' ;
    dest += 'price=' + minvalue + '-' + maxvalue;

    window.location = dest;
});

Related Topic