Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
search-processor. processwire
<?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
You can’t perform that action at this time.