Exemplo n.º 1
0
function get_price_range($cat_id)
{
    $ci =& get_instance();
    $cat_ids_arr = mychildrecur($cat_id);
    $cat_ids_arr[] = $cat_id;
    $cat_ids = implode(",", $cat_ids_arr);
    $sql = "select max(sale_price) as max_price, min(sale_price) as min_price from products where cat_id in ({$cat_ids})";
    $field_values = $ci->db->query($sql)->row_array();
    return $field_values;
}
Exemplo n.º 2
0
 public function total_product_by_category($category_id)
 {
     $all_child_cat = implode(',', mychildrecur($category_id));
     $cat_detail = $this->db->query("select parent_id from categories where cat_id = {$category_id};")->row_array();
     if ($all_child_cat != '') {
         $where = 'products.cat_id IN(' . $category_id . ',' . $all_child_cat . ')';
     } else {
         $where = "products.cat_id = {$category_id}";
     }
     // $where = "products.cat_id = {$category_id}";
     $query_params = $this->input->get();
     if (isset($query_params['brand'])) {
         $raw_brands = str_replace(array("-", "_", '.'), array(" ", "&", "','"), $query_params['brand']);
     } else {
         $raw_brands = '';
     }
     if (isset($query_params['min_price'])) {
         $min_price = $query_params['min_price'];
     } else {
         $min_price = 0;
     }
     if (isset($query_params['max_price'])) {
         $max_price = $query_params['max_price'];
     } else {
         $max_price = 0;
     }
     if ($raw_brands != '') {
         $where .= " AND products.brand in ('" . $raw_brands . "')";
     }
     if ($min_price > 0) {
         $where .= " AND products.sale_price>=" . $min_price;
     }
     if ($max_price > 0) {
         $where .= " AND products.sale_price<=" . $max_price;
     }
     $where .= " and products.status=1 ";
     $query = $this->db->select('count(*) as products_total')->join('product_deal', 'product_deal.product_id = products.id')->join('cities', 'cities.city_id = products.city_id', 'left')->join('categories', 'categories.cat_id = products.cat_id')->where("( ( NOW() BETWEEN product_deal.sale_start_date and product_deal.sale_end_date) OR (product_deal.sale_end_date = '0000-00-00') )")->where($where)->get('products')->row_array();
     //echo $this->db->last_query();
     $res = isset($query['products_total']) && $query['products_total'] ? intval($query['products_total']) : 0;
     return $res;
 }