All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Range filter gives unexpected results when targeting a CartThrob Price field

sajwal 25 Nov 2014 23:35 problem, complete

I just noticed a bug , thought to share so it might help all :

ISSUE : using query strings with low search filters not giving accurate range results

I fixed it by converting the 'from' and 'to' parameters to int value

Changes done as below :

filename : low_search > filters > ranges > lsf.ranges

Somewhere around line 195 :

CHANGE FROM : (LINE 195)


// Limit by Greater Than option
if (isset($range['from']))
{

$gt = ($exclude || $this->params->in_param("range-from:{$field}", 'exclude'))
? ' >'
: ' >=';

ee()->db->where($sql_field.$gt, $range['from']);
}
<code>

CHANGE TO :

<code>
// Limit by Greater Than option
if (isset($range['from']))
{
$range['from'] = intval($range['from']);
$gt = ($exclude || $this->params->in_param("range-from:{$field}", 'exclude'))
? ' >'
: ' >=';

ee()->db->where($sql_field.$gt, $range['from']);
}


and

CHANGE FROM : (LINE 206)



// Limit by Lesser Than option
if (isset($range['to']))
{

$lt = ($exclude || $this->params->in_param("range-to:{$field}", 'exclude'))
? ' <'
: ' <=';

ee()->db->where($sql_field.$lt, $range['to']);
}



TO

// Limit by Lesser Than option
if (isset($range['to']))
{
$range['to'] = intval($range['to']);
$lt = ($exclude || $this->params->in_param("range-to:{$field}", 'exclude'))
? ' <'
: ' <=';

ee()->db->where($sql_field.$lt, $range['to']);
}

Replies

  1. Low 26 Nov 2014 08:31

    Hmm, what search query was giving you the incorrect results? Numeric strings should work just fine.

    Your solution won't work for floating point numerical values.

  2. sajwal 26 Nov 2014 10:34

    My Numeric search wasn't working till i implemented this fix....

    I am using query strings in url .... and i found that the entries were not returned corrected after the query..

    You are correct for floating we can change the variables gt and lt values to float i guess... but my requirement was for integers :) i dont know why it didnt return good results...i think its something to do with my server (nginx) responding to query strings or something?

    I am just a noob.

  3. Low 26 Nov 2014 10:51

    But what search query was giving you the incorrect results

  4. sajwal 26 Nov 2014 11:34

    {exp:low_search:results query="{segment_3}" limit="40"
    collection="products"
    paginate="both"
    range:product_price="200|800"
    }
    {title} - eid {entry_id}<br>
    price : {product_price}<br>
    weight : {weight}<br>

    {if no_results}No Results{/if}
    {/exp:low_search:results}


    I was getting results for products more than 800 or even lesser than 200 ... i dont know why...i tried with hard coded url too.

  5. Low 26 Nov 2014 12:01

    Are you sure the product_price field has 'Field Content' settings set to anything

  6. sajwal 27 Nov 2014 19:30

    Well a CT field simple price fieldtype does not have these settings...but based on your answer i found one gap that helped....

    I checked my db tables and found that particularly that field_id_X was set to "char" type when it should be float as seen for any other price fields set by CT.

    I think that was the issue here.....

    I wish i could change the subject line of this post !!!

    something to do with CT i guess...

  7. Low 28 Nov 2014 08:38

    Yep, if it's a fieldtype by CT, then the price field should be a decimal type, not a char. Then ranges should work just fine. I changed the subject title to reflect this.