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/mesinpolesshinemate.com/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); //this class is to display best seller, new arrival, and promo products from specific parent category only... class Category_list extends Public_Controller { public function __construct() { parent::__construct(); } public function get($alias_level1 = NULL, $category_type = NULL, $alias_level2 = NULL) { if ($alias_level1 == NULL) { show_404(); } if ($category_type == NULL) { show_404(); } if ($alias_level1 !== NULL && $category_type !== NULL && $alias_level2 === NULL) { //check if this category alias exist $this->db->select('id_categories')->from('categories')->where('alias', $alias_level1)->where('parent', NULL)->where('status', 1); $count_category = $this->db->get()->num_rows(); if ($count_category == 0) { show_404(); } //if exist, get the ID for level 1 category $this->db->select('id_categories, category')->from('categories')->where('alias', $alias_level1)->where('parent', NULL); $level1 = $this->db->get()->row(); $this->data['level1_id'] = $level1->id_categories; $this->data['level1_title'] = $level1->category; $this->data['level1_alias'] = $alias_level1; } if ($alias_level1 !== NULL && $category_type !== NULL && $alias_level2 !== NULL) { //check if this category alias exist $this->db->select('id_categories')->from('categories')->where('alias', $alias_level1)->where('parent', NULL)->where('status', 1); $count_category = $this->db->get()->num_rows(); if ($count_category == 0) { show_404(); } //if exist, get the ID for level 1 category $this->db->select('id_categories, category')->from('categories')->where('alias', $alias_level1)->where('parent', NULL); $level1 = $this->db->get()->row(); $this->data['level1_id'] = $level1->id_categories; $this->data['level1_title'] = $level1->category; $this->data['level1_alias'] = $alias_level1; } //user request level 1 category if ($alias_level1 !== NULL && $category_type !== NULL && $alias_level1 === NULL) { //get category parameters $this->db->select('*')->from('categories')->where('id_categories', $level1->id_categories)->where('parent', NULL); $this->data['category'] = $this->db->get()->row(); //check if post sort_product is exist if ($this->input->post('sort_product')) { $this->session->set_userdata('sort_product', $this->input->post('sort_product')); } //PRODUCTS //pagination in action //get no. of products per page (pagination) from configuration table $this->db->select('products_displayed')->from('configuration')->where('id_configuration', 1); $per_page = $this->db->get()->row(); $this->load->library('pagination'); $config = array(); $this->load->helper('pagination_helper'); $config = pagination_format(); $config['base_url'] = base_url() . 'category_list/' . $alias_level1 . '/' . $category_type . '/'; $this->load->model('product_m'); $config['total_rows'] = $this->product_m->count_products_by_category($this->data['category']->id_categories); $config['per_page'] = $per_page->products_displayed; $config['uri_segment'] = 4; //get total rows $this->db->select('products.alias as alias, products.image1 as image1, products.image2 as image2, products.title as title, products.id_products as id_products'); $this->db->from('products'); $this->db->join('category_product', 'products.id_products = category_product.id_product'); $this->db->where('category_product.id_category', $this->data['category']->id_categories); $this->db->where('products.product_status', '1'); $config['total_rows'] = $this->db->get()->num_rows(); $this->pagination->initialize($config); $this->data['sort_product_by'] = $this->session->userdata('sort_product'); $data['sidebanner_active_category_id'] = $this->data['level1_id']; $this->data['total_products'] = $config['total_rows']; //get products $this->db->select('*'); $this->db->from('products'); $this->db->join('category_product', 'products.id_products = category_product.id_product'); $this->db->join('product_details', 'products.id_products = product_details.product_id'); //this useful to get only each 1 record from right table $this->db->group_by('products.id_products'); $this->db->where('category_product.id_category', $this->data['category']->id_categories); $this->db->where('products.product_status', '1'); if($category_type == 'bestseller') { $this->db->where('products.best_Seller', 'yes'); } if($category_type == 'newarrival') { $this->db->where('products.new_arrival', 'yes'); } if($category_type == 'promo') { $this->db->where('product_details.discounted_price !=', 0); } if ($this->session->userdata('sort_product')) { switch ($this->session->userdata('sort_product')) { case 'price-asc': $this->db->order_by('product_details.price', 'ASC'); break; case 'price-desc': $this->db->order_by('product_details.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 { $this->db->order_by('products.created_at', 'DESC'); } $this->db->limit($config['per_page'], $this->uri->segment($config['uri_segment'])); $this->data['products'] = $this->db->get()->result(); } //get SEO $this->data_header['browser_title'] = 'Category - ' . ucwords($this->data['category']->category); $this->data_header['meta_description'] = $this->data['category']->meta_description; $this->data_header['meta_keywords'] = $this->data['category']->meta_keywords; $this->load->view('template/header', $this->data_header); $this->load->view('category', $this->data); $this->load->view('template/footer', $this->data_footer); } }