|
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/rabbithabit.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) {
//check if product exist
$this->db->select('*')->from('products')->where('alias', $alias)->where('product_status', 1);
$data['product'] = $this->db->get()->row();
if(count($data['product']) == 0 || $alias == NULL) { show_404(); }
//set url to session, so can be access by cart page, continue shopping link button
$this->session->set_userdata('productpage_to_cart', base_url() . 'product/' . $alias);
//get this product data
$this->db->select('*')->from('products')->where('alias', $alias);
$data['product'] = $this->db->get()->row();
// echo "<pre>";
// var_dump($data['product']); exit();
//get this product details
$product_id = (int) $data['product']->id_products;
//get product code (SKU), weight, and stock display status
$this->db->select('show_product_sku, show_product_weight, show_product_stock')->from('configuration')->where('id_configuration', 1);
$display_status = $this->db->get()->row();
$data['display_sku'] = $display_status->show_product_sku;
$data['display_weight'] = $display_status->show_product_weight;
$data['display_stock'] = $display_status->show_product_stock;
$this->load->helper('product');
$category_discount_percentage = category_discount($product_id);
//check if point rewards program is active or not.
$this->db->select('*')->from('point_rewards')->where('id_point_rewards', 1);
$data['point_rewards'] = $this->db->get()->row();
//get brand name
$this->db->select('brand')->from('brands')->where('id_brands', $data['product']->brand_id);
$data['brand_name'] = $this->db->get()->row()->brand;
//LOAD LANGUAGE FILES
if($this->session->userdata('site_lang') == 'english') {
$this->lang->load('product_detail', 'english');
$this->lang->load('product_list', 'english');
} else {
$this->lang->load('product_detail', 'indonesian');
$this->lang->load('product_list', 'indonesian');
}
//check for flash sale
if($this->session->has_userdata('flashsale_id_active')) {
//if flashdata session is currently active
$this->db->select('product_id, discounted_price')->from('flashsale_products')->where('flashsale_id',$this->session->userdata('flashsale_id_active'))->where('product_id',$product_id);
$data['flashsale_product'] = $this->db->get()->row();
}
//get product reviews
$this->db->select('*')->from('product_review')->where('product_id', $product_id);
$data['product_reviews'] = $this->db->get()->result();
// echo "<pre>";
// var_dump($data['product_reviews']);
// exit();
$this->db->select('AVG(CAST(rating AS UNSIGNED)) as avg_rating')->from('product_review')->where('product_id', $product_id);
$data['avg_product_reviews'] = (int)$this->db->get()->row()->avg_rating;
//get INITIAL varians
$this->db->select('attribute_id');
$this->db->from('product_combination');
$this->db->join('product_attributes', 'product_attributes.id = product_combination.attribute_id');
$this->db->where('product_id', $product_id);
$this->db->where('attribute_id != ', NULL);
$this->db->order_by('priority', 'ASC')->group_by('attribute_id');
$data['varians'] = $this->db->get()->result();
//get INITIAL varian details (each varian will have 1 initial detail)
$data['initial_varian_detail_ids'] = array();
foreach ($data['varians'] as $varian) {
$this->db->select('attribute_detail_id')->from('product_combination')->join('product_attributes_detail', 'product_attributes_detail.id = product_combination.attribute_detail_id')->where('product_id', $product_id)->where('attribute_id', $varian->attribute_id)->order_by('priority', 'ASC')->limit(1);
$attribute_detail_id = $this->db->get()->row()->attribute_detail_id;
if($attribute_detail_id != NULL) {
$data['initial_varian_detail_ids'][] = $attribute_detail_id;
}
}
//get TOC Indent
$this->db->select('toc')->from('toc')->where('id_toc', 3);
$data['toc_indent'] = $this->db->get()->row()->toc;
$data['modules_setting'] = $this->data['modules_setting'];
//get SEO
if($data['product']->meta_title === '') {
$this->data_header['browser_title'] = 'Produk ' . ucwords($data['product']->title) . ' - ' . ucwords($this->data_header['website_name']);
} else {
$this->data_header['browser_title'] = $data['product']->meta_title;
}
if(empty($data['product']->meta_description)) {
$this->data_header['meta_description'] = 'Produk ' . ucwords($data['product']->title) . ' - ' . ucwords($this->data_header['website_name']);
} else {
$this->data_header['meta_description'] = $data['product']->meta_description;
}
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view("themes/$this->theme_no/product", $data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
}