Magento – Custom from-to price filter in layered navigation

javascriptlayered-navigationmagento-1.7

We try to create a custom from-to price filter on our Magento homepage.

We're using a Layered Navigation extension and we can't find a way to understand the price algorithm.

We have two static HTML select boxes. One for the from price and one for the to price. We combine the values from the selected options to one URL with jQuery.

But this unfortunately gives very strange results. Below some examples:

From 10 to 20 gives € 180 – € 200

From 20 to 30 gives € 570 – € 600

From 30 to 40 gives € 1160 – € 1200

How we can access the correct algorithm within our static select option values?

Please see our code below:

<form>

    <select class="price">
        <option value="1">0</option>
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
    </select>

    <select class="price">
        <option value="">no max</option>
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
    </select>

</form>

<a href="" id="search">Zoeken</a>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script type="text/javascript">
    $('#search').click(function (e) {

        e.preventDefault();

        var price = $('.price option:selected').map(function () {
            return this.value;
        }).get().join(',');

        window.location.href = '/category/filter/price/' + price;
    });
</script>

Best Answer

There 2 parts of the price filter in the layered navigation.

The first one is frontend, by default it is only list of ranges, but you can modify it to a dropdown, slider or from-to widget in the .phrml file.

The second part is the backend, that handles the price filer request and converts it to SQL query. To modify this part you need to rewrite class mage-catalog-model-layer-filer-price to accept values from the url and treat them as from-to boundaries and not as ranges.

Related Topic