2

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>
1

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.

0

I think the price should be a range so when you want price range 10 to 20 your url should look as follows:

/category/filter/price/10-20

Or you can pass the price filter via get ?price=10-20

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.