Coroico / AdvSearch

Dynamic content search add-on for MODx Revolution that supports results highlighting, faceted search and search in custom packages
21 stars 14 forks source link

Filter Price ranges! How can i do it? #46

Open NunoBentes opened 11 years ago

NunoBentes commented 11 years ago

Hi guys

I´m building a filter form with Advsearch plugin, but now i´m having some troubles in filtering prices. How can i put this working? I tried, but it´s not working!! This is not an issue for sure, it´s something that i´m not doing well and because of that isn´t working!! :)

Many thanks in advance, Legues

The form part is this one:

``

Then i tried a queryhook like this one:

 * AdvSearch
 *
 * Copyright 2012 by Coroico <coroico@wangba.fr>
 *
 * QueryHook for Faceted search demo 1
 *
 */

$andConditions = array(
    'tv.property-type:=' => 'type:request:all',
    'tv.property-number-bedrooms:=' => 'bedrooms:request:all',
    'tv.property-location:=' => 'location:request:all'
);

$requests = array();

// price
$tag = 'pricerange';
$pricerange = strip_tags($_GET[$tag]);
if (!empty($pricerange)) {
    $vpricerange = substr($pricerange,0,-1); // to clear the money unit
    if ($vpricerange == '>2,000,000') {
        $andConditions['tv.property-price:>'] = '2,000,000:numfield';
    }
    else {
        list($pinf,$psup) = explode('-',$vpricerange);
        $andConditions['tv.property-price:>='] = $pinf.':numfield';
        $andConditions['tv.property-price:<='] = $psup.':numfield';
    }

    // propagate the http request variable for pagination
    $requests['pricerange'] = $pricerange;
};

$qhDeclaration = array(
    'qhVersion' => '1.2',
    'andConditions' => $andConditions,
    'requests' => $requests
);

$hook->setQueryHook($qhDeclaration);
return true;```