|
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/kamariallee.com/public_html/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Customize extends Public_Controller
{
public function __construct()
{
parent::__construct();
}
public function get($alias_level1 = NULL, $alias_level2 = NULL)
{
if ($alias_level1 == NULL) { show_404(); }
//if exist, get the Category Id for level 1 category
$this->db->select('id_categories, category, image, title, description, meta_description, can_delete')->from('categories')->where('alias', $alias_level1)->where('parent', NULL);
$category = $this->db->get()->row_array();
if(!$category) { show_404(); }
$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();
if ($alias_level1 !== NULL && $alias_level2 == NULL)
{
$this->data['level1_id'] = $category['id_categories'];
$this->data['level1_category'] = $category['category'];
$this->data['level1_alias'] = $alias_level1;
$this->data['category_name'] = $category['category'];
$this->data['banner_title'] = $category['title'];
$this->data['banner_description'] = $category['description'];
$this->data['banner_image'] = $category['image'];
//check if post sort_product is exist
if ($this->input->post('sort_product'))
{
$this->session->set_userdata('sort_product', $this->input->post('sort_product'));
}
if ($category['can_delete'] === 'no')
{
//pagination in action
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'category/' . strtolower($alias_level1) . '/';
$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']));
}
else
{
//this is get products by category
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'category/' . strtolower($alias_level1) . '/';
$config['total_rows'] = $this->product_m->count_products_by_category($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['total_products'] = $config['total_rows'];
$this->data['products'] = $this->product_m->get_products_by_category($category['id_categories'], $config['per_page'], $this->uri->segment($config['uri_segment']));
}
}
if ($alias_level1 !== NULL && $alias_level2 != NULL)
{
if (is_numeric($alias_level2))
{
# the numeric is for pagination.
//do nothing...
}
else
{
//if exist, get the Category Id for level 2 category
$this->db->select('id_categories, category, title, description, image, meta_description')->from('categories')->where('alias', $alias_level2)->where('parent', $category['id_categories']);
$category = $this->db->get()->row_array();
if (!$category) { show_404(); }
$this->data['level2_id'] = $category['id_categories'];
$this->data['level2_category'] = $category['category'];
$this->data['level2_alias'] = $alias_level2;
$this->data['category_name'] = $category['category'];
$this->data['banner_title'] = $category['title'];
$this->data['banner_description'] = $category['description'];
$this->data['banner_image'] = $category['image'];
//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->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'category/' . $alias_level1 . '/' . $alias_level2 . '/';
$config['total_rows'] = $this->product_m->count_products_by_category($category['id_categories']);
$config['per_page'] = $per_page->products_displayed;
$config['uri_segment'] = 4;
$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_by_category($category['id_categories'], $config['per_page'], $this->uri->segment($config['uri_segment']));
}
}
$this->data['alias_level1'] = $alias_level1;
$this->data['alias_level2'] = $alias_level2;
//Get SEO
$this->data_header['browser_title'] = 'Category - ' . ucwords($category['category']);
$this->data_header['meta_description'] = $category['meta_description'];
$this->load->view('template/header', $this->data_header);
$this->load->view('customize', $this->data);
$this->load->view('template/footer', $this->data_footer);
//set current category to session, so it can be track to product page
/* $this->session->set_userdata('current_viewed_category', $alias); */
}
}