|
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/controllers/ |
Upload File : |
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Category extends Public_Controller
{
public function __construct()
{
parent::__construct();
}
public function get($alias = NULL)
{
if ($alias == NULL)
{
redirect(base_url('shop'));
}
if ($alias !== NULL && $alias != 'all-categories')
{
//check if this category alias exist
$this->db->select('id_categories')->from('categories')->where('alias', $alias)->where('parent', NULL)->where('status', 1);
$count_category = $this->db->get()->num_rows();
if ($count_category == 0)
{
redirect(base_url('shop'));
}
else
{
$this->db->select('*')->from('categories')->where('alias', $alias);
$category = $this->db->get()->row();
$this->data['cat_id'] = $category->id_categories;
$this->data['cat_title'] = $category->category;
$this->data['cat_alias'] = $alias;
$this->data['cat_banner'] = $category->image;
}
}
//Load model product_m
$this->load->model('product_m');
//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();
//user request
if ($alias != NULL && $alias != 'all-categories')
{
//get category parameters
$this->db->select('*')->from('categories')->where('id_categories',$category->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'));
}
else
{
$this->session->unset_userdata('sort_product', $this->input->post('sort_product'));
}
//PRODUCTS
//pagination in action
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'category/' . $alias . '/';
$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'] = 3;
$this->pagination->initialize($config);
$this->data['sort_product_by'] = $this->session->userdata('sort_product');
$this->data['sidebanner_active_category_id'] = $this->data['level1_id'];
$this->data['total_products'] = $config['total_rows'];
$this->data['products'] = $this->product_m->get_products_by_category($this->data['category']->id_categories, $config['per_page'], $this->uri->segment($config['uri_segment']), $this->data['sort_product_by']);
}
//set current category to session, so it can be track to product page
if ($alias != 'all-categories')
{
$this->session->set_userdata('current_viewed_category_id', $this->data['category']->id_categories);
}
if ($alias == 'all-categories')
{
//check if post sort_product is exist
if ($this->input->post('sort_product'))
{
$this->session->set_userdata('sort_product', $this->input->post('sort_product'));
}
else
{
$this->session->unset_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();
//PRODUCTS
//pagination in action
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'category/all-categories/';
$this->load->model('product_m');
$config['total_rows'] = $this->product_m->count_products_all();
$config['per_page'] = (int) $per_page->products_displayed;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$this->data['sort_product_by'] = $this->session->userdata('sort_product');
$this->data['total_products'] = $config['total_rows'];
$this->data['products'] = $this->product_m->get_products_all($config['per_page'], $this->uri->segment($config['uri_segment']));
//to display title on product_list view
$this->data['product_list_title'] = 'koleksi';
$this->db->select('category, alias, thumbnail')->from('categories')->where('parent', NULL)->where('status', '1')->order_by('priority', 'ASC');
$this->data['categories'] = $this->db->get()->result();
//get SEO
$this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - Shop';
$this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - Shop';
}
else
{
//get SEO
$this->data_header['browser_title'] = 'Category - ' . ucwords($this->data['category']->category);
$this->data_header['meta_description'] = $this->data['category']->meta_description;
}
//LOAD LANGUAGE FILES FOR PRODUCT LIST PAGE
if ($this->session->userdata('site_lang') == 'english') {
$this->lang->load('product_detail', 'english');
$this->lang->load('product_list', 'english');
} else {
$this->lang->load('product_list', 'indonesian');
$this->lang->load('product_detail', 'indonesian');
}
$this->data['category_url'] = $config['base_url'];
//get categories menu
$this->data['categories'] = $this->db->select('category, alias')->from('categories')->where('status', '1')->order_by('priority', 'ASC')->get()->result();
$this->data_header['categories'] = $this->data['categories'];
$this->load->view("themes/$this->theme_no/header-shop", $this->data_header);
$this->load->view("themes/$this->theme_no/product_list", $this->data);
$this->load->view("themes/$this->theme_no/footer-shop", $this->data_footer);
}
}