Created
June 1, 2013 13:42
-
-
Save outflux3/5690429 to your computer and use it in GitHub Desktop.
search-processor. processwire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// check if there are GET variables present in the URL | |
if(count($input->get)) { | |
$selector = ''; | |
if($input->get->application) { | |
$application = $sanitizer->pageName($input->get->application); | |
$appid = $pages->get("template=product-options, name=$application"); | |
$parents = $pages->find("product_app_select=$appid"); | |
$selector .= "parent=$parents, "; | |
} | |
// if a use is specified, then we limit the results to having that use as their parent | |
if($input->get->product_use) { | |
$use= $pages->get("/speakers/" . $sanitizer->pageName($input->get->product_use)); | |
if($use->id) { | |
$use = $use->children; | |
$selector .= "parent="; | |
foreach($use as $u) { | |
$selector .= "|$u"; | |
$input->whitelist('use', $u->name); | |
} | |
$selector .= ", "; | |
} | |
} | |
if($input->get->length) { | |
$length = (int) $input->get->length; | |
} | |
if($input->get->width) { | |
$width = (int) $input->get->width; | |
} | |
if($input->get->height) { | |
$height = (int) $input->get->height; | |
} | |
if($input->get->width && $input->get->length && $input->get->height) { | |
$roomcf = $width * $length * $height; | |
$s_selector .= "roomsize_min<=$roomcf, roomsize_max>=$roomcf, "; | |
} | |
if($input->get->price) { | |
$price = $sanitizer->selectorValue($input->get->price); | |
$selector .= "product_price<=$price, "; | |
} | |
if($input->get->distance) { | |
$distance = $sanitizer->selectorValue($input->get->distance); | |
$selector .= "speaker_distance>=$distance, "; | |
} | |
if($input->get->series) { | |
$series = $sanitizer->selectorValue($input->get->series); | |
$selector .= "product_series=$series, "; | |
} | |
if($input->get->name) { | |
$name = $sanitizer->selectorValue($input->get->name); | |
$selector .= "product_name%=$name, "; | |
} | |
$out = ''; | |
$selector .= "template=product-child, "; | |
$matches = $pages->find("$selector, $s_selector, sort=product_price, limit=150"); | |
if($input->get->width && $input->get->length && $input->get->height) { | |
$s_matches = $pages->find("$selector, roomsize_min=, roomsize_max="); | |
$matches->import($s_matches)->sort('product_price'); | |
} | |
$count = count($matches); | |
if($count) { | |
$out .= "<h3 class='res-count'>Found $count products matching your search:</h3>"; | |
} else { | |
$out .= "<h3>Sorry, no products were found that match.</h3>"; | |
} | |
} else { | |
$out .= "<h3>Please select one or more options to return results.</h3>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment