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/kanvakanva.com/public_html/application/models/ |
Upload File : |
<?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'; public $rules = [ [ 'field' => 'product_name', 'label' => 'Product Name', 'rules' => 'trim|required|callback__cek_existing_product_title', ] ]; function __construct() { parent::__construct(); } //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(); } //function count all record for category public function record_count() { return $this->db->get('products')->num_rows(); } //function to display new product, where all fields are empty public function get_new() { $products = new stdClass(); $products->title = ''; $products->id_products = ''; $products->price = ''; $products->discount_price = ''; $products->weight = ''; $products->stock = ''; $products->product_status = ''; $products->preorder = ''; $products->description = ''; $products->long_description = ''; $products->additional_information = ''; $products->image = ''; $products->new_arrival = ''; $products->priority = ''; $products->image1 = ''; $products->image2 = ''; $products->image3 = ''; $products->image4 = ''; $products->image5 = ''; $products->meta_description = ''; $products->meta_keywords = ''; $products->product_theme = ''; $products->theme_id = ''; $products->editor_notes = ''; $products->dimensions = ''; $products->material = ''; $products->good_to_know = ''; $products->is_voucher = ''; $products->new_sale = ''; $products->in_promo1 = ''; $products->in_promo2 = ''; 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('products.priority', '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(); } //get products by category id public function get_products_by_category( $category_id, $limit, $start, $sort_product_by ) { $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'); if ($sort_product_by != null) { switch ($sort_product_by) { case 'price-asc': $this->db->order_by('products.price', 'ASC'); break; case 'price-desc': $this->db->order_by('products.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; } } else { $this->db->order_by('products.priority', 'ASC'); $this->db->order_by('products.id_products', 'DESC'); } $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //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(); } //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('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 { $this->db->order_by('priority', 'ASC'); } $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //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 new arrival public function get_products_new_arrival($limit, $start, $sort_product_by) { $this->db->select('*'); $this->db->from('products'); $this->db->where('new_arrival', 'yes'); $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 { $this->db->order_by('priority', 'ASC'); } $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //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(); } //get products by sale item public function get_products_sale($limit, $start, $sort_product_by) { $this->db->select('*'); $this->db->from('products'); $this->db->where('discount_price !=', 0); $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 { $this->db->order_by('prioroty', 'ASC'); } $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //count products by sale item public function count_products_sale() { $this->db->select('*'); $this->db->from('products'); $this->db->where('discount_price !=', 0); $this->db->where('product_status', 1); $query = $this->db->get(); return $query->num_rows(); } //cek if product title already exist public function cek_existing_product_title($str, $product_current_id) { $this->db->select('id_products'); $this->db->from('products'); $this->db->where('title', $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(); } //get products promo public function get_products_by_promo( $promo, $sort_product_by, $limit, $start ) { $this->db->select('*'); $this->db->from('products'); $this->db->where($promo, 'yes'); $this->db->where('products.product_status', '1'); if ($sort_product_by != null) { switch ($sort_product_by) { case 'price-asc': $this->db->order_by('products.price', 'ASC'); break; case 'price-desc': $this->db->order_by('products.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; } } else { $this->db->order_by('products.priority', 'ASC'); } $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } //count products by promo public function count_products_by_promo($promo) { $this->db->select('*'); $this->db->from('products'); $this->db->where($promo, 'yes'); $this->db->where('products.product_status', '1'); $query = $this->db->get(); return $query->num_rows(); } }