\!/ KyuuKazami \!/

Path : /home/kohli/public_html/application/models/
Upload :
Current File : /home/kohli/public_html/application/models/productm_bk.php

<?php
class Productm extends CI_Model  {
    
    function __construct(){
        parent::__construct();
    }
    
    function get_category_products($cat_id,$offset=0,$limit=0,$sort_column="product_name",$sort_order="asc"){
        $this->db->where("p.active",1);        
        if($cat_id > 0 && !is_array($cat_id)){
            // $strps = "p.category_id in (".$cat_id.")";
            $this->db->like('p.category_id', $cat_id);
           // $this->db->where("p.category_id",$cat_id);  
        }
        
        if(is_array($cat_id)){
            if(count($cat_id) > 0){
                foreach($cat_id as $column => $value){
                    $this->db->where($value);
                }
            }
        }
            
        $this->db->order_by('rand()');        
      //  $this->db->order_by($sort_column,$sort_order);

              
        if($limit > 0 && $offset >= 0 ){
            $this->db->limit($limit,$offset);
        }
        
        $this->db->join("manufacturers man","p.manufacturer_id = man.manufacturer_id","left");
        $this->db->join("colors col","p.color_id = col.color_id","left");
        $this->db->join("collections cl","p.collection_id = cl.collection_id","left");
       // $this->db->join("categories c","p.category_id = c.category_id","left");
		$q = $this->db->get('products p');
       // echo $this->db->last_query();   
        $result = $q->result();		
		return $result;
	}
    
    function get_clearance_products($offset=0,$limit=0,$sort_column="product_name",$sort_order="asc"){
        $this->db->where("active",1);        
        
        $this->db->where("promo_price > 0");    
                
        $this->db->order_by($sort_column,$sort_order);
                
        if($limit > 0 && $offset >= 0 ){
            $this->db->limit($limit,$offset);
        }
		$q = $this->db->get('products');
        //echo $this->db->last_query();        
        $result = $q->result();		
		return $result;
	}
    
    function get_deal_products($offset=0,$limit=0,$sort_column="product_name",$sort_order="asc"){
        $this->db->where("active",1); 
        $this->db->where("deal_status",1);       
        
                
        $this->db->order_by($sort_column,$sort_order);
                
        if($limit > 0 && $offset >= 0 ){
            $this->db->limit($limit,$offset);
        }
		$q = $this->db->get('products');
       // echo $this->db->last_query();        
        $result = $q->result();		
		return $result;
	}
    
    
    function get_hot_products($offset=0,$limit=0,$sort_column="product_name",$sort_order="asc"){
        $this->db->where("active",1); 
        $this->db->where("hot_sellers",1);       
        
                
        $this->db->order_by($sort_column,$sort_order);
                
        if($limit > 0 && $offset >= 0 ){
            $this->db->limit($limit,$offset);
        }
		$q = $this->db->get('products');
       // echo $this->db->last_query();        
        $result = $q->result();		
		return $result;
	}
    function get_user_wishlist($user_id){        
        $this->db->select('*');
        $this->db->from('wishlist');
        $this->db->join("products","wishlist.product_id = products.product_id");
        $this->db->join("sizes","sizes.size_id = wishlist.size_id","left");
        $this->db->where("products.active",1);        
        $this->db->where("wishlist.user_id = $user_id");
	    $q = $this->db->get();
        $result = $q->result();
	    return $result;
    }
    
    function get_all_products($extra_where=""){
        $this->db->where("active",1);
        if($extra_where != ""){
            $this->db->where($extra_where);    
        }
        $this->db->order_by("product_id","asc");
	    $q = $this->db->get('products');
        $result = $q->result();		
        return $result;
    }        
    
    function get_size_stock($product_id){
        $this->db->select("sum(stock_available) as size_stock");
        $this->db->where(array('active' => 1));
        $this->db->where(array('product_id' => $product_id));
        $this->db->group_by("product_id");
                
        $q = $this->db->get('product_sizes');        
        $result = $q->result();        
        return $result;
    }
    
    function get_product_sizes($product_id,$extra_where=array()){
        $this->db->where(array('active' => 1));
        $this->db->where(array('product_id' => $product_id));
        if(count($extra_where) > 0){
            $this->db->where($extra_where);    
        }
        $this->db->join("sizes s","s.size_id = ps.size_id");
        $q = $this->db->get('product_sizes ps');
        $result = $q->result();
        $size_array = array();
        foreach($result as $row){
            $size_array[$row->size_id] = $row; 
        }        
        
        return $size_array;
    }
    
     function get_range_print($product_id,$extra_where=array()){
        $this->db->where(array('product_id' => $product_id));
        if(count($extra_where) > 0){
            $this->db->where($extra_where);    
        }
        $this->db->join("range g","g.range_id = pp.range_id");
        $q = $this->db->get('product_printcost pp');
        $result = $q->result();
        $size_array = array();
        foreach($result as $row){
            $size_array[$row->range_id] = $row; 
        }        
        
        return $size_array;
    }
    
    function get_product_images($product_id){
        $this->db->where(array('pi.product_id' => $product_id));        
        $q = $this->db->get('product_images pi');
        $result = $q->result();        
        return $result;
    }
    
    function get_all_sizes($extra_where=""){
        $q = $this->db->get('sizes');
        $result = $q->result();		
        return $result;
    }
    
    function get_all_product_feq($product_id){
        $this->db->where(array('product_id' => $product_id));
        $q = $this->db->get('product_frequently');
        $result = $q->result();	
        $add_on_product = array();
        foreach($result as $row){
            $add_on_product[$row->add_on_product_id] = $row; 
        }        
        
        return $add_on_product;	
    }
    
    function get_latest_products($extra_where="",$type=""){
        
        $this->db->where("active",1);        
        if($extra_where != ""){
            $this->db->where($extra_where);    
        }
        
        if($type == "new"){
            $this->db->where("is_new",1);    
        }
        
        if($type == "hot"){
            $this->db->where("hot_sellers",1);    
        }
        
        if($type == "featured"){
            $this->db->where("on_sale",1);    
        }
        
        if($type == "popular"){
            $this->db->where("upcoming",1);    
        }
        
        $this->db->order_by("product_id","desc"); 
        $this->db->limit(20,0);
		$q = $this->db->get('products');
        $result = $q->result();		
		return $result;
	}
    
    function get_product_detail($pid){
        $this->db->select('*');
        $this->db->from('products');
        $this->db->join("categories","products.category_id = categories.category_id","left");
        $this->db->join("manufacturers","products.manufacturer_id = manufacturers.manufacturer_id","left");
        $this->db->where("active",1);
        $this->db->where("product_id",$pid);
        $q = $this->db->get();
        $result = $q->result();		
        return $result;
    }
    
    function get_product_reviews($pid,$status=1){
        $this->db->select('*');
        $this->db->from('product_reviews');
        $this->db->where("status",$status);
        $this->db->where("product_id",$pid);
        $q = $this->db->get();
        $result = $q->result();
        return $result;
    }
    
    function get_product_variant($pid,$pcode){
        $this->db->where("item_number",$pcode);
        $this->db->where_not_in("product_id",$pid);        
		$q = $this->db->get('products');
        $result = $q->result();		
		return $result;
    }   
}

@KyuuKazami