|
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 Product extends Public_Controller
{
public function __construct()
{
parent::__construct();
}
public function get($alias = NULL)
{
if ($alias == NULL) { show_404(); }
//get specific product data
$this->db->select('*')->from('products')->where('alias', $alias);
$data['product'] = $this->db->get()->row_array();
if (!$data['product']) { show_404(); }
//get SEO
$this->data_header['browser_title'] = 'Product - ' . ucwords($data['product']['title']);
$this->data_header['meta_description'] = $data['product']['meta_description'];
$this->data_header['meta_keywords'] = $data['product']['meta_keywords'];
//get initial product detail
$product_id = (int) $data['product']['id_products'];
$this->db->select('price, discounted_price, sku, attributes')->from('product_details')->where('product_id', $product_id)->order_by('id_product_details', 'ASC')->limit(1);
//$this->db->where('stock !=', 0);
$query = $this->db->get();
$data['product_detail'] = $query->row_array();
//IF CURRENT CATEGORY SESSION EXIST
//get category alias from session. This session was created at category.php controller
//if session category alias is set..
if ($this->session->userdata('current_viewed_category'))
{
$data['category_alias'] = $this->session->userdata('current_viewed_category');
//get related products with given category alias
//get category ID
$this->db->select('id_categories')->from('categories')->where('alias', $data['category_alias']);
$category_id = $this->db->get()->row();
//get related products (products in the same category)
$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->id_categories);
$this->db->where('products.product_status', '1');
$this->db->limit(4);
$data['related_products'] = $this->db->get()->result();
}
//IF CURRENT BRAND SESSION EXIST
//get brand alias from session. This session was created at brand.php controller
//if session brand alias is set..
if ($this->session->userdata('current_viewed_brand'))
{
$data['brand_alias'] = $this->session->userdata('current_viewed_brand');
//get related products with given brand alias
//get brand ID
$this->db->select('id_brands')->from('brands')->where('alias', $data['brand_alias']);
$brand_id = $this->db->get()->row();
//get related products (products in the same brand)
/* $this->db->select('*');
$this->db->from('products');
$this->db->where('brand_id', $brand_id->id_brands);
$this->db->where('products.product_status', '1');
$this->db->limit(4);
$data['related_products'] = $this->db->get()->result(); */
}
//get brand name
$this->db->select('brand')->from('brands')->where('id_brands', $data['product']['brand_id']);
$data['brand_name'] = $this->db->get()->row()->brand;
//get all product reviews
/* $this->db->select('*')->from('product_review')->where('product_id', $product_id)->order_by('review_date', 'DESC');
$data['product_reviews'] = $this->db->get()->result(); */
//check the stock. if no stock at all, display no stock.
$this->db->select('stock')->from('product_details')->where('product_id', $product_id)->where('stock !=', 0);
$data['count_product_stock'] = $this->db->get()->num_rows();
//get average reviews
/* $this->db->select('rating')->from('product_review')->where('product_id', $product_id);
$data['review_ratings'] = $this->db->get()->result();
if (count($data['review_ratings']) != 0)
{
$sum_review = 0;
foreach ($data['review_ratings'] as $rating)
{
$sum_review = $sum_review + $rating->rating;
}
$data['average_rating'] = floor($sum_review / count($data['review_ratings']));
} */
$this->load->view('template/header', $this->data_header);
$this->load->view('product', $data);
$this->load->view('template/footer', $this->data_footer);
}
}