Ejemplo n.º 1
0
 public function SetPanelSettings()
 {
     $count = 0;
     $GLOBALS['SNIPPETS']['HomeSaleProducts'] = '';
     if (GetConfig('HomeNewProducts') == 0) {
         $this->DontDisplay = true;
         return;
     }
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid)\n\t\t\t\tWHERE p.prodsaleprice != 0 AND p.prodsaleprice < p.prodprice AND p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))\n\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\tORDER BY RAND()\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, GetConfig('HomeNewProducts'));
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         $GLOBALS['ProductId'] = $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         // Determine the price of this product
         $originalPrice = CalcRealPrice(CalcProdCustomerGroupPrice($row, $row['prodprice']), 0, 0, $row['prodistaxable']);
         $GLOBALS['OriginalProductPrice'] = CurrencyConvertFormatPrice($originalPrice);
         $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         // Workout the product description
         $desc = strip_tags($row['proddesc']);
         if (isc_strlen($desc) < 120) {
             $GLOBALS['ProductSummary'] = $desc;
         } else {
             $GLOBALS['ProductSummary'] = isc_substr($desc, 0, 120) . "...";
         }
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         $GLOBALS['SNIPPETS']['HomeSaleProducts'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("HomeSaleProductsItem");
         if (!$GLOBALS['SNIPPETS']['HomeSaleProducts']) {
             $this->DontDisplay = true;
             return;
         }
     }
 }
Ejemplo n.º 2
0
 public function SetPanelSettings()
 {
     $GLOBALS['AlsoBoughtProductListing'] = '';
     $query = "\n\t\t\tSELECT ordprodid\n\t\t\tFROM [|PREFIX|]order_products\n\t\t\tWHERE orderorderid IN (SELECT orderorderid FROM [|PREFIX|]order_products WHERE ordprodid='" . $GLOBALS['ISC_CLASS_PRODUCT']->GetProductId() . "') AND ordprodid != " . $GLOBALS['ISC_CLASS_PRODUCT']->GetProductId() . "\n\t\t\tGROUP BY ordprodid\n\t\t\tORDER BY COUNT(ordprodid) DESC\n\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 10);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $productIds = array();
     while ($product = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $productIds[] = $product['ordprodid'];
     }
     if (empty($productIds)) {
         $this->DontDisplay = true;
         return;
     }
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     $query = "\n\t\t\tSELECT p.*, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating, i.imagefile, i.imageisthumb, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\tFROM [|PREFIX|]products p\n\t\t\tLEFT JOIN [|PREFIX|]product_images i ON (p.productid = i.imageprodid AND i.imageisthumb=1)\n\t\t\tWHERE p.prodvisible='1' AND p.productid IN (" . implode(',', $productIds) . ")\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t";
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         $GLOBALS['ProductId'] = (int) $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         $GLOBALS['AlsoBoughtProductListing'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideProductAlsoBoughtItem");
     }
     if (!$GLOBALS['AlsoBoughtProductListing']) {
         $this->DontDisplay = true;
     }
 }
Ejemplo n.º 3
0
 public function SetPanelSettings()
 {
     if ($GLOBALS['ISC_CLASS_PRODUCT']->GetRelatedProducts() != "") {
         $output = "";
         if (GetConfig('EnableProductReviews') == 0) {
             $GLOBALS['HideProductRating'] = "display: none";
         }
         $query = "\n\t\t\t\t\tSELECT p.*, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating, i.imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\t\tLEFT JOIN [|PREFIX|]product_images i ON (p.productid = i.imageprodid)\n\t\t\t\t\tWHERE p.prodvisible='1' AND p.productid IN (" . $GLOBALS['ISC_CLASS_PRODUCT']->GetRelatedProducts() . ") AND i.imageisthumb=1\n\t\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\t\tORDER BY prodsortorder ASC\n\t\t\t\t";
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         if ($GLOBALS['ISC_CLASS_DB']->CountResult($result) > 0) {
             $GLOBALS['AlternateClass'] = '';
             while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
                 if ($GLOBALS['AlternateClass'] == 'Odd') {
                     $GLOBALS['AlternateClass'] = 'Even';
                 } else {
                     $GLOBALS['AlternateClass'] = 'Odd';
                 }
                 $GLOBALS['ProductCartQuantity'] = '';
                 if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
                     $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
                 }
                 $GLOBALS['ProductId'] = (int) $row['productid'];
                 $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
                 $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
                 // Determine the price of this product
                 $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
                 $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
                 $thumb = $GLOBALS['ShopPath'] . "/" . GetConfig('ImageDirectory') . "/" . isc_html_escape($row['imagefile']);
                 $GLOBALS['ProductThumb'] = '<img src="' . $thumb . '" alt="" />';
                 $output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideRelatedProducts");
             }
             $GLOBALS['SNIPPETS']['SideProductsRelated'] = $output;
         } else {
             // No related products, hide the panel
             $GLOBALS['HideRelatedProductsPanel'] = "none";
             $this->DontDisplay = true;
         }
     } else {
         // No related products, hide the panel
         $GLOBALS['HideRelatedProductsPanel'] = "none";
         $this->DontDisplay = true;
     }
 }
Ejemplo n.º 4
0
 public function SetPanelSettings()
 {
     $output = "";
     // If product ratings aren't enabled then we don't even need to load anything here
     if (GetConfig('EnableProductReviews') == 0) {
         $this->DontDisplay = true;
         return;
     }
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)\n\t\t\t\tWHERE prodvisible='1' AND prodratingtotal > 0\n\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\tORDER BY prodavgrating DESC\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 5);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     if ($GLOBALS['ISC_CLASS_DB']->CountResult($result) > 0) {
         $GLOBALS['AlternateClass'] = '';
         while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
             if ($GLOBALS['AlternateClass'] == 'Odd') {
                 $GLOBALS['AlternateClass'] = 'Even';
             } else {
                 $GLOBALS['AlternateClass'] = 'Odd';
             }
             $GLOBALS['ProductCartQuantity'] = '';
             if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
                 $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
             }
             $GLOBALS['ProductId'] = $row['productid'];
             $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
             $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
             $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
             // Determine the price of this product
             $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
             $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
             $output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SidePopularProducts");
         }
         // Showing the syndication option?
         if (GetConfig('RSSPopularProducts') != 0 && GetConfig('RSSSyndicationIcons') != 0) {
             $GLOBALS['SNIPPETS']['SidePopularProductsFeed'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SidePopularProductsFeed");
         }
     } else {
         $GLOBALS['HideSidePopularProductsPanel'] = "none";
         $this->DontDisplay = true;
     }
     $GLOBALS['SNIPPETS']['SidePopularProducts'] = $output;
 }
Ejemplo n.º 5
0
 public function SetPanelSettings()
 {
     $count = 0;
     $output = "";
     $GLOBALS['SNIPPETS']['HomeNewProducts'] = '';
     if (GetConfig('HomeNewProducts') > 0) {
         if (GetConfig('EnableProductReviews') == 0) {
             $GLOBALS['HideProductRating'] = "display: none";
         }
         $query = "\n\t\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid)\n\t\t\t\t\tWHERE p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))\n\t\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\t\tORDER BY proddateadded DESC\n\t\t\t\t";
         $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, GetConfig('HomeNewProducts'));
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         if ($GLOBALS['ISC_CLASS_DB']->CountResult($result) > 0) {
             $GLOBALS['AlternateClass'] = '';
             while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
                 if ($GLOBALS['AlternateClass'] == 'Odd') {
                     $GLOBALS['AlternateClass'] = 'Even';
                 } else {
                     $GLOBALS['AlternateClass'] = 'Odd';
                 }
                 $GLOBALS['ProductCartQuantity'] = '';
                 if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
                     $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
                 }
                 $GLOBALS['ProductId'] = $row['productid'];
                 $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
                 $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
                 $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
                 // Determine the price of this product
                 $GLOBALS['ProductPrice'] = CalculateProductPrice_retail($row);
                 // Workout the product description
                 $desc = strip_tags($row['proddesc']);
                 if (strlen($desc) < 120) {
                     $GLOBALS['ProductSummary'] = $desc;
                 } else {
                     $GLOBALS['ProductSummary'] = substr($desc, 0, 120) . "...";
                 }
                 $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
                 if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
                     $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
                     $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
                 } else {
                     //$GLOBALS['ProductURL'] = CartLink($row['productid']);
                     $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
                     //blessen
                     if (intval($row['prodretailprice']) <= 0) {
                         $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
                     } else {
                         $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink1');
                     }
                     //blessen
                     // original$GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
                 }
                 if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
                     $GLOBALS['HideActionAdd'] = '';
                 } else {
                     $GLOBALS['HideActionAdd'] = 'none';
                 }
                 $GLOBALS['HideProductVendorName'] = 'display: none';
                 $GLOBALS['ProductVendor'] = '';
                 if (GetConfig('ShowProductVendorNames') && $row['prodvendorid'] > 0) {
                     $vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
                     if (isset($vendorCache[$row['prodvendorid']])) {
                         $GLOBALS['ProductVendor'] = '<a href="' . VendorLink($vendorCache[$row['prodvendorid']]) . '">' . isc_html_escape($vendorCache[$row['prodvendorid']]['vendorname']) . '</a>';
                         $GLOBALS['HideProductVendorName'] = '';
                     }
                 }
                 $GLOBALS['SNIPPETS']['HomeNewProducts'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("HomeNewProductsItem");
             }
             // Showing the syndication option?
             if (GetConfig('RSSNewProducts') != 0 && GetConfig('RSSSyndicationIcons') != 0) {
                 $GLOBALS['SNIPPETS']['HomeNewProductsFeed'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("HomeNewProductsFeed");
             }
         } else {
             $this->DontDisplay = true;
             $GLOBALS['HideHomeNewProductsPanel'] = "none";
         }
     } else {
         $this->DontDisplay = true;
         $GLOBALS['HideHomeNewProductsPanel'] = "none";
     }
 }
 function GetWhereBySearchItems(&$outer_condition = "", &$havingquery = array())
 {
     $qualifier_flag = 0;
     $searchTerms = $this->_searchterms;
     $queryWhere = array();
     $queryWhere1 = array();
     $queryWhere1[] = $queryWhere[] = "p.prodvisible='1'";
     //return $queryWhere1;
     // Add in the group category restrictions
     $permissionSql = GetProdCustomerGroupPermissionsSQL(null, false);
     if ($permissionSql && !empty($permissionSql)) {
         $queryWhere1[] = $queryWhere[] = $permissionSql;
     }
     // Do we need to filter on brand?
     if (isset($searchTerms['brand']) && $searchTerms['brand'] != "") {
         $brand_query = "select brandid from [|PREFIX|]brands WHERE brandname='" . $searchTerms['brand'] . "'";
         $brand_result = $GLOBALS['ISC_CLASS_DB']->Query($brand_query);
         $brandId = $GLOBALS['ISC_CLASS_DB']->FetchOne($brand_result);
         if ((int) $brandId > 0) {
             $qualifier_flag = 1;
             $queryWhere1[] = $queryWhere[] = "p.prodbrandid='" . $GLOBALS['ISC_CLASS_DB']->Quote($brandId) . "'";
         }
     }
     // Do we need to filter on brand series?
     if (isset($searchTerms['series']) && $searchTerms['series'] != "") {
         $qualifier_flag = 1;
         if (isset($GLOBALS['seriesid'])) {
             $brand_series_id = (int) $GLOBALS['seriesid'];
         } else {
             $series_qry = "select s.seriesid from isc_brand_series s where s.seriesname = '" . $searchTerms['series'] . "' ";
             $series_res = $GLOBALS['ISC_CLASS_DB']->Query($series_qry);
             $series_arr = $GLOBALS['ISC_CLASS_DB']->Fetch($series_res);
             $brand_series_id = (int) $series_arr['seriesid'];
         }
         $queryWhere1[] = $queryWhere[] = " p.brandseriesid = " . $GLOBALS['ISC_CLASS_DB']->Quote($brand_series_id);
     }
     if (isset($searchTerms['partnumber'])) {
         $qualifier_flag = 1;
         $prod_code = $searchTerms['partnumber'];
         $queryWhere1[] = $queryWhere[] = " p.prodcode like '" . $prod_code . "%'";
     }
     // Do we need to filter on price?
     if (isset($searchTerms['price'])) {
         $queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice='" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price']) . "'";
     } else {
         /*if (isset($searchTerms['price_from']) && is_numeric($searchTerms['price_from'])) {
         			 $queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice >= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_from'])."'";
         			 }
         
         			 if (isset($searchTerms['price_to']) && is_numeric($searchTerms['price_to'])) {
         			 $queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice <= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_to'])."'";
         			 }*/
     }
     // Do we need to filter on rating?
     if (isset($searchTerms['rating'])) {
         $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) = '" . (int) $searchTerms['rating'] . "'";
     } else {
         if (isset($searchTerms['rating_from']) && is_numeric($searchTerms['rating_from'])) {
             $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) >= '" . (int) $searchTerms['rating_from'] . "'";
         }
         if (isset($searchTerms['rating_to']) && is_numeric($searchTerms['rating_to'])) {
             $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) <= '" . (int) $searchTerms['rating_to'] . "'";
         }
     }
     // Do we need to filter on featured?
     if (isset($searchTerms['featured']) && $searchTerms['featured'] != "") {
         $featured = (int) $searchTerms['featured'];
         if ($featured == 1) {
             $queryWhere1[] = $queryWhere[] = "p.prodfeatured=1";
         } else {
             $queryWhere1[] = $queryWhere[] = "p.prodfeatured=0";
         }
     }
     // Do we need to filter on free shipping?
     if (isset($searchTerms['shipping']) && $searchTerms['shipping'] != "") {
         $shipping = (int) $searchTerms['shipping'];
         if ($shipping == 1) {
             $queryWhere1[] = $queryWhere[] = "p.prodfreeshipping='1' ";
         } else {
             $queryWhere1[] = $queryWhere[] = "p.prodfreeshipping='0' ";
         }
     }
     // Do we need to filter only products we have in stock?
     if (isset($searchTerms['instock']) && $searchTerms['instock'] != "") {
         $stock = (int) $searchTerms['instock'];
         if ($stock == 1) {
             $queryWhere1[] = $queryWhere[] = "(p.prodcurrentinv>0 or p.prodinvtrack=0) ";
         }
     }
     // Do we need to filter for make of the product
     if (isset($searchTerms['make']) && $searchTerms['make'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
         $make = $searchTerms['make'];
         if (!empty($make)) {
             $qualifier_flag = 1;
             $ext = "";
             //if(isset($searchTerms['is_catg']))
             $ext .= " OR v.prodmake = 'NON-SPEC VEHICLE' ";
             $queryWhere[] = " ( v.prodmake = '" . $make . "' {$ext} ) ";
             $queryWhere1[] = " ( v.prodmake = '" . $make . "' {$ext} ) ";
         }
     }
     // Do we need to filter for model of the product
     if (isset($searchTerms['model']) && $searchTerms['model'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
         $model = $searchTerms['model'];
         if (!empty($model)) {
             $qualifier_flag = 1;
             $ext = "";
             //if(isset($searchTerms['is_catg']))
             $ext .= " OR v.prodmodel = 'ALL' ";
             //if(isset($_REQUEST['model'])) {
             if (!isset($searchTerms['model_flag']) || isset($searchTerms['model_flag']) && $searchTerms['model_flag'] == 1) {
                 $queryWhere[] = " ( v.prodmodel = '" . $model . "' {$ext} ) ";
                 $queryWhere1[] = " ( v.prodmodel = '" . $model . "' {$ext} ) ";
             } else {
                 $queryWhere[] = " ( v.prodmodel like '" . $model . "%' {$ext} ) ";
                 $queryWhere1[] = " ( v.prodmodel like '" . $model . "%' {$ext} ) ";
             }
         }
     }
     // Do we need to filter for submodel of the product
     if (isset($searchTerms['submodel']) && $searchTerms['submodel'] != "") {
         $submodel = $searchTerms['submodel'];
         if (!empty($model)) {
             $qualifier_flag = 1;
             $queryWhere[] = " ( v.prodsubmodel = '" . $submodel . "' OR v.prodsubmodel = '' ) ";
             $queryWhere1[] = " ( v.prodsubmodel = '" . $submodel . "' OR v.prodsubmodel = '' ) ";
         }
     }
     // Do we need to filter for year of the product
     if (isset($searchTerms['year']) && $searchTerms['year'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
         $year = $searchTerms['year'];
         if (!empty($year)) {
             $qualifier_flag = 1;
             if (is_numeric($year)) {
                 $ext = "";
                 //if(isset($searchTerms['is_catg']))
                 $ext .= " OR v.prodstartyear = 'ALL' ";
                 $queryWhere[] = " ( " . $year . " between v.prodstartyear and v.prodendyear {$ext} ) ";
                 $queryWhere1[] = " ( " . $year . " between v.prodstartyear and v.prodendyear {$ext} ) ";
             } else {
                 $queryWhere[] = " ( v.prodstartyear = '{$year}' OR v.prodendyear = '{$year}' ) ";
                 $queryWhere1[] = " ( v.prodstartyear = '{$year}' OR v.prodendyear = '{$year}' ) ";
             }
         }
     }
     if (isset($searchTerms['price_from']) && isset($searchTerms['price_to'])) {
         $from_price = $searchTerms['price_from'];
         $to_price = $searchTerms['price_to'];
         if ($from_price != "" && $to_price != "") {
             $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice between " . $from_price . " and " . $to_price;
         }
     } else {
         if (isset($searchTerms['price_from'])) {
             $from_price = $searchTerms['price_from'];
             if (!empty($from_price)) {
                 $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice >= " . $from_price;
             }
         } else {
             if (isset($searchTerms['price_to'])) {
                 $to_price = $searchTerms['price_to'];
                 if (!empty($to_price)) {
                     $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice <= " . $from_price;
                 }
             }
         }
     }
     /*---- the below variables are used for displaying submodels in sideproductfilters.php --- */
     $GLOBALS['wherecondition'] = $queryWhere;
     $GLOBALS['wherecondition1'] = $queryWhere1;
     /*--------- creating conditions for dynamic filters----------*/
     $havingquery = array();
     $outer_condition = "";
     if (!empty($searchTerms['dynfilters'])) {
         $dynfilters = $searchTerms['dynfilters'];
         foreach ($dynfilters as $dynkey => $dynval) {
             $qualifier_flag = 1;
             $orgdynkey = $dynkey;
             //Added by Simha
             $str_to_check_pqvq = "";
             if (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] == 0) {
                 $str_to_check_pqvq = '^(vq|pq)';
             } else {
                 $str_to_check_pqvq = '^pq';
             }
             if (eregi($str_to_check_pqvq, $dynkey)) {
                 $dynkey = " v.{$dynkey} ";
                 //$outer_condition .= " AND $dynkey like '%".$dynval."%'";
                 if ($dynval == 'others') {
                     $havingquery[] = "( {$orgdynkey} = '' OR {$orgdynkey} IS NULL OR {$orgdynkey} = '~' )";
                     // here included '~' as in left navi query will return ~
                 } else {
                     if (strcasecmp($dynkey, ' v.VQbedsize ') == 0) {
                         $outer_condition .= " AND ( ( ( {$dynkey} = '" . $dynval . "') OR ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) ) OR ( ( v.bedsize_generalname = '" . $dynval . "' ) OR (  v.bedsize_generalname regexp ';' AND v.bedsize_generalname regexp '" . $dynval . "' ) ) ) ";
                     } else {
                         if (strcasecmp($dynkey, ' v.VQcabsize ') == 0) {
                             $outer_condition .= " AND ( ( ( {$dynkey} = '" . $dynval . "') OR ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) ) OR ( ( v.cabsize_generalname = '" . $dynval . "' ) OR (  v.cabsize_generalname regexp ';' AND v.cabsize_generalname regexp '" . $dynval . "' ) ) ) ";
                         } else {
                             $outer_condition .= " AND ( ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) OR ( {$dynkey} not regexp ';' AND {$dynkey} = '" . $dynval . "') )";
                         }
                     }
                 }
             }
         }
     }
     if (isset($searchTerms['vqsbedsize'])) {
         $qualifier_flag = 1;
         $outer_condition .= " AND (  v.VQbedsize like '%" . $searchTerms['vqsbedsize'] . "%' OR  v.bedsize_generalname like '%" . $searchTerms['vqsbedsize'] . "%' ) ";
     }
     if (isset($searchTerms['vqscabsize'])) {
         $qualifier_flag = 1;
         $outer_condition .= " AND (  v.VQcabsize like '%" . $searchTerms['vqscabsize'] . "%' OR  v.cabsize_generalname like '%" . $searchTerms['vqscabsize'] . "%' ) ";
     }
     if ($qualifier_flag == 0 && isset($searchTerms['search']) && (eregi('search.php', $_SERVER['REQUEST_URI']) || isset($GLOBALS['PathInfo']) && count($GLOBALS['PathInfo']) > 0) && !isset($_REQUEST['change'])) {
         //$joinQuery .= "INNER JOIN isc_product_search ps ON (p.productid=ps.productid)";
         //$joinQuery1 .= "INNER JOIN isc_product_search ps ON (p.productid=ps.productid)";
         if (isset($searchTerms['search_string'])) {
             $searchTerms['search_query'] = $searchTerms['search_string'];
         }
         if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "" && $searchTerms['search_query'] != "categories" && $searchTerms['search_query'] != "brands") {
             //$termQuery = "(" . $GLOBALS['ISC_CLASS_DB']->FullText($fulltext_fields, $searchTerms['search_query'], true);
             //$termQuery = " ( ";
             //$termQuery = " p.prodname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "' ";
             //$termQuery .= " p.prodname like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             /*$termQuery .= "OR p.proddesc like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR p.prodsearchkeywords like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodalternates like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodmake like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodmodel like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodsubmodel like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodstartyear like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR ps.prodendyear like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
             	 $termQuery .= "OR p.prodcode = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "') ";*/
             //$queryWhere1[] = $queryWhere[] = $termQuery;
             //$termQuery = " p.prodname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "' ";
             //$queryWhere1[] = $queryWhere[] = $termQuery;
         }
     }
     return $queryWhere1;
 }
Ejemplo n.º 7
0
 /**
  * Set the panel settings
  */
 public function SetPanelSettings()
 {
     $count = 1;
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     $output = "";
     $vendorRestriction = '';
     // If we're on a vendor page, only show top sellers from this particular vendor
     if (isset($GLOBALS['ISC_CLASS_VENDORS'])) {
         $vendor = $GLOBALS['ISC_CLASS_VENDORS']->GetVendor();
         $vendorRestriction = " AND p.prodvendorid='" . (int) $vendor['vendorid'] . "'";
     }
     $query = "\n\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\tFROM [|PREFIX|]products p\n\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)\n\t\t\tWHERE p.prodnumsold > '0' AND p.prodvisible='1' " . $vendorRestriction . "\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\tORDER BY p.prodnumsold DESC\n\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 5);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         // Use the SideTopSellersFirst snippet for the first product only
         if ($count == 1) {
             $snippet = "SideTopSellersFirst";
         } else {
             $snippet = "SideTopSellers";
         }
         $GLOBALS['ProductThumb'] = ImageThumbNew($row['imagefile'], ProdLink($row['prodname']));
         if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
             $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
             $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
         } else {
             $GLOBALS['ProductURL'] = CartLink($row['productid']);
             $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
         }
         if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
             $GLOBALS['HideActionAdd'] = '';
         } else {
             $GLOBALS['HideActionAdd'] = 'none';
         }
         $GLOBALS['HideProductVendorName'] = 'display: none';
         $GLOBALS['ProductVendor'] = '';
         if (GetConfig('ShowProductVendorNames') && $row['prodvendorid'] > 0) {
             $vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
             if (isset($vendorCache[$row['prodvendorid']])) {
                 $GLOBALS['ProductVendor'] = '<a href="' . VendorLink($vendorCache[$row['prodvendorid']]) . '">' . isc_html_escape($vendorCache[$row['prodvendorid']]['vendorname']) . '</a>';
                 $GLOBALS['HideProductVendorName'] = '';
             }
         }
         $GLOBALS['ProductNumber'] = $count++;
         $GLOBALS['ProductId'] = $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         $output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet($snippet);
     }
     $GLOBALS['SNIPPETS']['SideTopSellers'] = $output;
     if (!$output) {
         $this->DontDisplay = true;
     }
 }
Ejemplo n.º 8
0
	/**
	 * Set the panel settings.
	 */
	public function SetPanelSettings()
	{
		$cVendor = GetClass('ISC_VENDORS');
		$vendor = $cVendor->GetVendor();

		$GLOBALS['VendorId'] = $vendor['vendorid'];
		$GLOBALS['VendorName'] = $vendor['vendorname'];

		// Set the field we're sorting results by
		if(isset($_REQUEST['sort'])) {
			$sort = $_REQUEST['sort'];
		}
		else {
			$sort = '';
		}

		switch($sort) {
			case 'newest':
				$sortField = 'p.productid DESC';
				$GLOBALS['SortNewestSelected'] = 'selected="selected"';
				break;
			case 'bestselling':
				$sortField = 'p.prodnumsold DESC';
				$GLOBALS['SortBestSellingSelected'] = 'selected="selected"';
				break;
			case 'alphaasc':
				$sortField = 'p.prodname ASC';
				$GLOBALS['SortAlphaAsc'] = 'selected="selected"';
				break;
			case 'alphadesc':
				$sortField = 'p.prodname DESC';
				$GLOBALS['SortAlphaDesc'] = 'selected="selected"';
				break;
			case 'avgcustomerreview':
				$sortField = 'prodavgrating DESC';
				$GLOBALS['SortAvgReview'] = 'selected="selected"';
				break;
			case 'priceasc':
				$sortField = 'p.calculated_price ASC';
				$GLOBALS['SortPriceAsc'] = 'selected="selected"';
				break;
			case 'pricedesc';
				$sortField = 'p.calculated_price DESC';
				$GLOBALS['SortPriceDesc'] = 'selected="selected"';
				break;
			default:
				$sortField = 'p.prodvendorfeatured DESC';
				$sort = 'featured';
				$GLOBALS['SortFeaturedSelected'] = 'selected="selected"';
				break;
		}

		// If we're viewing a certain page, fetch our starting position
		if(isset($_REQUEST['page']) && IsId($_REQUEST['page'])) {
			$page = (int)$_REQUEST['page'];
			$start = ($page * GetConfig('CategoryProductsPerPage')) - GetConfig('CategoryProductsPerPage');
		}
		else {
			$page = 1;
			$start = 0;
		}

		// Count the number of products that belong in this vendor
		$query = "
			SELECT COUNT(p.productid) AS numproducts
			FROM [|PREFIX|]products p
			".GetProdCustomerGroupPermissionsSQL()."
			WHERE p.prodvisible='1' AND p.prodvendorid='".(int)$vendor['vendorid']."'
		";
		$numProducts = $GLOBALS['ISC_CLASS_DB']->FetchOne($query);
		$numPages = ceil($numProducts / GetConfig('CategoryProductsPerPage'));

		// Now load the actual products for this vendor
		$query = $this->getProductQuery(
			'p.prodvendorid='.(int)$vendor['vendorid'],
			$sortField.', prodname ASC',
			getConfig('CategoryProductsPerPage'),
			$start
		);
		$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

		$GLOBALS['SNIPPETS']['VendorProducts'] = '';

		if(!GetConfig('ShowProductRating')) {
			$GLOBALS['HideProductRating'] = "display: none";
		}

		// Should we show the compare button?
		if(GetConfig('EnableProductComparisons') == 0 || $numProducts < 2) {
			$GLOBALS['HideCompareItems'] = "none";
		}
		else {
			$GLOBALS['CompareLink'] = CompareLink();
		}

		$GLOBALS['AlternateClass'] = '';
		while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
			$this->setProductGlobals($row);
			$GLOBALS['SNIPPETS']['VendorProducts'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("VendorProductsItem");
		}

		// Does paging need to be shown?
		if($numProducts > GetConfig('CategoryProductsPerPage')) {
			$GLOBALS['SNIPPETS']['PagingData'] = "";

			$numEitherSide = 5;
			$start = max($page-$numEitherSide,1);
			$end = min($page+$numEitherSide, $numPages);

			for($i = $start; $i <= $end; $i++) {
				if ($i == $page) {
					$snippet = "CategoryPagingItemCurrent";
				}
				else {
					$snippet = "CategoryPagingItem";
				}

				$pageData = array(
					'page' => $i,
					'sort' => $sort
				);
				$GLOBALS['PageLink'] = VendorProductsLink($vendor, $pageData);
				$GLOBALS['PageNumber'] = $i;
				$GLOBALS['SNIPPETS']['PagingData'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet($snippet);
			}

			// Do we need to output a "Previous" link?
			if($page > 1) {
				$pageData = array(
					'page' => $page-1,
					'sort' => $sort
				);
				$GLOBALS['PrevLink'] = VendorProductsLink($vendor, $pageData);
				$GLOBALS['SNIPPETS']['CategoryPagingPrevious'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPagingPrevious");
			}

			// Do we need to output a "Next" link?
			if($page < $numPages) {
				$pageData = array(
					'page' => $page+1,
					'sort' => $sort
				);
				$GLOBALS['NextLink'] = VendorProductsLink($vendor, $pageData);
				$GLOBALS['SNIPPETS']['CategoryPagingNext'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPagingNext");
			}

			$output = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPaging");
			$output = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseSnippets($output, $GLOBALS['SNIPPETS']);
			$GLOBALS['SNIPPETS']['ProductPaging'] = $output;
		}

		// Parse the sort select box snippet
		if($numProducts > 1) {

			// Parse the sort select box snippet
			if($GLOBALS['EnableSEOUrls'] == 1 && $vendor['vendorfriendlyname']) {
				$GLOBALS['URL'] = VendorProductsLink($vendor);
			}
			else {
				$GLOBALS['URL'] = $GLOBALS['ShopPath']."/vendors.php";
				$GLOBALS['HiddenSortField'] = "<input type=\"hidden\" name=\"vendorid\" value=\"".(int)$vendor['vendorid']."\" />";
				$GLOBALS['HiddenSortField'] .= "<input type=\"hidden\" name=\"action\" value=\"products\" />";
			}

			$GLOBALS['SNIPPETS']['CategorySortBox'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategorySortBox");
		}
	}
Ejemplo n.º 9
0
		/**
		*	Show a list of items that the customer has recently viewed by browsing our site
		*/
		private function ShowRecentItems()
		{

			$viewed = "";

			if (isset($_COOKIE['RECENTLY_VIEWED_PRODUCTS'])) {
				$viewed = $_COOKIE['RECENTLY_VIEWED_PRODUCTS'];
			} else if (isset($_SESSION['RECENTLY_VIEWED_PRODUCTS'])) {
				$viewed = $_SESSION['RECENTLY_VIEWED_PRODUCTS'];
			}

			if ($viewed != "") {
				$GLOBALS['HideNoRecentItemsMessage'] = "none";
				$GLOBALS['SNIPPETS']['AccountRecentItems'] = "";

				$viewed_products = array();
				$viewed_products = explode(",", $viewed);
				foreach ($viewed_products as $k => $p) {
					$viewed_products[$k] = (int) $p;
				}

				// Reverse the array so recently viewed products appear up top
				$viewed_products = array_reverse($viewed_products);

				// Hide the compare button if there's less than 2 products
				if (GetConfig('EnableProductComparisons') == 0 || count($viewed_products) < 2) {
					$GLOBALS['HideCompareItems'] = "none";
				}

				if (!empty($viewed_products)) {
					if(!getProductReviewsEnabled()) {
						$GLOBALS['HideProductRating'] = "display: none";
					}
					$query = "
						SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL()."
						FROM [|PREFIX|]products p
						LEFT JOIN [|PREFIX|]product_images pi ON (productid=pi.imageprodid AND imageisthumb=1)
						WHERE prodvisible='1' AND productid in ('".implode("','", $viewed_products)."')
						".GetProdCustomerGroupPermissionsSQL()."
					";
					$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
					if ($GLOBALS['ISC_CLASS_DB']->CountResult($result) > 0) {
						$GLOBALS['AlternateClass'] = '';
						while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
							if($GLOBALS['AlternateClass'] == 'Odd') {
								$GLOBALS['AlternateClass'] = 'Even';
							}
							else {
								$GLOBALS['AlternateClass'] = 'Odd';
							}

							$GLOBALS['ProductId'] = (int) $row['productid'];
							$GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
							$GLOBALS['ProductLink'] = ProdLink($row['prodname']);
							$GLOBALS['ProductRating'] = (int)$row['prodavgrating'];

							// Determine the price of this product
							$GLOBALS['ProductPrice'] = '';
							if (GetConfig('ShowProductPrice') && !$row['prodhideprice']) {
								$GLOBALS['ProductPrice'] = formatProductCatalogPrice($row);
							}

							$GLOBALS['ProductThumb'] = ImageThumb($row, ProdLink($row['prodname']));

							$GLOBALS['SNIPPETS']['AccountRecentItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AccountRecentlyViewedProducts");
						}
					}
				}
				else {
					$GLOBALS['HideRecentItemList'] = "none";
				}
			}
			else {
				$GLOBALS['HideRecentItemList'] = "none";
			}

			$GLOBALS['CompareLink'] = CompareLink();

			// Show the list of available shipping addresses
			$GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(GetConfig('StoreName') . " - " . GetLang('RecentlyViewedItems'));
			$GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("account_recentitems");
			$GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate();
		}
Ejemplo n.º 10
0
		public function LoadProductsForBrand()
		{
			$taxJoin = $this->getTaxPricingJoin();
			$query = "
				SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL()."
				FROM [|PREFIX|]products p
				LEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)
				".$taxJoin."
				WHERE prodbrandid='".(int)$this->GetId()."' AND prodvisible='1'
				".GetProdCustomerGroupPermissionsSQL()."
				ORDER BY ".$this->GetSortField().", prodname ASC
			";
			$query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($this->GetStart(), GetConfig('CategoryProductsPerPage'));
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

			while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				$row['prodavgrating'] = (int)$row['prodavgrating'];
				$this->_brandproducts[] = $row;
			}
		}
Ejemplo n.º 11
0
		/**
		 * Search for products
		 *
		 * Method will search for all the products and return an array of product records records
		 *
		 * @access public
		 * @param array $searchQuery The search query array. Currently will only understand the 'search_query' option
		 * @param int &$totalAmount The referenced variable to store in the total amount of the result
		 * @param int $start The optional start position of the result total. Default is 0
		 * @param int $limit The optional limit position of the result total. Default is -1 (no limit)
		 * @param string $sortBy The optional order by. Default is GetConfig("SearchDefaultProductSort")
		 * @return array The array result set on success, FALSE on error
		 */
		static public function searchForItems($searchQuery, &$totalAmount, $start=0, $limit=-1, $sortBy="")
		{
			if (trim($sortBy) == "") {
				$sortBy = GetConfig("SearchDefaultProductSort");
			}

			if (!is_array($searchQuery)) {
				return false;
			}

			$totalAmount = 0;

			if (!is_array($searchQuery) || empty($searchQuery)) {
				return false;
			}

			$fullTextFields = array("ps.prodname", "ps.prodcode", "ps.proddesc", "ps.prodsearchkeywords");

			$products = array();
			$query = "SELECT SQL_CALC_FOUND_ROWS p.*, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating,
							" . GetProdCustomerGroupPriceSQL() . ", pi.* ";

			if (isset($searchQuery["search_query"]) && trim($searchQuery["search_query"]) !== "") {
				$query .= ", (IF(p.prodname='" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "', 10000, 0) +
							  IF(p.prodcode='" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "', 10000, 0) +
							  ((" . $GLOBALS["ISC_CLASS_DB"]->FullText(array("ps.prodname"), $searchQuery["search_query"], false) . ") * 10) +
								" . $GLOBALS["ISC_CLASS_DB"]->FullText($fullTextFields, $searchQuery["search_query"], false) . ") AS score ";
			}

			$query .= " FROM [|PREFIX|]products p
							LEFT JOIN [|PREFIX|]product_images pi ON (p.productid = pi.imageprodid AND pi.imageisthumb = 1) ";

			// Sorting or filtering by price. Need to join the tax pricing table
			if(!empty($searchQuery['price']) || !empty($searchQuery['price_from']) || !empty($searchQuery['price_to']) || $sortBy == 'priceasc' || $sortBy == 'pricedesc') {
				$priceColumn = 'tp.calculated_price';

				// Showing prices ex tax, so the tax zone ID = 0
				if(getConfig('taxDefaultTaxDisplayCatalog') == TAX_PRICES_DISPLAY_EXCLUSIVE) {
					$taxZone = 0;
				}
				// Showing prices inc tax, so we need to fetch the applicable tax zone
				else {
					$taxZone = getClass('ISC_TAX')->determineTaxZone();
				}

				$query .= '
					JOIN [|PREFIX|]product_tax_pricing tp
					ON (
						tp.price_reference=p.prodcalculatedprice AND
						tp.tax_zone_id='.$taxZone.' AND
						tp.tax_class_id=p.tax_class_id
					)
				';
			}
			else {
				$priceColumn = 'p.prodcalculatedprice';
			}

			if (isset($searchQuery["categoryid"])) {
				$searchQuery["category"] = array($searchQuery["categoryid"]);
			}

			$searchTerms = $GLOBALS['ISC_CLASS_SEARCH']->readSearchSession();

			$categorySearch = false;
			$categoryIds = array();
			$nestedset = new ISC_NESTEDSET_CATEGORIES;
			if (isset($searchQuery["category"]) && is_array($searchQuery["category"])) {
				foreach ($searchQuery["category"] as $categoryId) {
					// All categories were selected, so don"t continue
					if (!isId($categoryId)) {
						$categorySearch = false;
						break;
					}

					$categoryIds[] = (int)$categoryId;

					// If searching sub categories automatically, fetch & tack them on
					if (isset($searchQuery["searchsubs"]) && $searchQuery["searchsubs"] == "ON") {
						foreach ($nestedset->getTree(array('categoryid'), $categoryId) as $childCategory) {
							$categoryIds[] = (int)$childCategory['categoryid'];
						}
						unset($childCategory);
					}
				}

				$categoryIds = array_unique($categoryIds);
				if (!empty($categoryIds)) {
					$categorySearch = true;
				}
			}

			if ($categorySearch == true) {
				$query .= " INNER JOIN [|PREFIX|]categoryassociations a ON a.productid = p.productid AND a.categoryid IN (" . implode(",", $categoryIds) . ") ";
			}

			if (isset($searchQuery["search_query"]) && trim($searchQuery["search_query"]) !== "") {
				$query .= " INNER JOIN [|PREFIX|]product_search ps ON p.productid = ps.productid ";
			}

			$query .= " WHERE p.prodvisible = 1 " . GetProdCustomerGroupPermissionsSQL();

			// Do we need to filter on brand?
			if (isset($searchQuery["brand"]) && isId($searchQuery["brand"])) {
				$query .= " AND p.prodbrandid = " . (int)$searchQuery["brand"];
			}

			// Do we need to filter on price?
			if (isset($searchQuery["price"]) && is_numeric($searchQuery["price"])) {
				$query .= " AND ".$priceColumn." ='" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchTerms["price"]) . "'";
			} else {
				if (isset($searchQuery["price_from"]) && is_numeric($searchQuery["price_from"])) {
					$query .= " AND ".$priceColumn." >= '" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["price_from"]) . "'";
				}

				if (isset($searchQuery["price_to"]) && is_numeric($searchQuery["price_to"])) {
					$query .= " AND ".$priceColumn." <= '" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["price_to"]) . "'";
				}
			}

			// Do we need to filter on rating?
			if (isset($searchQuery["rating"])) {
				$query .= " AND FLOOR(p.prodratingtotal/p.prodnumratings) = " . (int)$searchQuery["rating"];
			} else {
				if (isset($searchQuery["rating_from"]) && is_numeric($searchQuery["rating_from"])) {
					$query .= " AND FLOOR(p.prodratingtotal/p.prodnumratings) >= " . (int)$searchQuery["rating_from"];
				}

				if (isset($searchQuery["rating_to"]) && is_numeric($searchQuery["rating_to"])) {
					$query .= " AND FLOOR(p.prodratingtotal/p.prodnumratings) <= " . (int)$searchQuery["rating_to"];
				}
			}

			// Do we need to filter on featured?
			if (isset($searchQuery["featured"]) && is_numeric($searchQuery["featured"])) {
				if ((int)$searchQuery["featured"] == 1) {
					$query .= " AND p.prodfeatured = 1 ";
				} else {
					$query .= " AND p.prodfeatured = 0 ";
				}
			}

			// Do we need to filter on free shipping?
			if (isset($searchQuery["shipping"]) && is_numeric($searchQuery["shipping"])) {
				if ((int)$searchQuery["shipping"] == 1) {
					$query .= " AND p.prodfreeshipping = 1 ";
				}
				else {
					$query .= " AND p.prodfreeshipping = 0 ";
				}
			}

			// Do we need to filter only products we have in stock?
			if (isset($searchQuery["instock"]) && is_numeric($searchQuery["instock"])) {
				if ((int)$searchQuery["instock"] == 1) {
					$query .= " AND (p.prodcurrentinv > 0 OR p.prodinvtrack = 0) ";
				}
			}

			if (isset($searchQuery["search_query"]) && trim($searchQuery["search_query"]) !== "") {
				$searchPart = array();

				if (GetConfig("SearchOptimisation") == "fulltext" || GetConfig("SearchOptimisation") == "both") {
					$searchPart[] = $GLOBALS["ISC_CLASS_DB"]->FullText($fullTextFields, $searchQuery["search_query"], true);
				}

				if (GetConfig("SearchOptimisation") == "like" || GetConfig("SearchOptimisation") == "both") {
					$searchPart[] = "p.prodname LIKE '%" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "%'";
					$searchPart[] = "p.proddesc LIKE '%" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "%'";
					$searchPart[] = "p.prodsearchkeywords LIKE '%" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "%'";
				}

				$query .= " AND (ps.prodcode = '" . $GLOBALS["ISC_CLASS_DB"]->Quote($searchQuery["search_query"]) . "' OR TRUE) ";
				$query .= " AND (" . implode(" OR ", $searchPart) . ") ";
			}

			$orderBy = "";

			switch (isc_strtolower($sortBy)) {
				case "relevance":
					if (isset($searchQuery["search_query"]) && trim($searchQuery["search_query"]) !== "") {
						$orderBy = "score DESC";
					}

					break;

				case "featured":
					$orderBy = "p.prodfeatured DESC";
					break;

				case "newest":
					$orderBy = "p.productid DESC";
					break;

				case "bestselling":
					$orderBy = "p.prodnumsold DESC";
					break;

				case "alphaasc":
					$orderBy = "p.prodname ASC";
					break;

				case "alphadesc":
					$orderBy = "p.prodname DESC";
					break;

				case "avgcustomerreview":
					$orderBy = "prodavgrating DESC";
					break;

				case "priceasc":
					$orderBy = $priceColumn.' ASC';
					break;

				case "pricedesc":
					$orderBy = $priceColumn.' DESC';
					break;
			}

			if (trim($orderBy) !== "") {
				$query .= " ORDER BY " . $orderBy;
			} else {
				$query .= " ORDER BY p.productid DESC";
			}

			if (is_numeric($limit) && $limit > 0) {
				if (is_numeric($start) && $start > 0) {
					$query .= " LIMIT " . (int)$start . "," . (int)$limit;
				} else {
					$query .= " LIMIT " . (int)$limit;
				}
			}

			$result = $GLOBALS["ISC_CLASS_DB"]->Query($query);
			$row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result);

			if (!$row) {
				return array();
			}

			$totalAmount = $GLOBALS["ISC_CLASS_DB"]->FetchOne("SELECT FOUND_ROWS()");
			$products[$row["productid"]] = $row;

			while ($row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result)) {
				$products[$row["productid"]] = $row;
			}

			return $products;
		}
Ejemplo n.º 12
0
	/**
	* Returns a list of products, most popular first, related to the provided product id on the basis of similar viewing habits
	*
	* @param int $productId
	* @param int $limit Number of related products to return, or 0 to not limit
	* @param bool $returnResult If true, will return mysql result resource, otherwise returns array of ids with highest-cross-viewed product first
	* @return array
	*/
	public static function getRelatedProducts($productId, $limit = 0, $returnResult = false)
	{
		$db = $GLOBALS['ISC_CLASS_DB'];

		$sql = "
			SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, " . GetProdCustomerGroupPriceSQL() . "
			FROM `[|PREFIX|]products` p
			LEFT JOIN `[|PREFIX|]product_images` pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)
			INNER JOIN `[|PREFIX|]product_related_byviews` prv ON prv.prodida = " . $productId . " AND prv.prodidb = p.productid
			WHERE p.prodvisible = 1
			" . GetProdCustomerGroupPermissionsSQL() . "
			ORDER BY prv.relevance DESC";

		if ($limit) {
			$sql .= " LIMIT " . $limit;
		}

		$result = $db->Query($sql);

		if ($returnResult) {
			// return result for an iterator or something to use
			return $result;
		}

		$products = array();
		if ($result) {
			while ($product = $db->Fetch($result)) {
				$products[] = $product;
			}
		}
		return $products;
	}
Ejemplo n.º 13
0
 public function LoadProductsForBrand()
 {
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid)\n\t\t\t\tWHERE prodbrandid='" . (int) $this->GetId() . "' AND prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))\n\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\tORDER BY " . $this->GetSortField() . ", prodname ASC\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($this->GetStart(), GetConfig('CategoryProductsPerPage'));
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $row['prodavgrating'] = (int) $row['prodavgrating'];
         $this->_brandproducts[] = $row;
     }
 }
Ejemplo n.º 14
0
 public function SetPanelSettings()
 {
     $count = 0;
     $prod_ids = array();
     $output = "";
     $GLOBALS['SuggestedProductListing'] = "";
     // Hide the "compare" checkbox for each product
     $GLOBALS['HideCompareItems'] = "none";
     // Make sure the query doesn't return the product we're adding to
     // the cart or any other products in the cart for that matter
     $GLOBALS['ISC_CLASS_CART'] = GetClass('ISC_CART');
     $ignore_prod_list = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCartCSV();
     if ($ignore_prod_list == "") {
         $ignore_prod_list = 0;
     }
     $query = "\n\t\t\t\tSELECT ordprodid\n\t\t\t\tFROM [|PREFIX|]order_products\n\t\t\t\tWHERE orderorderid IN (\n\t\t\t\t\tSELECT orderorderid FROM [|PREFIX|]order_products WHERE ordprodid='" . (int) $GLOBALS['ProductJustAdded'] . "'\n\t\t\t\t) AND ordprodid NOT IN (" . $ignore_prod_list . ")\n\t\t\t\tGROUP BY ordprodid\n\t\t\t\tORDER BY COUNT(ordprodid) DESC\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 9);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     // Get the list of suggested product id's
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $prod_ids[] = $row['ordprodid'];
     }
     $suggest_prod_ids = implode(",", $prod_ids);
     $remaining_places = 9 - count($prod_ids);
     // If there aren't enough products to suggest, we will get
     // the popular products (based on reviews) instead
     // If there aren't enough suggested products, fetch related products for this item
     if ($remaining_places > 0) {
         require_once APP_ROOT . "/includes/classes/class.product.php";
         $related = GetRelatedProducts($GLOBALS['Product']['productid'], $GLOBALS['Product']['prodname'], $GLOBALS['Product']['prodrelatedproducts']);
         // Any returned products? add them to the list
         $relatedProducts = explode(",", $related);
         // Limit the number of products to the # of empty spaces we have
         for ($i = 0; $i <= $remaining_places; ++$i) {
             if (!isset($relatedProducts[$i]) || $relatedProducts[$i] == "") {
                 break;
             }
             if (!in_array($relatedProducts[$i], $prod_ids) && !@in_array($relatedProducts[$i], $ignore_prod_list)) {
                 $prod_ids[] = $relatedProducts[$i];
             }
         }
         $remaining_places = 9 - count($prod_ids);
         $suggest_prod_ids = implode(",", $prod_ids);
     }
     // Still don't have enough? Fetch popular products
     if ($remaining_places > 0) {
         if (!$suggest_prod_ids) {
             $suggest_prod_ids = 0;
         }
         $query = sprintf("select productid, floor(prodratingtotal/prodnumratings) as prodavgrating from [|PREFIX|]products where productid not in (%s) and productid not in (%s) and prodvisible='1' order by prodavgrating desc", $suggest_prod_ids, $ignore_prod_list);
         $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, $remaining_places);
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         // Is there at least one product to suggest?
         while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
             $prod_ids[] = $row['productid'];
         }
         $suggest_prod_ids = implode(",", $prod_ids);
     }
     // If there are *still* no products to suggest, just show them
     // the normal shopping cart view instead
     if (!empty($prod_ids)) {
         // Get a list of products that were ordered at the
         // same time as the product that was just added to the cart
         if (!$suggest_prod_ids) {
             $suggest_prod_ids = 0;
         }
         if (GetConfig('EnableProductReviews') == 0) {
             $GLOBALS['HideProductRating'] = "display: none";
         }
         $query = "\n\t\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid)\n\t\t\t\t\tWHERE p.productid IN (" . $suggest_prod_ids . ") AND p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))\n\t\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\t\tORDER BY prodnumsold DESC, prodratingtotal DESC\n\t\t\t\t";
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         $GLOBALS['AlternateClass'] = '';
         while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
             if ($GLOBALS['AlternateClass'] == 'Odd') {
                 $GLOBALS['AlternateClass'] = 'Even';
             } else {
                 $GLOBALS['AlternateClass'] = 'Odd';
             }
             $GLOBALS['ProductCartQuantity'] = '';
             if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
                 $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
             }
             $GLOBALS['ProductId'] = (int) $row['productid'];
             $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
             $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
             $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
             // Determine the price of this product
             $GLOBALS['ProductPrice'] = CalculateProductPrice_retail($row);
             $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
             if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
                 $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
                 $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
             } else {
                 //$GLOBALS['ProductURL'] = CartLink($row['productid']);
                 $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
                 //blessen
                 if (intval($row['prodretailprice']) <= 0) {
                     $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
                 } else {
                     $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink1');
                 }
                 //blessen
                 //$GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
             }
             if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
                 $GLOBALS['HideActionAdd'] = '';
             } else {
                 $GLOBALS['HideActionAdd'] = 'none';
             }
             $GLOBALS['HideProductVendorName'] = 'display: none';
             $GLOBALS['ProductVendor'] = '';
             if (GetConfig('ShowProductVendorNames') && $row['prodvendorid'] > 0) {
                 $vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
                 if (isset($vendorCache[$row['prodvendorid']])) {
                     $GLOBALS['ProductVendor'] = '<a href="' . VendorLink($vendorCache[$row['prodvendorid']]) . '">' . isc_html_escape($vendorCache[$row['prodvendorid']]['vendorname']) . '</a>';
                     $GLOBALS['HideProductVendorName'] = '';
                 }
             }
             $GLOBALS['SuggestedProductListing'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryProductsItem");
         }
     }
     if (!$GLOBALS['SuggestedProductListing']) {
         ob_end_clean();
         header("Location:cart.php");
         die;
     }
 }
Ejemplo n.º 15
0
 public function LoadProductsToCompare()
 {
     $count = 0;
     $output = "";
     $tOutput = "";
     $products = array();
     // First row - the "Remove" link
     $GLOBALS['SNIPPETS']['TD1'] = "";
     $GLOBALS['SNIPPETS']['TD2'] = "";
     $GLOBALS['SNIPPETS']['TD3'] = "";
     $GLOBALS['SNIPPETS']['TD4'] = "";
     $GLOBALS['SNIPPETS']['TD5'] = "";
     $GLOBALS['SNIPPETS']['TD6'] = "";
     $GLOBALS['SNIPPETS']['TD7'] = "";
     $GLOBALS['SNIPPETS']['TD8'] = "";
     $GLOBALS['SNIPPETS']['TD9'] = "";
     $GLOBALS['SNIPPETS']['TD10'] = "";
     $GLOBALS['SNIPPETS']['TD11'] = "";
     // Do we need to sort?
     if ($this->_comparesort != "") {
         $sort = sprintf("order by %s", $this->_comparesort);
     } else {
         $sort = "";
     }
     $product_ids = $this->GetProductIds();
     if (empty($product_ids)) {
         return;
     }
     $productids_array = explode('/', $this->GetIds());
     if ($GLOBALS['EnableSEOUrls'] == 1) {
         $GLOBALS['BaseCompareLink'] = CompareLink($productids_array) . '?';
     } else {
         $GLOBALS['BaseCompareLink'] = CompareLink($productids_array) . '&amp;';
     }
     $compareWidth = 100 - 20;
     $compareWidth = floor($compareWidth / count($this->_compareproducts));
     $GLOBALS['CompareWidth'] = $compareWidth . "%";
     $GLOBALS['CompareHeadWidth'] = 100 - $compareWidth * count($this->_compareproducts) . "%";
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . ",\n\t\t\t\t(SELECT brandname FROM [|PREFIX|]brands WHERE brandid=prodbrandid) AS brand,\n\t\t\t\t(select count(fieldid) from [|PREFIX|]product_customfields where fieldprodid=p.productid) as numcustomfields,\n\t\t\t\t(select count(reviewid) from [|PREFIX|]reviews where revproductid=p.productid and revstatus='1') AS numreviews\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid)\n\t\t\t\tWHERE p.prodvisible='1' AND p.productid IN (" . $product_ids . ") AND (pi.imageisthumb=1 OR ISNULL(pi.imageisthumb))\n\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t" . $sort;
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $GLOBALS['ProductNumber'] = $count++;
         if ($row['brand'] != "") {
             $GLOBALS['ProductBrand'] = sprintf("<a href='%s'>%s</a>", BrandLink($row['brand']), isc_html_escape($row['brand']));
         } else {
             $GLOBALS['ProductBrand'] = GetLang('NA');
         }
         // Build the page title
         $this->_comparetitle .= sprintf("%s %s ", isc_html_escape($row['prodname']), GetLang('VS'));
         $GLOBALS['ProductId'] = $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         $GLOBALS['NumReviews'] = $row['numreviews'];
         if ($row['numreviews'] == 0) {
             $GLOBALS['HideComparisonReviewLink'] = "none";
         } else {
             $GLOBALS['HideComparisonReviewLink'] = "";
         }
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice_retail($row);
         if ($row['prodavailability'] != "") {
             $GLOBALS['ProductAvailability'] = isc_html_escape($row['prodavailability']);
         } else {
             $GLOBALS['ProductAvailability'] = GetLang('NA');
         }
         $compare_ids = array_diff($this->_compareproducts, array($row['productid']));
         if (count($compare_ids) == 1) {
             $GLOBALS['RemoveCompareLink'] = "javascript:alert('%%LNG_CompareTwoProducts%%');";
         } else {
             $GLOBALS['RemoveCompareLink'] = CompareLink($compare_ids);
             if (!empty($this->_comparesort)) {
                 $GLOBALS['RemoveCompareLink'] .= '?sort=' . $_GET['sort'];
             }
         }
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         if ($row['proddesc'] != "") {
             // Strip out HTML from the description first
             $row['proddesc'] = strip_tags($row['proddesc']);
             if (isc_strlen($row['proddesc']) > 200) {
                 $GLOBALS['ProductSummary'] = isc_substr($row['proddesc'], 0, 200) . "...";
             } else {
                 $GLOBALS['ProductSummary'] = $row['proddesc'];
             }
         } else {
             $GLOBALS['ProductSummary'] = GetLang('NA');
         }
         // Are there any custom fields?
         if ($row['numcustomfields'] > 0) {
             $GLOBALS['CustomFields'] = "";
             // Get the custom fields for this product
             $query = sprintf("select * from [|PREFIX|]product_customfields where fieldprodid='%d'", $GLOBALS['ISC_CLASS_DB']->Quote($row['productid']));
             $cResult = $GLOBALS['ISC_CLASS_DB']->Query($query);
             while ($cRow = $GLOBALS['ISC_CLASS_DB']->Fetch($cResult)) {
                 $GLOBALS['CustomFieldName'] = isc_html_escape($cRow['fieldname']);
                 $GLOBALS['CustomFieldValue'] = $cRow['fieldvalue'];
                 $GLOBALS['CustomFields'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductCustomField");
             }
         } else {
             $GLOBALS['CustomFields'] = GetLang('NA');
         }
         $GLOBALS['SNIPPETS']['TD1'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD1");
         $GLOBALS['SNIPPETS']['TD2'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD2");
         $GLOBALS['SNIPPETS']['TD3'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD3");
         $GLOBALS['SNIPPETS']['TD4'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD4");
         $GLOBALS['SNIPPETS']['TD5'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD5");
         $GLOBALS['SNIPPETS']['TD6'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD6");
         $GLOBALS['SNIPPETS']['TD7'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD7");
         $GLOBALS['SNIPPETS']['TD8'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD8");
         $GLOBALS['SNIPPETS']['TD9'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTD9");
     }
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none;";
     }
     $output1 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR1");
     $output2 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR2");
     $output3 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR3");
     $output4 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR4");
     $output5 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR5");
     $output6 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR6");
     $output7 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR7");
     $output8 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR8");
     $output9 = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CompareProductTR9");
     $output = $output1 . $output2 . $output3 . $output4 . $output9 . $output5 . $output6 . $output7 . $output8;
     $output = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseSnippets($output, $GLOBALS['SNIPPETS']);
     $GLOBALS['SNIPPETS']['ComparisonList'] = $output;
 }
Ejemplo n.º 16
0
 /**
  * Load a list of products in the current tag that we're viewing.
  */
 private function LoadProductsForTag()
 {
     if (!is_array($this->tag)) {
         return false;
     }
     $query = "\n\t\t\tSELECT COUNT(p.productid) AS numproducts\n\t\t\tFROM [|PREFIX|]products p\n\t\t\tINNER JOIN [|PREFIX|]product_tagassociations ta ON (ta.productid=p.productid AND ta.tagid='" . (int) $this->tag['tagid'] . "')\n\t\t\tWHERE prodvisible='1'\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t";
     $this->numProducts = $GLOBALS['ISC_CLASS_DB']->FetchOne($query);
     $this->pageCount = ceil($this->numProducts / GetConfig('CategoryProductsPerPage'));
     // For some reason the tag could has become out of sync for this tag, we need to reset it
     if ($this->numProducts != $this->tag['tagcount']) {
         $updatedTag = array('tagcount' => $this->numProducts);
         $GLOBALS['ISC_CLASS_DB']->UpdateQuery('product_tags', $updatedTag, "tagid='" . (int) $this->tag['tagid'] . "'");
     }
     // Now load the actual products for this tag
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND imageisthumb=1)\n\t\t\t\tINNER JOIN [|PREFIX|]product_tagassociations ta ON (ta.productid=p.productid AND ta.tagid='" . (int) $this->tag['tagid'] . "')\n\t\t\t\tWHERE prodvisible='1'\n\t\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\t\tORDER BY " . $this->sortField . ", prodname ASC\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($this->productStart, GetConfig('CategoryProductsPerPage'));
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         $row['prodavgrating'] = (int) $row['prodavgrating'];
         $this->products[] = $row;
     }
 }
 public function SetPanelSettings()
 {
     if (!gzte11(ISC_HUGEPRINT) || $GLOBALS['ISC_CLASS_PRODUCT']->GetProductVendor() === false) {
         $this->DontDisplay = true;
         return false;
     }
     $vendor = $GLOBALS['ISC_CLASS_PRODUCT']->GetProductVendor();
     $GLOBALS['SNIPPETS']['VendorsOtherProducts'] = '';
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     $query = "\n\t\t\tSELECT p.*, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating, i.imagefile, i.imageisthumb, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\tFROM [|PREFIX|]products p\n\t\t\tLEFT JOIN [|PREFIX|]product_images i ON (p.productid = i.imageprodid AND i.imageisthumb=1)\n\t\t\tWHERE p.prodvisible='1' AND p.prodvendorid='" . (int) $vendor['vendorid'] . "' AND p.productid!='" . (int) $GLOBALS['ISC_CLASS_PRODUCT']->GetProductId() . "'\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\tORDER BY p.prodvendorfeatured DESC, RAND() DESC\n\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 9);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $productsDone = 0;
     $hasMore = false;
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         ++$productsDone;
         if ($productsDone == 9) {
             $hasMore = true;
             break;
         }
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         $GLOBALS['ProductId'] = (int) $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice_retail($row);
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
             $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
             $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
         } else {
             //$GLOBALS['ProductURL'] = CartLink($row['productid']);
             $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
             //blessen
             if (intval($row['prodretailprice']) <= 0) {
                 $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
             } else {
                 $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink1');
             }
             //blessen
             //$GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
         }
         if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
             $GLOBALS['HideActionAdd'] = '';
         } else {
             $GLOBALS['HideActionAdd'] = 'none';
         }
         $GLOBALS['SNIPPETS']['VendorsOtherProducts'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductVendorsOtherProductsItem");
     }
     if (!$GLOBALS['SNIPPETS']['VendorsOtherProducts']) {
         $this->DontDisplay = true;
     }
     $GLOBALS['VendorProductsLink'] = VendorProductsLink($vendor);
     if ($hasMore == true) {
         $GLOBALS['HideViewAllLink'] = '';
     } else {
         $GLOBALS['HideViewAllLink'] = 'display: none';
     }
 }
Ejemplo n.º 18
0
	/**
	 * Build an SQL query for the specified search terms.
	 *
	 * @param array Array of search terms
	 * @param string String of fields to match
	 * @param string The field to sort by
	 * @param string The order to sort results by
	 * @return array An array containing the query to count the number of results and a query to perform the search
	 */
	function BuildProductSearchQuery($searchTerms, $fields="", $sortField=array("score", "proddateadded"), $sortOrder="desc")
	{
		$queryWhere = array();
		$joinQuery = '';

		// Construct the full text search part of the query
		$fulltext_fields = array("ps.prodname", "ps.prodcode", "ps.proddesc", "ps.prodsearchkeywords");

		if (!$fields) {
			$fields = "p.*, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating, ".GetProdCustomerGroupPriceSQL().", ";
			$fields .= "pi.* ";
			if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "") {
				$fields .= ', '.$GLOBALS['ISC_CLASS_DB']->FullText($fulltext_fields, $searchTerms['search_query'], false) . " as score ";
			}
		}

		if(isset($searchTerms['categoryid'])) {
			$searchTerms['category'] = array($searchTerms['categoryid']);
		}

		// If we're searching by category, we need to completely
		// restructure the search query - so do that first
		$categorySearch = false;
		$categoryIds = array();
		$nestedset = new ISC_NESTEDSET_CATEGORIES;
		if(isset($searchTerms['category']) && is_array($searchTerms['category'])) {
			foreach($searchTerms['category'] as $categoryId) {
				$categoryId = (int)$categoryId;
				// All categories were selected, so don't continue
				if($categoryId == 0) {
					$categorySearch = false;
					break;
				}

				$categoryIds[] = $categoryId;

				// If searching sub categories automatically, fetch & tack them on
				if(isset($searchTerms['searchsubs']) && $searchTerms['searchsubs'] == 'ON') {
					foreach ($nestedset->getTree(array('categoryid'), $categoryId) as $childCategory) {
						$categoryIds[] = (int)$childCategory['categoryid'];
					}
					unset($childCategory);
				}
			}

			$categoryIds = array_unique($categoryIds);
			if(!empty($categoryIds)) {
				$categorySearch = true;
			}
		}

		if($categorySearch == true) {
			$fromTable = '[|PREFIX|]categoryassociations a, [|PREFIX|]products p';
			$queryWhere[] = 'a.productid=p.productid AND a.categoryid IN ('.implode(',', $categoryIds).')';
		}
		else {
			$fromTable = '[|PREFIX|]products p';
		}

		if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "") {
			// Only need the product search table if we have a search query
			$joinQuery .= "INNER JOIN [|PREFIX|]product_search ps ON (p.productid=ps.productid) ";
		} else if ($sortField == "score") {
			// If we don't, we better make sure we're not sorting by score
			$sortField = "p.prodname";
			$sortOrder = "ASC";
		}

		$joinQuery .= "LEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1) ";

		$queryWhere[] = "p.prodvisible='1'";

		// Add in the group category restrictions
		$permissionSql = GetProdCustomerGroupPermissionsSQL(null, false);
		if($permissionSql) {
			$queryWhere[] = $permissionSql;
		}

		// Do we need to filter on brand?
		if (isset($searchTerms['brand']) && $searchTerms['brand'] != "") {
			$brand_id = (int)$searchTerms['brand'];
			$queryWhere[] = "p.prodbrandid='" . $GLOBALS['ISC_CLASS_DB']->Quote($brand_id) . "'";
		}

		// Do we need to filter on price?
		if (isset($searchTerms['price'])) {
			$queryWhere[] = "p.prodcalculatedprice='".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price'])."'";
		} else {
			if (isset($searchTerms['price_from']) && is_numeric($searchTerms['price_from'])) {
				$queryWhere[] = "p.prodcalculatedprice >= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_from'])."'";
			}

			if (isset($searchTerms['price_to']) && is_numeric($searchTerms['price_to'])) {
				$queryWhere[] = "p.prodcalculatedprice <= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_to'])."'";
			}
		}

		// Do we need to filter on rating?
		if (isset($searchTerms['rating'])) {
			$queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) = '".(int)$searchTerms['rating']."'";
		}
		else {
			if (isset($searchTerms['rating_from']) && is_numeric($searchTerms['rating_from'])) {
				$queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) >= '".(int)$searchTerms['rating_from']."'";
			}

			if (isset($searchTerms['rating_to']) && is_numeric($searchTerms['rating_to'])) {
				$queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) <= '".(int)$searchTerms['rating_to']."'";
			}
		}

		// Do we need to filter on featured?
		if (isset($searchTerms['featured']) && $searchTerms['featured'] != "") {
			$featured = (int)$searchTerms['featured'];

			if ($featured == 1) {
				$queryWhere[] = "p.prodfeatured=1";
			}
			else {
				$queryWhere[] = "p.prodfeatured=0";
			}
		}

		// Do we need to filter on free shipping?
		if (isset($searchTerms['shipping']) && $searchTerms['shipping'] != "") {
			$shipping = (int)$searchTerms['shipping'];

			if ($shipping == 1) {
				$queryWhere[] = "p.prodfreeshipping='1' ";
			}
			else {
				$queryWhere[] = "p.prodfreeshipping='0' ";
			}
		}

		// Do we need to filter only products we have in stock?
		if (isset($searchTerms['instock']) && $searchTerms['instock'] != "") {
			$stock = (int)$searchTerms['instock'];
			if ($stock == 1) {
				$queryWhere[] = "(p.prodcurrentinv>0 or p.prodinvtrack=0) ";
			}
		}

		if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "") {
			$termQuery = "(" . $GLOBALS['ISC_CLASS_DB']->FullText($fulltext_fields, $searchTerms['search_query'], true);
			$termQuery .= "OR ps.prodname like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
			$termQuery .= "OR ps.proddesc like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
			$termQuery .= "OR ps.prodsearchkeywords like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
			$termQuery .= "OR ps.prodcode = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "') ";
			$queryWhere[] = $termQuery;
		}

		if (!is_array($sortField)) {
			$sortField = array($sortField);
		}

		if (!is_array($sortOrder)) {
			$sortOrder = array($sortOrder);
		}

		$sortField = array_filter($sortField);
		$sortOrder = array_filter($sortOrder);

		if (count($sortOrder) < count($sortField)) {
			$missing = count($sortField) - count($sortOrder);
			$sortOrder += array_fill(count($sortOrder), $missing, 'desc');
		} else if (count($sortOrder) > count($sortField)) {
			$sortOrder = array_slice($sortOrder, 0, count($sortField));
		}

		if (!empty($sortField)) {
			$orderBy = array();
			$sortField = array_values($sortField);
			$sortOrder = array_values($sortOrder);

			foreach ($sortField as $key => $field) {
				$orderBy[] = $field . ' ' . $sortOrder[$key];
			}

			$orderBy = ' ORDER BY ' . implode(',', $orderBy);
		} else {
			$orderBy = '';
		}

		$query = "
			SELECT ".$fields."
			FROM ".$fromTable."
			".$joinQuery."
			WHERE 1=1 AND ".implode(' AND ', $queryWhere).$orderBy;

		$countQuery = "
			SELECT COUNT(p.productid)
			FROM ".$fromTable."
			".$joinQuery."
			WHERE 1=1 AND ".implode(' AND ', $queryWhere);

		return array(
			'query' => $query,
			'countQuery' => $countQuery
		);
	}
Ejemplo n.º 19
0
 /**
  * Set the panel settings.
  */
 public function SetPanelSettings()
 {
     $cVendor = GetClass('ISC_VENDORS');
     $vendor = $cVendor->GetVendor();
     $GLOBALS['VendorId'] = $vendor['vendorid'];
     $GLOBALS['VendorName'] = $vendor['vendorname'];
     // Set the field we're sorting results by
     if (isset($_REQUEST['sort'])) {
         $sort = $_REQUEST['sort'];
     } else {
         $sort = '';
     }
     switch ($sort) {
         case 'newest':
             $sortField = 'p.productid DESC';
             $GLOBALS['SortNewestSelected'] = 'selected="selected"';
             break;
         case 'bestselling':
             $sortField = 'p.prodnumsold DESC';
             $GLOBALS['SortBestSellingSelected'] = 'selected="selected"';
             break;
         case 'alphaasc':
             $sortField = 'p.prodname ASC';
             $GLOBALS['SortAlphaAsc'] = 'selected="selected"';
             break;
         case 'alphadesc':
             $sortField = 'p.prodname DESC';
             $GLOBALS['SortAlphaDesc'] = 'selected="selected"';
             break;
         case 'avgcustomerreview':
             $sortField = 'prodavgrating DESC';
             $GLOBALS['SortAvgReview'] = 'selected="selected"';
             break;
         case 'priceasc':
             $sortField = 'p.prodcalculatedprice ASC';
             $GLOBALS['SortPriceAsc'] = 'selected="selected"';
             break;
         case 'pricedesc':
             $sortField = 'p.prodcalculatedprice DESC';
             $GLOBALS['SortPriceDesc'] = 'selected="selected"';
             break;
         default:
             $sortField = 'p.prodvendorfeatured DESC';
             $sort = 'featured';
             $GLOBALS['SortFeaturedSelected'] = 'selected="selected"';
             break;
     }
     // If we're viewing a certain page, fetch our starting position
     if (isset($_REQUEST['page']) && IsId($_REQUEST['page'])) {
         $page = (int) $_REQUEST['page'];
         $start = $page * GetConfig('CategoryProductsPerPage') - GetConfig('CategoryProductsPerPage');
     } else {
         $page = 1;
         $start = 0;
     }
     // Count the number of products that belong in this vendor
     $query = "\n\t\t\tSELECT COUNT(p.productid) AS numproducts\n\t\t\tFROM [|PREFIX|]products p\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\tWHERE p.prodvisible='1' AND p.prodvendorid='" . (int) $vendor['vendorid'] . "'\n\t\t";
     $numProducts = $GLOBALS['ISC_CLASS_DB']->FetchOne($query);
     $numPages = ceil($numProducts / GetConfig('CategoryProductsPerPage'));
     // Now load the actual products for this vendor
     $query = "\n\t\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND imageisthumb=1)\n\t\t\t\tWHERE prodvisible='1' AND p.prodvendorid='" . (int) $vendor['vendorid'] . "'\n\t\t\t\tORDER BY " . $sortField . ", prodname ASC\n\t\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($start, GetConfig('CategoryProductsPerPage'));
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $GLOBALS['SNIPPETS']['VendorProducts'] = '';
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     // Should we show the compare button?
     if (GetConfig('EnableProductComparisons') == 0 || $numProducts < 2) {
         $GLOBALS['HideCompareItems'] = "none";
     } else {
         $GLOBALS['CompareLink'] = CompareLink();
     }
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         $GLOBALS['ProductId'] = (int) $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
             $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
             $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
         } else {
             $GLOBALS['ProductURL'] = CartLink($row['productid']);
             $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
         }
         if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
             $GLOBALS['HideActionAdd'] = '';
         } else {
             $GLOBALS['HideActionAdd'] = 'none';
         }
         $GLOBALS['HideProductVendorName'] = 'display: none';
         $GLOBALS['ProductVendor'] = '';
         if (GetConfig('ShowProductVendorNames') && $row['prodvendorid'] > 0) {
             $vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
             if (isset($vendorCache[$row['prodvendorid']])) {
                 $GLOBALS['ProductVendor'] = '<a href="' . VendorLink($vendorCache[$row['prodvendorid']]) . '">' . isc_html_escape($vendorCache[$row['prodvendorid']]['vendorname']) . '</a>';
                 $GLOBALS['HideProductVendorName'] = '';
             }
         }
         $GLOBALS['SNIPPETS']['VendorProducts'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("VendorProductsItem");
     }
     // Does paging need to be shown?
     if ($numProducts > GetConfig('CategoryProductsPerPage')) {
         $GLOBALS['SNIPPETS']['PagingData'] = "";
         $numEitherSide = 5;
         $start = max($page - $numEitherSide, 1);
         $end = min($page + $numEitherSide, $numPages);
         for ($i = $start; $i <= $end; $i++) {
             if ($i == $page) {
                 $snippet = "CategoryPagingItemCurrent";
             } else {
                 $snippet = "CategoryPagingItem";
             }
             $pageData = array('page' => $i, 'sort' => $sort);
             $GLOBALS['PageLink'] = VendorProductsLink($vendor, $pageData);
             $GLOBALS['PageNumber'] = $i;
             $GLOBALS['SNIPPETS']['PagingData'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet($snippet);
         }
         // Do we need to output a "Previous" link?
         if ($page > 1) {
             $pageData = array('page' => $page - 1, 'sort' => $sort);
             $GLOBALS['PrevLink'] = VendorProductsLink($vendor, $pageData);
             $GLOBALS['SNIPPETS']['CategoryPagingPrevious'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPagingPrevious");
         }
         // Do we need to output a "Next" link?
         if ($page < $numPages) {
             $pageData = array('page' => $page + 1, 'sort' => $sort);
             $GLOBALS['NextLink'] = VendorProductsLink($vendor, $pageData);
             $GLOBALS['SNIPPETS']['CategoryPagingNext'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPagingNext");
         }
         $output = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategoryPaging");
         $output = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseSnippets($output, $GLOBALS['SNIPPETS']);
         $GLOBALS['SNIPPETS']['ProductPaging'] = $output;
     }
     // Parse the sort select box snippet
     if ($numProducts > 1) {
         // Parse the sort select box snippet
         if ($GLOBALS['EnableSEOUrls'] == 1 && $vendor['vendorfriendlyname']) {
             $GLOBALS['URL'] = VendorProductsLink($vendor);
         } else {
             $GLOBALS['URL'] = $GLOBALS['ShopPath'] . "/vendors.php";
             $GLOBALS['HiddenSortField'] = "<input type=\"hidden\" name=\"vendorid\" value=\"" . (int) $vendor['vendorid'] . "\" />";
             $GLOBALS['HiddenSortField'] .= "<input type=\"hidden\" name=\"action\" value=\"products\" />";
         }
         $GLOBALS['SNIPPETS']['CategorySortBox'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CategorySortBox");
     }
 }
Ejemplo n.º 20
0
		/**
		*	Get a list of items in this customer's wishlist by wish list token
		*/
		private function _GetWishListItemsByToken($wishlisttoken="")
		{
			$items = array();

			$query = "
				SELECT wi.wishlistitemid, p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL()."
				FROM  [|PREFIX|]wishlists w
				LEFT JOIN [|PREFIX|]wishlist_items wi ON (w.wishlistid=wi.wishlistid)
				INNER JOIN [|PREFIX|]products p ON (wi.productid=p.productid)
				LEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)
				WHERE w.wishlisttoken='".$GLOBALS['ISC_CLASS_DB']->Quote($wishlisttoken)."'
				".GetProdCustomerGroupPermissionsSQL()."
			";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

			while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				array_push($items, $row);
			}
			return $items;
		}
Ejemplo n.º 21
0
/**
 * Build an SQL query for the specified search terms.
 *
 * @param array Array of search terms
 * @param string String of fields to match
 * @param string The field to sort by
 * @param string The order to sort results by
 * @return array An array containing the query to count the number of results and a query to perform the search
 */
function BuildProductSearchQuery($searchTerms, $fields = "", $sortField = array("score", "proddateadded"), $sortOrder = "desc")
{
    $queryWhere = array();
    $joinQuery = '';
    $queryWhere1 = array();
    $joinQuery1 = '';
    $qualifier_flag = 0;
    $qualifier_category = 0;
    $v_cols = array();
    $p_cols = array();
    /*$q_qry = "select * from isc_import_variations limit 0,1";
    	 $q_res = $GLOBALS['ISC_CLASS_DB']->Query($q_qry);
    	 $q_row = $GLOBALS['ISC_CLASS_DB']->Fetch($q_res);
    	 foreach($q_row as $q_key => $q_val)
    	 {
    	 if(eregi('^(vq)', $q_key)) {
    	 $v_cols[] = $q_key;
    	 } else if(eregi('^(pq)', $q_key)) {
    	 $p_cols[] = $q_key;
    	 }
    	 }*/
    $v_cols = isset($GLOBALS['sidev_cols']) ? $GLOBALS['sidev_cols'] : array();
    $p_cols = isset($GLOBALS['sidep_cols']) ? $GLOBALS['sidep_cols'] : array();
    $common_fields_product = " b.callbestprice bbestprice, c.callbestprice cbestprice, bs.callbestprice sbestprice,p.prodcode, p.productid , b.brandname , c.categoryid, c.catname , c.catuniversal,csi.icon_file ";
    $common_fields_variation = " p.prodcode, v.productid, v.prodstartyear, v.prodendyear , v.prodmodel, v.prodsubmodel, v.prodmake ";
    $new_fields = " p.proddesc , p.prodname , p.proddescfeature , prodwarranty , p.prodvariationid,p.prodconfigfields,p.prodeventdaterequired,p.prodvendorid,p.prodprice,p.prodretailprice,p.prodsaleprice,p.prodistaxable,p.prodcatids,p.prodhideprice,p.prodinvtrack,p.prodcurrentinv,p.prodallowpurchases,p.prodbrandid,p.prodcalculatedprice,prodweight,prodheight ";
    // Construct the full text search part of the query
    /*$fulltext_fields = array("ps.prodname", "ps.prodcode", "ps.proddesc", "ps.prodsearchkeywords", "ps.prodalternates", "ps.prodmake", "ps.prodmodel", "ps.prodsubmodel", "ps.prodstartyear", "ps.prodendyear");*/
    $fulltext_fields = array("ps.prodname", "ps.prodcode", "ps.proddesc", "ps.prodsearchkeywords");
    if (!$fields) {
        $fields = "{$new_fields}, FLOOR(p.prodratingtotal/p.prodnumratings) AS prodavgrating, " . GetProdCustomerGroupPriceSQL() . ", ";
        $fields .= "pi.imageisthumb, pi.imagefile ";
        if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "") {
            //$fields .= ', '.$GLOBALS['ISC_CLASS_DB']->FullText($fulltext_fields, $searchTerms['search_query'], false) . " as score ";
        }
    }
    $fields1 = $fields . " ,v. " . implode(",v.", $v_cols);
    //$fields .= " ,v. ".implode(",v. ",$v_cols).", group_concat(distinct PQcolor,', ',PQmaterial,', ',PQstyle separator '~') as productoption ";
    //$fields .= " , group_concat(distinct PQcolor,', ',PQmaterial,', ',PQstyle separator '~') as productoption ";
    if (isset($searchTerms['categoryid'])) {
        $searchTerms['category'] = array($searchTerms['categoryid']);
    }
    // If we're searching by category, we need to completely
    // restructure the search query - so do that first
    $categorySearch = false;
    $categoryIds = array();
    if (isset($searchTerms['category']) && is_array($searchTerms['category'])) {
        foreach ($searchTerms['category'] as $categoryId) {
            // All categories were selected, so don't continue
            if ($categoryId == 0) {
                $categorySearch = false;
                break;
            }
            $categoryIds[] = (int) $categoryId;
            // If searching sub categories automatically, fetch & tack them on
            if (isset($searchTerms['searchsubs']) && $searchTerms['searchsubs'] == 'ON') {
                $categoryIds = array_merge($categoryIds, GetChildCats($categoryId));
            }
        }
        $categoryIds = array_unique($categoryIds);
        if (!empty($categoryIds)) {
            $categorySearch = true;
        }
    }
    /* this below is condition is used when category is mentioned in search keyword */
    if (isset($searchTerms['srch_category'])) {
        $categorySearch = true;
        $categoryIds = $searchTerms['srch_category'];
    }
    if ($categorySearch == true) {
        $qualifier_category = 1;
        $qualifier_flag = 1;
        /*$fromTable = 'isc_categoryassociations a, isc_products p ';
        			$queryWhere[] = 'a.productid=p.productid AND a.categoryid IN ('.implode(',', $categoryIds).')';
        
        			$fromTable1 = 'isc_categoryassociations a, isc_import_variations v ';
        			$queryWhere1[] = 'a.productid=v.productid AND a.categoryid IN ('.implode(',', $categoryIds).')';*/
        if ($searchTerms['flag_srch_category'] == 1) {
            $fromTable = 'isc_products p USE INDEX (PRIMARY) ';
        } else {
            $fromTable = 'isc_products p ';
        }
        //            $fromTable = 'isc_products p USE INDEX (categoryid) ';
        $queryWhere[] = 'c.categoryid IN (' . implode(',', $categoryIds) . ')';
        $fromTable1 = 'isc_import_variations v ';
        $queryWhere1[] = 'c.categoryid IN (' . implode(',', $categoryIds) . ')';
    } else {
        $fromTable = 'isc_products p';
        $fromTable1 = 'isc_import_variations v';
        $queryWhere[] = " c.categoryid is not null ";
    }
    /*  this code is commented as we are no longer checking in search table as the records are split in product and variations table.
    		if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "") {
    		// Only need the product search table if we have a search query
    		$joinQuery .= "INNER JOIN [|PREFIX|]product_search ps ON (p.productid=ps.productid) ";
    		} else if ($sortField == "score") {
    		// If we don't, we better make sure we're not sorting by score
    		$sortField = "p.prodname";
    		$sortOrder = "ASC";
    		}
    		*/
    /* Below condition has been added if any product detail page is seen directly , need to assign it as array */
    if (!isset($searchTerms['dynfilters'])) {
        $searchTerms['dynfilters'] = array();
    }
    $otherkeys = array_keys($searchTerms['dynfilters'], "others");
    $others_factor = '';
    /*
    if ( isset($searchTerms['partnumber']) || ( isset($searchTerms['flag_srch_category']) && $searchTerms['flag_srch_category'] == 1 ) || (isset($searchTerms['flag_srch_brand']) &&  $searchTerms['flag_srch_brand'] == 1 ) || isset($searchTerms['series']) || isset($searchTerms['subcategory']) )
    {
    // listing page
    }
    else
    {
    foreach ($otherkeys as $otherkey)  {
    //$others_factor .= " AND (".$otherkey." = '' OR ".$otherkey." IS NULL )";
    $others_factor .= " AND (".$otherkey." = '' OR ".$otherkey." IS NULL )";
    }
    }
    */
    $partnumber_condition = "";
    if (!isset($searchTerms['partnumber'])) {
        //$partnumber_condition = "and c.catvisible = 1 ";
    }
    $joinQuery .= " LEFT JOIN [|PREFIX|]import_variations AS v ON v.productid = p.productid " . $others_factor . "\n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]categoryassociations ca on ca.productid = p.productid \n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]categories c on c.categoryid = ca.categoryid " . $partnumber_condition . " \n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]brands b on prodbrandid = b.brandid \n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]brand_series AS bs ON bs.seriesid = p.brandseriesid \n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)\n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]product_finalprice fp ON p.productid = fp.productid\n\t\t\t\t\t\tLEFT JOIN [|PREFIX|]prodcut_cap_size_images csi ON p.prodcode = csi.productcode and p.prodvendorprefix = csi.vendor_prix ";
    $joinQuery1 .= " LEFT JOIN [|PREFIX|]import_variations AS v ON v.productid = p.productid " . $others_factor . "\n\t\t\t\t\t\t\tLEFT JOIN [|PREFIX|]categoryassociations ca on ca.productid = p.productid \n\t\t\t\t\t\t\tLEFT JOIN [|PREFIX|]categories c on c.categoryid = ca.categoryid " . $partnumber_condition . " \n\t\t\t\t\t\t\tLEFT JOIN [|PREFIX|]brands b on prodbrandid = b.brandid \n\t\t\t\t\t\t\tLEFT JOIN [|PREFIX|]brand_series AS bs ON bs.seriesid = p.brandseriesid ";
    $queryWhere1[] = $queryWhere[] = "p.prodvisible='1'";
    // Add in the group category restrictions
    $permissionSql = GetProdCustomerGroupPermissionsSQL(null, false);
    if ($permissionSql) {
        $queryWhere1[] = $queryWhere[] = $permissionSql;
    }
    // Do we need to filter on brand?
    if (isset($searchTerms['brand']) && $searchTerms['brand'] != "") {
        $brand_query = "select brandid from [|PREFIX|]brands WHERE brandname='" . $searchTerms['brand'] . "'";
        $brand_result = $GLOBALS['ISC_CLASS_DB']->Query($brand_query);
        $brandId = $GLOBALS['ISC_CLASS_DB']->FetchOne($brand_result);
        if ((int) $brandId > 0) {
            $qualifier_flag = 1;
            $queryWhere1[] = $queryWhere[] = "p.prodbrandid='" . $GLOBALS['ISC_CLASS_DB']->Quote($brandId) . "'";
        }
    }
    // Do we need to filter on brand series?
    if (isset($searchTerms['series']) && $searchTerms['series'] != "") {
        $qualifier_flag = 1;
        if (isset($GLOBALS['seriesid'])) {
            $brand_series_id = (int) $GLOBALS['seriesid'];
        } else {
            $series_qry = "select s.seriesid from isc_brand_series s where s.seriesname = '" . $searchTerms['series'] . "' ";
            $series_res = $GLOBALS['ISC_CLASS_DB']->Query($series_qry);
            $series_arr = $GLOBALS['ISC_CLASS_DB']->Fetch($series_res);
            $brand_series_id = (int) $series_arr['seriesid'];
        }
        $queryWhere1[] = $queryWhere[] = " p.brandseriesid = " . $GLOBALS['ISC_CLASS_DB']->Quote($brand_series_id);
    }
    if (isset($searchTerms['partnumber'])) {
        $qualifier_flag = 1;
        $prod_code = $searchTerms['partnumber'];
        $queryWhere1[] = $queryWhere[] = " p.prodcode like '" . $prod_code . "%'";
    }
    // Do we need to filter on price?
    if (isset($searchTerms['price'])) {
        $queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice='" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price']) . "'";
    } else {
        /*if (isset($searchTerms['price_from']) && is_numeric($searchTerms['price_from'])) {
        		 $queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice >= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_from'])."'";
        			}
        
        			if (isset($searchTerms['price_to']) && is_numeric($searchTerms['price_to'])) {
        			$queryWhere1[] = $queryWhere[] = "p.prodcalculatedprice <= '".$GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['price_to'])."'";
        			}*/
    }
    // Do we need to filter on rating?
    if (isset($searchTerms['rating'])) {
        $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) = '" . (int) $searchTerms['rating'] . "'";
    } else {
        if (isset($searchTerms['rating_from']) && is_numeric($searchTerms['rating_from'])) {
            $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) >= '" . (int) $searchTerms['rating_from'] . "'";
        }
        if (isset($searchTerms['rating_to']) && is_numeric($searchTerms['rating_to'])) {
            $queryWhere1[] = $queryWhere[] = "FLOOR(p.prodratingtotal/p.prodnumratings) <= '" . (int) $searchTerms['rating_to'] . "'";
        }
    }
    // Do we need to filter on featured?
    if (isset($searchTerms['featured']) && $searchTerms['featured'] != "") {
        $featured = (int) $searchTerms['featured'];
        if ($featured == 1) {
            $queryWhere1[] = $queryWhere[] = "p.prodfeatured=1";
        } else {
            $queryWhere1[] = $queryWhere[] = "p.prodfeatured=0";
        }
    }
    // Do we need to filter on free shipping?
    if (isset($searchTerms['shipping']) && $searchTerms['shipping'] != "") {
        $shipping = (int) $searchTerms['shipping'];
        if ($shipping == 1) {
            $queryWhere1[] = $queryWhere[] = "p.prodfreeshipping='1' ";
        } else {
            $queryWhere1[] = $queryWhere[] = "p.prodfreeshipping='0' ";
        }
    }
    // Do we need to filter only products we have in stock?
    if (isset($searchTerms['instock']) && $searchTerms['instock'] != "") {
        $stock = (int) $searchTerms['instock'];
        if ($stock == 1) {
            $queryWhere1[] = $queryWhere[] = "(p.prodcurrentinv>0 or p.prodinvtrack=0) ";
        }
    }
    // Do we need to filter for make of the product
    if (isset($searchTerms['make']) && $searchTerms['make'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
        $make = $searchTerms['make'];
        if (!empty($make)) {
            $qualifier_flag = 1;
            $ext = "";
            //if(isset($searchTerms['is_catg']))
            $ext .= " OR v.prodmake = 'NON-SPEC VEHICLE' ";
            $queryWhere[] = " ( v.prodmake = '" . $make . "' {$ext} ) ";
            $queryWhere1[] = " ( v.prodmake = '" . $make . "' {$ext} ) ";
        }
    }
    // Do we need to filter for model of the product
    if (isset($searchTerms['model']) && $searchTerms['model'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
        $model = $searchTerms['model'];
        if (!empty($model)) {
            $qualifier_flag = 1;
            $ext = "";
            //if(isset($searchTerms['is_catg']))
            $ext .= " OR v.prodmodel = 'ALL' ";
            //if(isset($_REQUEST['model'])) {
            if (!isset($searchTerms['model_flag']) || isset($searchTerms['model_flag']) && $searchTerms['model_flag'] == 1) {
                $queryWhere[] = " ( v.prodmodel = '" . $model . "' {$ext} ) ";
                $queryWhere1[] = " ( v.prodmodel = '" . $model . "' {$ext} ) ";
            } else {
                $queryWhere[] = " ( v.prodmodel like '" . $model . "%' {$ext} ) ";
                $queryWhere1[] = " ( v.prodmodel like '" . $model . "%' {$ext} ) ";
            }
        }
    }
    // Do we need to filter for submodel of the product
    if (isset($searchTerms['submodel']) && $searchTerms['submodel'] != "") {
        $submodel = $searchTerms['submodel'];
        if (!empty($model)) {
            $qualifier_flag = 1;
            $queryWhere[] = " ( v.prodsubmodel = '" . $submodel . "' OR v.prodsubmodel = '' ) ";
            $queryWhere1[] = " ( v.prodsubmodel = '" . $submodel . "' OR v.prodsubmodel = '' ) ";
        }
    }
    // Do we need to filter for year of the product
    if (isset($searchTerms['year']) && $searchTerms['year'] != "" && (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] != 1)) {
        $year = $searchTerms['year'];
        if (!empty($year)) {
            $qualifier_flag = 1;
            if (is_numeric($year)) {
                $ext = "";
                //if(isset($searchTerms['is_catg']))
                $ext .= " OR v.prodstartyear = 'ALL' ";
                $queryWhere[] = " ( " . $year . " between v.prodstartyear and v.prodendyear {$ext} ) ";
                $queryWhere1[] = " ( " . $year . " between v.prodstartyear and v.prodendyear {$ext} ) ";
            } else {
                $queryWhere[] = " ( v.prodstartyear = '{$year}' OR v.prodendyear = '{$year}' ) ";
                $queryWhere1[] = " ( v.prodstartyear = '{$year}' OR v.prodendyear = '{$year}' ) ";
            }
        }
    }
    /*if (isset($searchTerms['weight']) && $searchTerms['weight'] != "") {
    	 $weight = $searchTerms['weight'];
    	 if (!empty($year)) {
    	 $queryWhere[] = " p.prodweight = ".$weight;
    	 }
    	 }
    
    	 if (isset($searchTerms['height']) && $searchTerms['height'] != "") {
    	 $height = $searchTerms['height'];
    	 if (!empty($year)) {
    	 $queryWhere[] = " p.prodheight = ".$height;
    	 }
    	 }
    
    	 if (isset($searchTerms['brand']) && $searchTerms['brand'] != "") {
    	 $brand = $searchTerms['brand'];
    	 if (!empty($brand)) {
    	 $queryWhere[] = " p.prodbrandid = ".$brand;
    	 $queryWhere1[] = " p.prodbrandid = ".$brand;
    	 }
    	 }*/
    if (isset($searchTerms['price_from']) && isset($searchTerms['price_to'])) {
        $from_price = $searchTerms['price_from'];
        $to_price = $searchTerms['price_to'];
        if ($from_price != "" && $to_price != "") {
            $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice between " . $from_price . " and " . $to_price;
        }
    } else {
        if (isset($searchTerms['price_from'])) {
            $from_price = $searchTerms['price_from'];
            if (!empty($from_price)) {
                $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice >= " . $from_price;
            }
        } else {
            if (isset($searchTerms['price_to'])) {
                $to_price = $searchTerms['price_to'];
                if (!empty($to_price)) {
                    $queryWhere1[] = $queryWhere[] = " p.prodcalculatedprice <= " . $from_price;
                }
            }
        }
    }
    /* --------- these below coditions are commented as they now belongs to qualifiers table ------------
    	 if (isset($searchTerms['bedsize']) && $searchTerms['bedsize'] != "") {
    	 $bedsize = $searchTerms['bedsize'];
    	 if (!empty($bedsize)) {
    	 $queryWhere1[] = $queryWhere[] = " p.prodbedsize like '%".$bedsize."%'";
    	 }
    	 }
    
    	 if (isset($searchTerms['cabsize']) && $searchTerms['cabsize'] != "") {
    	 $cabsize = $searchTerms['cabsize'];
    	 if (!empty($cabsize)) {
    	 $queryWhere1[] = $queryWhere[] = " p.prodcabsize like '%".$cabsize."%'";
    	 }
    	 }
    
    	 if (isset($searchTerms['tracksystem']) && $searchTerms['tracksystem'] != "") {
    	 $tracksystem = $searchTerms['tracksystem'];
    	 if (!empty($tracksystem)) {
    	 $queryWhere1[] = $queryWhere[] = " p.truckbedtracksystemtype like '%".$tracksystem."%'";
    	 }
    	 }
    
    	 if (isset($searchTerms['material']) && $searchTerms['material'] != "") {
    	 $material = $searchTerms['material'];
    	 if (!empty($material)) {
    	 $queryWhere1[] = $queryWhere[] = " p.prodmaterial like '%".$material."%'";
    	 }
    	 }
    
    	 if (isset($searchTerms['style']) && $searchTerms['style'] != "") {
    	 $style = $searchTerms['style'];
    	 if (!empty($style)) {
    	 $queryWhere1[] = $queryWhere[] = " p.prodstyle like '%".$style."%'";
    	 }
    	 }
    
    	 if (isset($searchTerms['color']) && $searchTerms['color'] != "") {
    	 $color = $searchTerms['color'];
    	 if (!empty($color)) {
    	 $queryWhere1[] = $queryWhere[] = " p.prodcolor like '%".$color."%'";
    	 }
    	 }
    	 /*---------------------------------------------------------------------------------------------*/
    /*---- the below variables are used for displaying submodels in sideproductfilters.php --- */
    $GLOBALS['qualifiercategory'] = $qualifier_category;
    $GLOBALS['wherecondition'] = $queryWhere;
    $GLOBALS['wherecondition1'] = $queryWhere1;
    /*--------- creating conditions for dynamic filters----------*/
    $havingquery = array();
    $outer_condition = "";
    if (!empty($searchTerms['dynfilters'])) {
        $dynfilters = $searchTerms['dynfilters'];
        foreach ($dynfilters as $dynkey => $dynval) {
            $qualifier_flag = 1;
            $orgdynkey = $dynkey;
            //Added by Simha
            $str_to_check_pqvq = "";
            if (!isset($searchTerms['catuniversal']) || $searchTerms['catuniversal'] == 0) {
                $str_to_check_pqvq = '^(vq|pq)';
            } else {
                $str_to_check_pqvq = '^pq';
            }
            if (eregi($str_to_check_pqvq, $dynkey)) {
                $dynkey = " v.{$dynkey} ";
                //$outer_condition .= " AND $dynkey like '%".$dynval."%'";
                if ($dynval == 'others') {
                    $havingquery[] = "( {$orgdynkey} = '' OR {$orgdynkey} IS NULL OR {$orgdynkey} = '~' )";
                    // here included '~' as in left navi query will return ~
                } else {
                    if (strcasecmp($dynkey, ' v.VQbedsize ') == 0) {
                        $outer_condition .= " AND ( ( ( {$dynkey} = '" . $dynval . "') OR ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) ) OR ( ( v.bedsize_generalname = '" . $dynval . "' ) OR (  v.bedsize_generalname regexp ';' AND v.bedsize_generalname regexp '" . $dynval . "' ) ) ) ";
                    } else {
                        if (strcasecmp($dynkey, ' v.VQcabsize ') == 0) {
                            $outer_condition .= " AND ( ( ( {$dynkey} = '" . $dynval . "') OR ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) ) OR ( ( v.cabsize_generalname = '" . $dynval . "' ) OR (  v.cabsize_generalname regexp ';' AND v.cabsize_generalname regexp '" . $dynval . "' ) ) ) ";
                        } else {
                            $outer_condition .= " AND ( ( {$dynkey} regexp ';' AND {$dynkey} regexp '" . $dynval . "' ) OR ( {$dynkey} not regexp ';' AND {$dynkey} = '" . $dynval . "') )";
                        }
                    }
                }
            }
        }
    }
    if (isset($searchTerms['vqsbedsize'])) {
        $qualifier_flag = 1;
        $outer_condition .= " AND (  v.VQbedsize like '%" . $searchTerms['vqsbedsize'] . "%' OR  v.bedsize_generalname like '%" . $searchTerms['vqsbedsize'] . "%' ) ";
    }
    if (isset($searchTerms['vqscabsize'])) {
        $qualifier_flag = 1;
        $outer_condition .= " AND (  v.VQcabsize like '%" . $searchTerms['vqscabsize'] . "%' OR  v.cabsize_generalname like '%" . $searchTerms['vqscabsize'] . "%' ) ";
    }
    if (($qualifier_flag == 0 || isset($searchTerms['search'])) && (eregi('search.php', $_SERVER['REQUEST_URI']) || isset($GLOBALS['PathInfo']) && count($GLOBALS['PathInfo']) > 0) && !isset($_REQUEST['change'])) {
        //$joinQuery .= "INNER JOIN isc_product_search ps ON (p.productid=ps.productid)";
        //$joinQuery1 .= "INNER JOIN isc_product_search ps ON (p.productid=ps.productid)";
        if (isset($searchTerms['search_string'])) {
            $searchTerms['search_query'] = $searchTerms['search_string'];
        }
        if (isset($searchTerms['search_query']) && $searchTerms['search_query'] != "" && $searchTerms['search_query'] != "categories" && $searchTerms['search_query'] != "brands") {
            //$termQuery = "(" . $GLOBALS['ISC_CLASS_DB']->FullText($fulltext_fields, $searchTerms['search_query'], true);
            //$termQuery = " ( ";
            $termQuery = " p.prodname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "' ";
            //$termQuery .= " p.prodname like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            /*$termQuery .= "OR p.proddesc like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR p.prodsearchkeywords like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodalternates like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodmake like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodmodel like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodsubmodel like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodstartyear like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR ps.prodendyear like '%" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "%' ";
            	 $termQuery .= "OR p.prodcode = '" . $GLOBALS['ISC_CLASS_DB']->Quote($searchTerms['search_query']) . "') ";*/
            $queryWhere1[] = $queryWhere[] = $termQuery;
        }
    }
    if (!is_array($sortField)) {
        $sortField = array($sortField);
    }
    if (!is_array($sortOrder)) {
        $sortOrder = array($sortOrder);
    }
    $sortField = array_filter($sortField);
    $sortOrder = array_filter($sortOrder);
    if (count($sortOrder) < count($sortField)) {
        $missing = count($sortField) - count($sortOrder);
        $sortOrder += array_fill(count($sortOrder), $missing, 'desc');
    } else {
        if (count($sortOrder) > count($sortField)) {
            $sortOrder = array_slice($sortOrder, 0, count($sortField));
        }
    }
    if (!empty($sortField)) {
        $orderBy = array();
        $sortField = array_values($sortField);
        $sortOrder = array_values($sortOrder);
        foreach ($sortField as $key => $field) {
            $orderBy[] = $field . ' ' . $sortOrder[$key];
        }
        $orderBy = ' ORDER BY ' . implode(',', $orderBy);
    } else {
        $orderBy = '';
    }
    $orderBy = '';
    /* the below query is used to check whether any series exist under the selected brand */
    if (isset($searchTerms['flag_srch_brand']) && $searchTerms['flag_srch_brand'] == 0) {
        $brand_series_qry = "select p.brandseriesid from isc_products p LEFT JOIN isc_categoryassociations ca on ca.productid = p.productid LEFT JOIN isc_categories c on c.categoryid = ca.categoryid LEFT JOIN isc_import_variations AS v ON p.productid = v.productid\nWHERE prodbrandid = " . $brandId . " and brandseriesid != 0  " . GetWhereWithAnd($queryWhere) . " {$outer_condition} group by brandseriesid";
        $brand_series_res = $GLOBALS['ISC_CLASS_DB']->Query($brand_series_qry);
        if ($GLOBALS['ISC_CLASS_DB']->CountResult($brand_series_res) > 0) {
            $GLOBALS['BRAND_SERIES_FLAG'] = 0;
        } else {
            $GLOBALS['BRAND_SERIES_FLAG'] = 1;
        }
        // series not exist under a brand
    }
    $qualifiers_where = "";
    ##Added by Simha // for "others" values in qualifier filters
    //$otherkeys = array_keys($searchTerms['dynfilters'], "others");
    $extrasearch = '';
    foreach ($p_cols as $key => $value) {
        if (in_array($value, $otherkeys)) {
            $extrasearch .= ',MAX(' . $value . ') as ' . $value . '';
            unset($p_cols[$key]);
            $p_cols = array_values($p_cols);
        }
    }
    foreach ($v_cols as $key => $value) {
        if (in_array($value, $otherkeys)) {
            $extrasearch .= ',MAX(' . $value . ') as ' . $value . '';
            unset($v_cols[$key]);
            $v_cols = array_values($v_cols);
        }
    }
    ##Added by Simha Ends
    $v_cols_new = '';
    $p_cols_new = '';
    if (empty($p_cols)) {
        $p_cols_new = " '' as productoption ";
    } else {
        //$p_cols = " CONCAT_WS('~',".implode(' , ' , $p_cols).") as productoption ";
        //$p_cols = implode(' , ' , $p_cols);
        for ($k = 0; $k < count($p_cols); $k++) {
            //$p_cols = implode(' , ' , $p_cols);
            $p_cols_new .= " group_concat(DISTINCT " . $p_cols[$k] . " separator '~') as " . $p_cols[$k] . " ,";
        }
    }
    if (empty($v_cols)) {
        $v_cols_new = " '' as vehicleoption ";
    } else {
        //$v_cols = " CONCAT_WS('~',".implode(' , ' , $v_cols).") as vehicleoption ";
        //$v_cols = implode(' , ' , $v_cols);
        for ($k = 0; $k < count($v_cols); $k++) {
            //$p_cols = implode(' , ' , $p_cols);
            //2010-11-15 Ronnie modify,VQcabsize,VQbedsize not is Special
            /*if(	$v_cols[$k] == 'VQbedsize' )
            		{
            		$v_cols_new .= " group_concat( DISTINCT if( v.bedsize_generalname != '', v.bedsize_generalname, v.VQbedsize ) separator '~' ) as VQbedsize ,";
            		}
            		else if( $v_cols[$k] == 'VQcabsize' )
            		{
            		//$v_cols_new .= " group_concat( DISTINCT if( v.cabsize_generalname != '', v.cabsize_generalname, v.VQcabsize ) separator '~' ) as VQcabsize ,";
            		$v_cols_new .= " group_concat( DISTINCT  v.VQcabsize  separator '~' ) as VQcabsize ,";
            		}
            		else
            		{*/
            $v_cols_new .= " group_concat(DISTINCT " . $v_cols[$k] . " separator '~') as " . $v_cols[$k] . " ,";
            //}
        }
    }
    $v_cols_new = trim($v_cols_new, ',');
    $p_cols_new = trim($p_cols_new, ',');
    //lguan_20100612: Added rating into select fields list
    if (isset($searchTerms['flag_srch_brand']) && $GLOBALS['BRAND_SERIES_FLAG'] == 0 && (!isset($searchTerms['srch_category']) || isset($searchTerms['category'])) && !isset($searchTerms['partnumber'])) {
        $GLOBALS['srch_where'] = "c.catname , c.categoryid , c.catuniversal , group_concat(DISTINCT ca.categoryid separator '~') as subcatgids , pa.catname as parentcatname , group_concat(DISTINCT brandname separator '~') as brandname , min(fp.prodfinalprice) as prodminprice , max(fp.prodfinalprice) as prodmaxprice , bs.seriesphoto as imagefile , p.proddesc , prodwarranty , bs.seriesname, bs.displayname, p.brandseriesid , count(distinct p.productid) as totalproducts , bs.feature_points1 , bs.feature_points2 , bs.feature_points3 , bs.feature_points4 , bs.feature_points , bs.seriesimagealt ,  b.brandimagefile , b.brandlargefile , b.branddescription , b.brandfooter, bs.serieshoverimagefile,floor(SUM(p.prodratingtotal)/SUM(p.prodnumratings)) AS prodavgrating ";
        $joinQuery .= "LEFT JOIN isc_categories pa on pa.categoryid = c.catparentid";
        $orderBy = ' ORDER BY bs.seriessort ASC , bs.seriesname ASC ';
        $queryWhere1[] = $queryWhere[] = " p.brandseriesid != 0 ";
        if (!empty($havingquery)) {
            $queryWhere1[] = $queryWhere[] = implode(' AND ', $havingquery);
            unset($havingquery);
            $extrasearch = "";
        }
    } else {
        if (isset($searchTerms['flag_srch_category']) && $searchTerms['flag_srch_category'] == 0 && (!isset($GLOBALS['BRAND_SERIES_FLAG']) || isset($GLOBALS['BRAND_SERIES_FLAG']) && $GLOBALS['BRAND_SERIES_FLAG'] == 0) && !isset($searchTerms['partnumber'])) {
            //wirror_20100809: add a return field for custom category filter
            //wirror_20101011: remove the group_concat products
            $GLOBALS['srch_where'] = "c.catname , c.categoryid , c.catuniversal , c.catimagealt , c.featurepoints , group_concat(DISTINCT brandname separator '~') as brandname , group_concat(DISTINCT p.brandseriesid separator '~') as seriesids , min(fp.prodfinalprice) as prodminprice , max(fp.prodfinalprice) as prodmaxprice , c.catimagefile as imagefile , c.cathoverimagefile , p.proddesc , prodwarranty , bs.seriesname, bs.displayname, p.brandseriesid , count(distinct p.productid) as totalproducts,floor(SUM(p.prodratingtotal)/SUM(p.prodnumratings)) AS prodavgrating ";
            $orderBy = ' ORDER BY c.catdeptid ASC, c.catsort ASC, c.catname ASC ';
            if (!empty($havingquery)) {
                $queryWhere1[] = $queryWhere[] = implode(' AND ', $havingquery);
                unset($havingquery);
                $extrasearch = "";
            }
        } else {
            $GLOBALS['srch_where'] = $common_fields_product . "," . $fields . " , {$p_cols_new} , {$v_cols_new} , bs.seriesname, bs.displayname, p.brandseriesid , bs.seriesdescription ,  bs.seriesfooter , b.brandimagefile, bs.serieslogoimage ";
            $GLOBALS['srch_where'] .= $extrasearch;
        }
    }
    $query = "select " . $GLOBALS['srch_where'] . " from\n\t{$fromTable} {$joinQuery} WHERE 1=1  " . GetWhereWithAnd($queryWhere) . " {$outer_condition} ";
    $countQuery = "SELECT count(p.productid) " . $extrasearch . " FROM {$fromTable}\n\t{$joinQuery1} WHERE 1=1 " . GetWhereWithAnd($queryWhere) . " {$outer_condition} ";
    //wirror_yin20101102: put the join statement to $_GLOBALS
    $GLOBALS['join_query'] = $joinQuery;
    if (isset($havingquery) && count($havingquery) > 0) {
        $GLOBALS['having_query'] = " HAVING (" . implode(' AND ', $havingquery) . ")";
    } else {
        $GLOBALS['having_query'] = '';
    }
    return array('query' => $query, 'countQuery' => $countQuery, 'orderby' => $orderBy);
}
Ejemplo n.º 22
0
 /**
  * Set the panel settings.
  */
 public function SetPanelSettings()
 {
     if (GetConfig('HomeFeaturedProducts') <= 0) {
         $this->DontDisplay = true;
         return false;
     }
     $GLOBALS['SNIPPETS']['VendorFeaturedItems'] = '';
     if (GetConfig('EnableProductReviews') == 0) {
         $GLOBALS['HideProductRating'] = "display: none";
     }
     $cVendor = GetClass('ISC_VENDORS');
     $vendor = $cVendor->GetVendor();
     $query = "\n\t\t\tSELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, imageisthumb, imagefile, " . GetProdCustomerGroupPriceSQL() . "\n\t\t\tFROM [|PREFIX|]products p\n\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND imageisthumb=1)\n\t\t\tWHERE p.prodvisible='1' AND p.prodvendorid='" . (int) $vendor['vendorid'] . "'\n\t\t\t" . GetProdCustomerGroupPermissionsSQL() . "\n\t\t\tORDER BY p.prodvendorfeatured DESC, RAND()\n\t\t";
     $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, GetConfig('HomeFeaturedProducts'));
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $GLOBALS['AlternateClass'] = '';
     while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
         if ($GLOBALS['AlternateClass'] == 'Odd') {
             $GLOBALS['AlternateClass'] = 'Even';
         } else {
             $GLOBALS['AlternateClass'] = 'Odd';
         }
         $GLOBALS['ProductCartQuantity'] = '';
         if (isset($GLOBALS['CartQuantity' . $row['productid']])) {
             $GLOBALS['ProductCartQuantity'] = (int) $GLOBALS['CartQuantity' . $row['productid']];
         }
         $GLOBALS['ProductId'] = $row['productid'];
         $GLOBALS['ProductName'] = isc_html_escape($row['prodname']);
         $GLOBALS['ProductLink'] = ProdLink($row['prodname']);
         // Determine the price of this product
         $GLOBALS['ProductPrice'] = CalculateProductPrice($row);
         $GLOBALS['ProductRating'] = (int) $row['prodavgrating'];
         // Workout the product description
         $desc = strip_tags($row['proddesc']);
         if (isc_strlen($desc) < 120) {
             $GLOBALS['ProductSummary'] = $desc;
         } else {
             $GLOBALS['ProductSummary'] = isc_substr($desc, 0, 120) . "...";
         }
         $GLOBALS['ProductThumb'] = ImageThumb($row['imagefile'], ProdLink($row['prodname']));
         if (isId($row['prodvariationid']) || trim($row['prodconfigfields']) != '' || $row['prodeventdaterequired'] == 1) {
             $GLOBALS['ProductURL'] = ProdLink($row['prodname']);
             $GLOBALS['ProductAddText'] = GetLang('ProductChooseOptionLink');
         } else {
             $GLOBALS['ProductURL'] = CartLink($row['productid']);
             $GLOBALS['ProductAddText'] = GetLang('ProductAddToCartLink');
         }
         if (CanAddToCart($row) && GetConfig('ShowAddToCartLink')) {
             $GLOBALS['HideActionAdd'] = '';
         } else {
             $GLOBALS['HideActionAdd'] = 'none';
         }
         $GLOBALS['HideProductVendorName'] = 'display: none';
         $GLOBALS['ProductVendor'] = '';
         if (GetConfig('ShowProductVendorNames') && $row['prodvendorid'] > 0) {
             $vendorCache = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('Vendors');
             if (isset($vendorCache[$row['prodvendorid']])) {
                 $GLOBALS['ProductVendor'] = '<a href="' . VendorLink($vendorCache[$row['prodvendorid']]) . '">' . isc_html_escape($vendorCache[$row['prodvendorid']]['vendorname']) . '</a>';
                 $GLOBALS['HideProductVendorName'] = '';
             }
         }
         $GLOBALS['SNIPPETS']['VendorFeaturedItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("VendorFeaturedItemsItem");
     }
     $GLOBALS['VendorProductsLink'] = VendorProductsLink($vendor);
     if (!$GLOBALS['SNIPPETS']['VendorFeaturedItems']) {
         $this->DontDisplay = true;
     }
 }