https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /var/www/angkasapuraretail.com/public_html/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/angkasapuraretail.com/public_html/application/models/Product_m.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Product_m extends MY_Model { 

	protected $_table_name = 'products';
	protected $_primary_key = 'id_products';
	protected $_order_by = 'id_products'; 
	private $website_product_ordering = NULL;

	function __construct() {
		parent::__construct();	
		//get website product ordering
		$this->db->select('website_product_ordering')->from('configuration')->where('id_configuration', 1);
		$this->website_product_ordering = $this->db->get()->row()->website_product_ordering;
	}

	public $rules = array(  
		array(
			'field'   => 'product_name',
			'label'   => 'Product Name',
			'rules'   => 'trim|required'
		),
    );

	//ADMIN WEBSITE
	//pagination included
	function get_all_products($limit, $start) {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->order_by('priority', 'ASC');
		$this->db->limit($limit, $start);
		$query = $this->db->get();		
		return $query->result(); 
	}

	//pagination included
	function get_all_products_search_product($keyword) {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->like('products.title', $keyword);
		$this->db->order_by('priority', 'ASC');
		$query = $this->db->get();	
		return $query->result(); 
	}

	//function count all record for category 
	public function record_count() {
        return $this->db->get('products')->num_rows();
    }

	//function count all record for search product
	public function record_count_search_product($keyword) {
        $this->db->select('*');
		$this->db->from('products'); 
		$this->db->like('products.title', $keyword);
		$query = $this->db->get();		
		return $query->num_rows();
    }

    //function to display new product, where all fields are empty
	public function get_new() {
		$products = new stdClass();
		$products->id_products = '';	
		$products->title = '';	
		$products->title2 = '';	
		$products->product_code = '';	
		$products->sku = '';	
		$products->product_status = '';	
		$products->description = '';
		$products->description_en = '';
		$products->long_description = '';
		$products->long_description_en = '';
		$products->additional_information = '';
		$products->additional_information_en = '';
		$products->payment_information = '';
		$products->payment_information_en = '';
		$products->new_arrival = '';
		$products->best_seller = '';	
		$products->popular_product = '';	
		$products->image1 = '';	
		$products->image2 = '';	
		$products->image3 = '';	
		$products->image4 = '';	
		$products->image5 = '';	
		$products->meta_description = '';	
		$products->meta_keywords = '';	
		$products->priority = '';
		$products->dimension_weight	= '';
		$products->dimension_length	= '';
		$products->dimension_width	= '';
		$products->dimension_height	= '';
		$products->competitor_price	= '';
		$products->sale_price	= '';
		$products->discounted_price	= '';
		$products->is_sale	= '';
		$products->minimum_stock = '';
		$products->warranty = '';
		$products->is_backorder = '';
		$products->is_discontinue = '';
		$products->is_delete = '';
		$products->indent_duration = '';
		$products->sold = '';
		return $products;
	}

	//function add new product
	function add_product($data) {
		$this->db->insert('products', $data);	
		return $this->db->insert_id();	
	}

	//function edit product
	function edit_product($id, $data) {
		$this->db->where('id_products', $id);
		$this->db->update('products', $data);	
	}

	//update orphan products to remove category
	function update_product_category($id, $data) {
		$this->db->where('category_id', $id);
		$this->db->update('products', $data); 
	}

	//update orphan products to remove brand
	function update_product_brand($id, $data) { 
		$this->db->where('brand_id', $id);
		$this->db->update('products', $data);  
	}

	//select chosen product at frontend
	function selected_product($chosen_product_id){
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('id_products', $chosen_product_id); 
		$query = $this->db->get();		
		return $query->row();
	}

	//update product stock in database after deduct from purchased stock
	function update_product_stock($id, $stock_data) {
		$this->db->where('id_products', $id);
		$this->db->update('products', $stock_data); 
	}

	//Public Page 
	public function get_products() {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('categories', 'categories.id_categories = products.category_id');
		$this->db->order_by('category', 'asc');
		$query = $this->db->get();		
		return $query->result();
	}

	//Public Page 
	public function get_product_by_id($id) {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('categories', 'categories.id_categories = products.category_id');
		$this->db->where('id_products', $id);
		$query = $this->db->get();	

		//check if product id already exist in database, to prevent display error
		if($query->num_rows() > 0) {
			return $query->row(); 
		} else {
			show_404(); 
		}
	}

	//Public Page cart
	public function get_image($product_id) {
		$this->db->select('image1');
		$this->db->from('products');
		$this->db->where('id_products', $product_id);
		$query = $this->db->get();		
		return $query->row();  
	}

	//get current stock
	public function get_current_stock($product_id) {
		$this->db->select('stock');
		$this->db->from('products');
		$this->db->where('id_products', $product_id);
		$query = $this->db->get();	 	
		return $query->row();
	} 

	//IS USED: get products by category id
	public function get_products_by_category($category_id, $limit, $start) {

		$this->db->select(
		 'products.alias as alias, 
			products.image1 as image1, 
			products.title as title,
			products.id_products as id_products, 
			products.created_at,
			products.sale_price,
			products.is_sale,
			products.discounted_price,
			products.sale_price as harga,
			products.new_arrival'
		);
		$this->db->from('products');  
		$this->db->join('category_product', 'products.id_products = category_product.id_product');
		$this->db->where('category_product.id_category', $category_id);
		$this->db->where('products.product_status', '1');

		if ($this->session->userdata('sort_product')) { 
			
			switch ($this->session->userdata('sort_product')) {
				case 'price-asc':
					$this->db->order_by('harga', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('harga', 'DESC');
					break;	
				case 'name-asc':
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC');
					break;	
				case 'created-date':
					$this->db->order_by('products.created_at', 'DESC');
					break;			
			}

		} else {

			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}
		
		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by category
	public function count_products_by_category($category_id) {
		
		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('category_product', 'products.id_products = category_product.id_product');
		$this->db->where('category_product.id_category', $category_id);
		$this->db->where('products.product_status', '1');
		$query = $this->db->get();
		return $query->num_rows();
	}

	//IS USED: get products by brand id
	public function get_products_by_brand($brand_id, $limit, $start, $sort_product_by) {

		$this->db->select(
			'*'
		);
		$this->db->from('products'); 
		$this->db->where('brand_id', $brand_id);
		$this->db->where('product_status', 1);
		
		if ($sort_product_by != NULL) {
			
			switch ($sort_product_by) {
				case 'price-asc':
					$this->db->order_by('sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('sale_price', 'DESC');
					break;	
				case 'name-asc':
					$this->db->order_by('title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('title', 'DESC');
					break;	
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('created_at', 'ASC');
					break;		
			}
		}
		
		$this->db->limit($limit, $start);
		$query = $this->db->get();		
		return $query->result();
	}

	//IS USED: count products by brand id
	public function count_products_by_brand($brand_id) {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('brand_id', $brand_id);
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//get products by promotion id
	public function get_products_by_promotion($promotion_id, $limit, $start, $sort_product_by) {

		$this->db->select('*');
        $this->db->from('products'); 
        $this->db->join('promotion_product', 'promotion_product.id_product = products.id_products');
        $this->db->where('promotion_product.id_promotion', $promotion_id);
        $this->db->where('product_status', 1);
        
        if ($sort_product_by != NULL) {
            
            switch ($sort_product_by) {
            
            case 'price-asc':
                $this->db->order_by('price', 'ASC');
                break;
            case 'price-desc':
                $this->db->order_by('price', 'DESC');
                break;  
            case 'name-asc':
                $this->db->order_by('title', 'ASC');
                break;  
            case 'name-desc':
                $this->db->order_by('title', 'DESC');
                break;  
            }

        } else {

            switch($this->website_product_ordering) {
                case 'random':
                    $this->db->order_by('products.title', 'RANDOM');
                    break;  
                case 'manual-order':
                    $this->db->order_by('products.priority', 'ASC');
                    break;  
                case 'input-date-desc':
                    $this->db->order_by('products.created_at', 'DESC');
                    break;  
                case 'input-date-asc':
                    $this->db->order_by('products.created_at', 'ASC');
                    break;      
            }
        }
        
        $this->db->limit($limit, $start);
        $query = $this->db->get();      
        return $query->result();
	}

	//count products by promotion id
	public function count_products_by_promotion($promotion_id) {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('promotion_id', $promotion_id);
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}


	//IS USED: get products by new arrival
	public function get_products_new_arrival($limit, $start) { 
		
		$this->db->select(
			'*'
		);
		$this->db->from('products');
		$this->db->where('products.new_arrival', 'yes');
		$this->db->where('products.product_status', 1);
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('sale_price', 'DESC');
					break;	
				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by new arrival
	public function count_products_new_arrival() {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('new_arrival', 'yes');
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by new arrival
	public function get_products_all($limit, $start) { 

		$this->db->select(
			'products.id_products as id_products, 
			products.alias as alias, 
			products.image1 as image1,
			products.image2 as image2, 
			products.title as title,		
			products.title2 as title2, 	 
			products.created_at,
			products.sale_price,
            products.competitor_price,
			IF(product_details.discounted_price = 0,product_details.price,product_details.discounted_price) as harga'
		);
		$this->db->from('products');
		$this->db->join('product_details', 'products.id_products = product_details.product_id', 'INNER');
		$this->db->where('products.product_status', 1);
		//$this->db->group_by('products.id_products');
		$this->db->group_by('product_details.product_id');
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('harga', 'ASC');
					break;

				case 'price-desc':
					
					$this->db->order_by('harga', 'DESC');
					break;	

				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by all
	public function count_products_all() {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by bestseller
	public function get_products_bestseller($limit, $start) { 

		$this->db->select(
			'*'
		);
		$this->db->from('products');
		$this->db->where('products.best_seller', 'yes');
		$this->db->where('products.product_status', 1);
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('sale_price', 'DESC');
					break;	
				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by bestseller
	public function count_products_bestseller() {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('best_Seller', 'yes');
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//count products by new arrival
	public function count_parent_products_new_arrival($parent_category) {

		//get parent id category
		$this->db->select('id_categories')->from('categories')->where('alias', $parent_category)->where('parent'. NULL);
		$parent_id_category = $this->db->get()->row()->id_categories;

		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('category_product', 'category_product.id_product = products.id_products');
		$this->db->where('new_arrival', 'yes');
		$this->db->where('category_product.id_category', $parent_id_category);
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}


	//get products by new arrival
	public function get_parent_products_new_arrival($limit, $start, $sort_product_by, $parent_category) {

		//get parent id category
		$this->db->select('id_categories')->from('categories')->where('alias', $parent_category)->where('parent'. NULL);
		$parent_id_category = $this->db->get()->row()->id_categories;

		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('category_product', 'category_product.id_product = products.id_products');
		$this->db->where('new_arrival', 'yes');
		$this->db->where('category_product.id_category', $parent_id_category);
		$this->db->where('product_status', 1);
		
		if ($sort_product_by != NULL) {
			
			switch ($sort_product_by) {
			
			case 'price-asc':
				$this->db->order_by('price', 'ASC');
				break;
			case 'price-desc':
				$this->db->order_by('price', 'DESC');
				break;	
			case 'name-asc':
				$this->db->order_by('title', 'ASC');
				break;	
			case 'name-desc':
				$this->db->order_by('title', 'DESC'); 
				break;	
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();		
		return $query->result();
	}


	//IS USED: get products by sale item
	public function get_products_sale($limit, $start) {
		
		$this->db->select(
			'products.alias as alias, 
			products.image1 as image1, 
			products.image2 as image2, 
			products.title as title, 
			products.title2 as title2, 
			products.id_products as id_products, 
			products.created_at,
			IF(product_details.discounted_price = 0,product_details.price,product_details.discounted_price) as harga'
		);
		$this->db->from('products');
		$this->db->join('product_details', 'product_details.product_id = products.id_products');
		$this->db->where('products.product_status', 1);
		$this->db->where('product_details.discounted_price !=', 0);
		$this->db->group_by('product_details.product_id');
		
		if ($this->session->userdata('sort_product')) { 
			
			switch ($this->session->userdata('sort_product')) { 
			
				case 'price-asc':
					$this->db->order_by('harga', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('harga', 'DESC');
					break;	
				case 'name-asc':
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
				}
		} else { 
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}
		$this->db->limit($limit, $start);
		$query = $this->db->get();		
		return $query->result();
	}

	//IS USED: count products by sale item
	public function count_products_sale() {

		$this->db->distinct('product_details.product_id');
		$this->db->select('products.id_products');
		$this->db->from('products');
		$this->db->join('product_details', 'product_details.product_id = products.id_products');
		$this->db->where('products.product_status', 1);
		$this->db->where('product_details.discounted_price !=', 0); 
		$query = $this->db->get();		
		return $query->num_rows(); 
	}

	//IS USED: count products by search
	public function count_products_by_search($keyword) {

		/* $this->db->select('*');
		$this->db->from('products'); 
		$this->db->join('brands', 'products.brand_id = brands.id_brands');
		$this->db->where('products.product_status', '1');
		$this->db->like('products.title', $keyword);
		$this->db->or_like('products.categories', $keyword);
		$this->db->or_like('brands.brand', $keyword); */

		$this->db->select('*');
		$this->db->from('products'); 
		$this->db->where('product_status', '1');
		$this->db->group_start();
		$this->db->like('title', $keyword);
		$this->db->or_like('categories', $keyword);
		$this->db->or_like('meta_description', $keyword);
		/* $this->db->or_like('meta_keywords', $keyword); */
		$this->db->group_end();

		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by search
	public function get_products_by_search($keyword, $limit, $start) {

		//get products 
		$this->db->select('*');
		$this->db->from('products'); 
		$this->db->where('product_status', '1');
		$this->db->group_start();
		$this->db->like('title', $keyword);
		$this->db->or_like('categories', $keyword);
		$this->db->or_like('description', $keyword);
		$this->db->or_like('sku', $keyword);
		/* $this->db->or_like('meta_keywords', $keyword); */
		$this->db->group_end();

		if ($this->session->userdata('sort_product')) {
			switch ($this->session->userdata('sort_product')) {
				case 'price-asc':
					$this->db->order_by('sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('sale_price', 'DESC');
					break;	
				case 'name-asc':
					$this->db->order_by('title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('title', 'DESC');
					break;	
				case 'created-at':
					$this->db->order_by('created_at', 'DESC');
					break;		
			}
		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('created_at', 'ASC');
					break;		
			}
		}
		$this->db->limit($limit, $start);
		$query = $this->db->get();		
		return $query->result(); 
	}

	//cek if product title already exist
	public function cek_existing_product_code($str, $product_current_id) {
		$this->db->select('id_products');
		$this->db->from('products'); 
		$this->db->where('product_code', $str);

		if ($product_current_id != NULL) {
			$this->db->where('id_products !=', $product_current_id);	 
		} 

		$query = $this->db->get();
		return $query->num_rows();
	}

	//function count if existing record exist
	public function count_exist($id) {
        $this->db->select('*');
        $this->db->from('products');
        $this->db->where('id_products', $id);
        $query = $this->db->get();		
		return $query->num_rows();
    }

    //IS USED: count products by bestseller
	public function count_products_topoffer() {
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('popular_product', 'yes');
		$this->db->where('product_status', 1);
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by bestseller
	public function get_products_topoffer($limit, $start) { 

		$this->db->select(
			'*'
		);
		$this->db->from('products');
		$this->db->where('products.popular_product', 'yes');
		$this->db->where('products.product_status', 1);
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('sale_price', 'DESC');
					break;	
				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by bestseller
	public function count_products_flashsale($id) {
		$this->db->select('*');
		$this->db->from('flashsale_products');
        $this->db->join('products', 'products.id_products = flashsale_products.product_id');
		$this->db->where('flashsale_products.flashsale_id', $id);
        $this->db->where('products.product_status', 1);
        $this->db->order_by('flashsale_products.product_id', 'RANDOM');
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by bestseller
	public function get_products_flashsale($limit, $start, $id) { 

		$this->db->select('
			flashsale_products.discounted_price,
            products.alias as alias, 
            products.image1 as image1,
            products.title as title, 
            products.title2 as title2, 
            products.id_products as id_products, 
            products.sale_price,
            products.is_sale
        ');
		$this->db->from('flashsale_products');
		$this->db->join('products', 'products.id_products = flashsale_products.product_id');
		$this->db->where('flashsale_products.flashsale_id', $id);
		$this->db->where('products.product_status', 1);
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('products.sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('products.sale_price', 'DESC');
					break;	
				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	//IS USED: count products by bestseller
	public function count_products_flashsale_next($id) {
		$this->db->select('*');
		$this->db->from('flashsale_products');
        $this->db->join('products', 'products.id_products = flashsale_products.product_id');
		$this->db->where('flashsale_products.flashsale_id', $id);
        $this->db->where('products.product_status', 1);
        $this->db->order_by('flashsale_products.product_id', 'RANDOM');
		$query = $this->db->get();		
		return $query->num_rows();
	}

	//IS USED: get products by bestseller
	public function get_products_flashsale_next($limit, $start, $id) { 

		$this->db->select('
			flashsale_products.discounted_price,
            products.alias as alias, 
            products.image1 as image1,
            products.title as title, 
            products.title2 as title2, 
            products.id_products as id_products, 
            products.sale_price,
            products.is_sale
        ');
		$this->db->from('flashsale_products');
		$this->db->join('products', 'products.id_products = flashsale_products.product_id');
		$this->db->where('flashsale_products.flashsale_id', $id);
		$this->db->where('products.product_status', 1);
		
		if ($this->session->userdata('sort_product')) {
			
			switch ($this->session->userdata('sort_product')) {
			
				case 'price-asc':
					$this->db->order_by('products.sale_price', 'ASC');
					break;
				case 'price-desc':
					$this->db->order_by('products.sale_price', 'DESC');
					break;	
				case 'name-asc': 
					$this->db->order_by('products.title', 'ASC');
					break;	
				case 'name-desc':
					$this->db->order_by('products.title', 'DESC'); 
					break;	
				case 'created-at':
					$this->db->order_by('products.created_at', 'DESC'); 
					break;		
			}

		} else {
			switch($this->website_product_ordering) {
				case 'random':
					$this->db->order_by('products.title', 'RANDOM');
					break;	
				case 'manual-order':
					$this->db->order_by('products.priority', 'ASC');
					break;	
				case 'input-date-desc':
					$this->db->order_by('products.created_at', 'DESC');
					break;	
				case 'input-date-asc':
					$this->db->order_by('products.created_at', 'ASC');
					break;		
			}
		}

		$this->db->limit($limit, $start);
		$query = $this->db->get();	
		return $query->result();
	}

	function excel_export() {
		$this->db->select('products.id_products, products.id_products, products.product_code, products.sku, products.title, products.sale_price, products.discounted_price, products.dimension_weight, products.dimension_height, products.dimension_width, products.dimension_length, stock.stock');
		$this->db->from('products');
		$this->db->join('stock','stock.id_product = products.id_products');
		$this->db->order_by('products.title', 'asc');
		$query = $this->db->get();		
		return $query->result();
	}



}

https://t.me/RX1948 - 2025