1

when i start filtering the priceslider from the min price in which in my case is $0 the slider works fine but when i start filtering from max value (keeping the min value to 0 ) nothing changes but when adjust /increase the filter to a non zero value the max value limit is applied, even if i set some static min value like 1$ or 2$ slider works fine but not with zero value

this is my slider code (relevent code)

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
        $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
        $rate = round(Mage::helper('directory')->currencyConvert(1.0000, $baseCurrencyCode, $currentCurrencyCode),2);
        if($this->_currMaxPrice > 0){$Curmax = $this->_currMaxPrice;} else{$Curmax = $this->getMaxRangePrice; }
        if($this->_currMinPrice > 0){$Curmin = $this->_currMinPrice;} else{$Curmin = $this->getMinRangePrice;}
        $minRange = $this->getMinRangePrice();
        $maxRange = $this->getMaxRangePrice();
        $minRange = $minRange * $rate;
        $maxRange = $maxRange * $rate;
        if(!isset($_GET['rate'])) {
            $Curmax = $Curmax * $rate;
            $Curmin = $Curmin * $rate;}



<div id="slider-range"></div>

script file /slider

$jq( "#slider-range" ).slider({
    range: true,
    min: min,
    max: max,
    values: [ currentMinPrice, currentMaxPrice ],
    slide: function( event, ui ) {
        $jq( "#amount" ).val( currencies + ui.values[ 0 ] + " - "+ currencies + ui.values[ 1 ] );
        $jq('input[name="first_price"]').val(ui.values[0]);
        $jq('input[name="last_price"]').val(ui.values[1]);
    },
    stop: function( event, ui ) {
        var first =   ui.values[0];
        var  last =  ui.values[1];
         var baseUrl = '<?php echo $baseUrl; ?>'+'?rate='+rate+'&first='+first+'&last='+last+params;
             ajaxFilter(baseUrl);

    }
});

$jq( "#amount" ).val( currencies + $jq( "#slider-range" ).slider( "values", 0 ) +
    " - "+currencies + $jq( "#slider-range" ).slider( "values", 1 ) );
$jq('input[name="first_price"]').val($jq( "#slider-range" ).slider( "values", 0 ));
$jq('input[name="last_price"]').val($jq( "#slider-range" ).slider( "values", 1 ));   
  • I don't understand the question and what has it to do with the code? And what is the exact problem? – Fabian Blechschmidt Mar 13 '14 at 5:07
  • @FabianBlechschmidt what i ment to say is if my min price zero and i reduce the the max value the filter dont work still shows all the result – Vishwas Bhatnagar Mar 13 '14 at 5:32
  • And where does the filtering happen? Just a guess: You check if($minValue && $maxValue) and if $minValue == 0 this is false. – Fabian Blechschmidt Mar 13 '14 at 5:38
  • filtering on product page of the store !! sorry couldn’t get you what part of my code are you reffering – Vishwas Bhatnagar Mar 13 '14 at 5:50
  • You are talking about a layered navigation category page? Magento has no slider, so I don't know which code makes the filtering – Fabian Blechschmidt Mar 13 '14 at 5:51
1

Your problem is of course in the core code, and I just learned how the price slider works.

Your problem with the 0 lies here:

\Mage_Catalog_Model_Layer_Filter_Price::_validateFilter
protected function _validateFilter($filter)
{
    $filter = explode('-', $filter);
    if (count($filter) != 2) {
        return false;
    }
    foreach ($filter as $v) {
        if (($v !== '' && $v !== '0' && (float)$v <= 0) || is_infinite((float)$v)) {
            return false;
        }
    }

    return $filter;
}

This validation checks whether ALL filters are > 0, and if this is not the case the filter is ignored (I guess, no idea what happens if this method returns false, but makes sense), so you should have at least 0.01$ or 1$ as bottom limit.

  • thanks for pointing out the problem !! but is there any workaround rather than setting default values ?? cos i tried manipulating that loop still no change – Vishwas Bhatnagar Mar 13 '14 at 6:51
  • Check what your slider submits and I think if you (for debugging) remove the && $v !== '0' && (float)$v <= 0) it should work. But maybe are more checks deeper. Didn't check. Happy digging! – Fabian Blechschmidt Mar 13 '14 at 6:52
  • Fixed the code if ($fisrt && $last) { $collection ->addFieldToFilter('price', array('gteq' => $fisrt)) ->addFieldToFilter('price', array('lteq' => $last)); } replaced and with a or in layer.php ! thanks mate for your help – Vishwas Bhatnagar Mar 13 '14 at 9:51
  • you should NEVER hack the code. at least copy the file to app/code/local/core/... but better rewrite the class and change the method – Fabian Blechschmidt Mar 13 '14 at 11:03
  • it was a custom theam option so core file altered ! – Vishwas Bhatnagar Mar 13 '14 at 13:08

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.