コード例 #1
0
ファイル: CKeywordSearch.php プロジェクト: kingsj/zeuscart
 /**
  * This function is used to find  the narrow search
  * @param integer $sort
  * @param string $mode
  * @return string
  */
 function narrowSearch($sort, $mode)
 {
     if ($_SESSION['subcategory'] != '') {
         $id = $_SESSION['subcategory'];
         $mycat = " a.category_id=" . $id . ' and ';
     } elseif ($_SESSION['category'] != "") {
         $id = $_SESSION['category'];
         $mycat = " b.category_parent_id=" . $id . ' and ';
     }
     if ($id == -1) {
         $mycat = "";
     }
     $ob = new Core_CKeywordSearch();
     $categoryname = $ob->categoryName($id);
     $head = $_GET['head'];
     $attib_value_id = $_GET['attrib_value_id'];
     $brand = $_GET['brand'];
     if ((int) $attib_value_id > 0) {
         $_SESSION['selectedbrand'] = 'You have Selected <b>' . $categoryname . '</b> >><b> ' . $subcategoryname . '</b>>><b>' . $head . '</b>';
     } elseif (count($brand) > 0) {
         $_SESSION['selectedbrand'] = 'You have Selected <b>' . $categoryname . '</b> >><b> ' . $subcategoryname . '</b>';
     }
     $pagesize = 10;
     if (isset($_GET['page'])) {
         $start = trim($_GET['page'] - 1) * $pagesize;
         $end = $pagesize;
     } else {
         $start = 0;
         $end = $pagesize;
     }
     $total = 0;
     $limitstart = 0;
     $sortby = $_POST['selsort'];
     if (empty($sortby)) {
         $sortby = 0;
     }
     if ($sortby == 0) {
         $sql = "Select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount  from products_table a inner join category_table b on a.category_id=b.category_id left join product_reviews_table r on a.product_id=r.product_id where " . $mycat . "  brand ='" . $brand . "' and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by a.msrp asc";
     } elseif ($sortby == 1) {
         //$sql="select * from products_table where brand='".$brand."' ".$mycat." order by msrp desc ";
         //$sql="Select a.*  from products_table a inner join category_table b on a.category_id=b.category_id where b.category_parent_id=".$catid." and brand='".$brand."' order by msrp desc" ;
         $sql = "Select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount  from products_table a inner join category_table b on a.category_id=b.category_id left join product_reviews_table r on a.product_id=r.product_id where " . $mycat . "  brand ='" . $brand . "' and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by msrp desc";
     } elseif ($sortby == 2) {
         //$sql="select * from products_table where brand='".$brand."' ".$mycat." order by title ";
         //$sql="Select a.*  from products_table a inner join category_table b on a.category_id=b.category_id where b.category_parent_id=".$catid." and brand='".$brand."' order by title" ;
         $sql = "Select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount  from products_table a inner join category_table b on a.category_id=b.category_id left join product_reviews_table r on a.product_id=r.product_id where " . $mycat . ".  brand ='" . $brand . "' and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id  order by title asc";
     } elseif ($sortby == 3) {
         // $sql="select * from products_table where brand='".$brand."' ".$mycat." order by title";
         //$sql="Select a.*  from products_table a inner join category_table b on a.category_id=b.category_id where b.category_parent_id=".$catid." and brand='".$brand."' order by title desc" ;
         $sql = "Select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount from products_table a inner join category_table b on a.category_id=b.category_id left join product_reviews_table r on a.product_id=r.product_id where " . $mycat . "  brand ='" . $brand . "' and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by title desc";
     }
     $obj = new Bin_Query();
     if ($obj->executeQuery($sql)) {
         $sql1 = $sql . ' LIMIT ' . $start . ',' . $end;
         $total = ceil($obj->totrows / $pagesize);
         include 'classes/Lib/Paging.php';
         $tmp = new Lib_Paging('classic', array('totalpages' => $total, 'length' => 10), 'pagination');
         $this->data['paging'] = $tmp->output;
         $this->data['prev'] = $tmp->prev;
         $this->data['next'] = $tmp->next;
         $query = new Bin_Query();
         if ($query->executeQuery($sql1)) {
             $_SESSION['countsearch'] = $query->totrows;
             if ((int) $query->totrows > 0) {
                 $i = 0;
                 foreach ($query->records as $row) {
                     $r[$i] = $row;
                     $prid = $row['product_id'];
                     $obj1 = new Core_CKeywordSearch();
                     $minval = $obj1->disRates($prid);
                     if ($minval > 0 or $minval != '') {
                         $r[$i]['msrp'] = '<!--$-->' . $_SESSION['currencysetting']['selected_currency_settings']['currency_tocken'] . number_format($row['msrp'] * $_SESSION['currencysetting']['selected_currency_settings']['conversion_rate'], 2) . ' - <!--$-->' . $_SESSION['currencysetting']['selected_currency_settings']['currency_tocken'] . number_format($minval * $_SESSION['currencysetting']['selected_currency_settings']['conversion_rate'], 2);
                     } else {
                         $r[$i]['msrp'] = '<!--$-->' . $_SESSION['currencysetting']['selected_currency_settings']['currency_tocken'] . number_format($row['msrp'] * $_SESSION['currencysetting']['selected_currency_settings']['conversion_rate'], 2);
                     }
                     $i++;
                 }
             }
         }
         return Display_DKeywordSearch::narrowSearch($r, $mode, $this->data['paging'], $this->data['prev'], $this->data['next']);
     } else {
         return Display_DKeywordSearch::narrowSearch($r, '', '', '', '');
     }
     $_SESSION['countsearch'] = $obj->totrows;
     $i = 0;
 }