// Filter Products by Product Type
if (!empty($product_type_id)) {
require_once (CLASSPATH."ps_product_type.php");
$ps_product_type = new ps_product_type();
// list parameters:
$q = "SELECT `parameter_name`, `parameter_type` FROM `#__{vm}_product_type_parameter` WHERE `product_type_id`='$product_type_id'";
$db_browse->query($q);
/*** GET ALL PUBLISHED PRODUCT WHICH MATCH PARAMETERS ***/
$join_array[] = "LEFT JOIN `#__{vm}_product_type_$product_type_id` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type_$product_type_id`.`product_id` ";
$join_array[] = "LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id` ";
$where_clause[] = "`#__{vm}_product_product_type_xref`.`product_type_id`=$product_type_id ";
// find by parameters
while ($db_browse->next_record()) {
$parameter_name = $db_browse->f("parameter_name");
$item_name = "product_type_$product_type_id"."_".$parameter_name;
$get_item_value = vmGet($_REQUEST, $item_name, "");
$get_item_value_comp = vmGet($_REQUEST, $item_name."_comp", "");
if (is_array($get_item_value) ? count($get_item_value) : strlen($get_item_value) ) {
// comparison
switch ($get_item_value_comp) {
case "lt": $comp = " < "; break;
case "le": $comp = " <= "; break;
case "eq": $comp = " <=> "; break;
case "ge": $comp = " >= "; break;
case "gt": $comp = " > "; break;
case "ne": $comp = " <> "; break;
case "texteq":
$comp = " <=> ";
break;
case "like":
$comp = " LIKE ";
$get_item_value = "%".$get_item_value."%";
break;
case "notlike":
$comp = "COALESCE(`".$parameter_name."` NOT LIKE '%".$get_item_value."%',1)";
$parameter_name = "";
$get_item_value = "";
break;
case "in": // Multiple section List of values
$comp = " IN ('".join("','",$get_item_value)."')";
$get_item_value = "";
break;
case "fulltext":
$comp = "MATCH (`".$parameter_name."`) AGAINST ";
$parameter_name = "";
$get_item_value = "('".$get_item_value."')";
break;
case "find_in_set":
$comp = "FIND_IN_SET('$get_item_value',REPLACE(`$parameter_name`,';',','))";
$parameter_name = "";
$get_item_value = "";
break;
case "find_in_set_all":
case "find_in_set_any":
$comp = array();
foreach($get_item_value as $value) {
array_push($comp,"FIND_IN_SET('$value',REPLACE(`$parameter_name`,';',','))");
}
$comp = "(" . join($get_item_value_comp == "find_in_set_all"?" AND ":" OR ", $comp) . ")";
$parameter_name = "";
$get_item_value = "";
break;
}
switch ($db_browse->f("parameter_type")) {
case "D": $get_item_value = "CAST('".$get_item_value."' AS DATETIME)"; break;
case "A": $get_item_value = "CAST('".$get_item_value."' AS DATE)"; break;
case "M": $get_item_value = "CAST('".$get_item_value."' AS TIME)"; break;
case "C": $get_item_value = "'".substr($get_item_value,0,1)."'"; break;
default:
if( strlen($get_item_value) ) $get_item_value = "'".$get_item_value."'";
}
if( !empty($parameter_name) ) $parameter_name = "`".$parameter_name."`";
$where_clause[] = $parameter_name.$comp.$get_item_value." ";
}
}
$item_name = "price";
$get_item_value = vmGet($_REQUEST, $item_name, "");
$get_item_value_comp = vmGet($_REQUEST, $item_name."_comp", "");
// search by price
if (!empty($get_item_value)) {
// comparison
switch ($get_item_value_comp) {
case "lt": $comp = " < "; break;
case "le": $comp = " <= "; break;
case "eq": $comp = " = "; break;
case "ge": $comp = " >= "; break;
case "gt": $comp = " > "; break;
case "ne": $comp = " <> "; break;
}
$where_clause[] = "( ISNULL(product_price) OR product_price".$comp.$get_item_value." ) ";
$auth = $_SESSION['auth'];
// get Shopper Group
$sgq = "( ISNULL(`#__{vm}_product_price`.`shopper_group_id`) OR `#__{vm}_product_price`.`shopper_group_id` IN (";
$comma="";
if ($auth["user_id"] != 0) { // find user's Shopper Group
$q2 = "SELECT `shopper_group_id` FROM `#__{vm}_shopper_vendor_xref` WHERE `user_id`='".$auth["user_id"]."'";
$db_browse->query($q2);
while ($db_browse->next_record()) {
$sgq .= $comma.$db_browse->f("shopper_group_id");
$comma=",";
}
}
// find default Shopper Groups
$q2 = "SELECT `shopper_group_id` FROM `#__{vm}_shopper_group` WHERE `default` = 1";
$db_browse->query($q2);
while ($db_browse->next_record()) {
$sgq .= $comma.$db_browse->f("shopper_group_id");
$comma=",";
}
$sgq .= "\n )) ";
$where_clause[] = $sgq;
}
}
// search by price functionality
global $mosConfig_absolute_path;
require_once($mosConfig_absolute_path.'/modules/mod_vm_cherry_picker/controller.php');
$chp=new chpController();
$w=$chp->getVMPriceQuery();
if($w)$where_clause[]=$w;
//////////////////////////////////
// ASSEMBLE THE QUERY
//////////////////////////////////