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 Productcustom extends Public_Controller { public function __construct() { parent::__construct(); } public function get($alias = NULL) { if ($alias == NULL) { show_404(); } //ajax call from product page, get detail by color if($alias == 'ajax_get_productdetailbycolor') { //test if ajax call to prevent direct access if(!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $color_text = $this->input->post('color_text'); $product_id = (int) $this->input->post('product_id'); //get first item of product detail, change prices $data_productdetail['product_detail'] = $this->db->select('price, discounted_price, sku, attributes, stock, image')->from('product_details')->where('product_id', $product_id)->like('attributes', $color_text)->get()->row_array(); $product_prices_html = $this->load->view('ajax_product_prices', $data_productdetail, TRUE); //$initial_colorcode & $initial_colorname changes $initial_colorname = ucwords(trim($color_text)); $initial_colorcode = $this->db->select('color_code')->from('product_attributes')->where('product_attributes', $initial_colorname)->get()->row()->color_code; //get all Sizes from database $data_productsizes['all_sizes'] = array(); $sizes = $this->db->select('product_attributes')->from('product_attributes')->where('id_product_size', 3)->get()->result_array(); foreach($sizes as $size) { $attribute = (int) $size['product_attributes']; if($attribute != 0) { array_push($data_productsizes['all_sizes'], $attribute); } } sort($data_productsizes['all_sizes']); //get available sizes for chosen initial color $available_attributes = $this->db->select('attributes, stock')->from('product_details')->where('product_id', $product_id)->like('attributes', $initial_colorname)->get()->result_array(); $data_productsizes['available_sizes'] = array(); foreach($available_attributes as $attribute) { $attr_array = explode(',', $attribute['attributes']); array_push($data_productsizes['available_sizes'], $attr_array[0]); } $chosen_attributes = $data_productdetail['product_detail']['attributes']; $attributes_arr = explode(',', $chosen_attributes); $data_productsizes['initial_size'] = $attributes_arr[0]; $product_sizes_html = $this->load->view('ajax_product_sizes', $data_productsizes, TRUE); //get chosen image switch ($data_productdetail['product_detail']['image']) { case 'image1': $image_file = $this->db->select('image1')->from('products')->where('id_products', $product_id)->get()->row()->image1; break; case 'image2': $image_file = $this->db->select('image2')->from('products')->where('id_products', $product_id)->get()->row()->image2; break; case 'image3': $image_file = $this->db->select('image3')->from('products')->where('id_products', $product_id)->get()->row()->image3; break; case 'image4': $image_file = $this->db->select('image4')->from('products')->where('id_products', $product_id)->get()->row()->image4; break; case 'image5': $image_file = $this->db->select('image5')->from('products')->where('id_products', $product_id)->get()->row()->image5; break; } return $this->output ->set_content_type('application/json') ->set_status_header(200) ->set_output(json_encode([ 'initial_colorname' => $initial_colorname, 'initial_colorcode' => $initial_colorcode, 'initial_size' => $data_productsizes['initial_size'], 'product_prices_html' => $product_prices_html, 'product_sizes_html' => $product_sizes_html, 'chosen_image' => base_url() . 'uploads/product/large/' . $image_file ])); } //ajax call from product page, get detail by size if($alias == 'ajax_get_productdetailbysize') { //test if ajax call to prevent direct access if(!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $size = $this->input->post('size'); $color_text = strtolower($this->input->post('color_text')); $product_id = (int) $this->input->post('product_id'); $attributes = $size . ',' . $color_text; //get product detail, change prices $data_productdetail['product_detail'] = $this->db->select('price, discounted_price, sku, attributes, stock')->from('product_details')->where('product_id', $product_id)->where('attributes', $attributes)->get()->row_array(); $product_prices_html = $this->load->view('ajax_product_prices', $data_productdetail, TRUE); //$initial_colorcode & $initial_colorname changes $initial_colorname = ucwords(trim($color_text)); $initial_colorcode = $this->db->select('color_code')->from('product_attributes')->where('product_attributes', $initial_colorname)->get()->row()->color_code; //get all Sizes from database $data_productsizes['all_sizes'] = array(); $sizes = $this->db->select('product_attributes')->from('product_attributes')->where('id_product_size', 3)->get()->result_array(); foreach($sizes as $item) { $attribute = (int) $item['product_attributes']; if($attribute != 0) { array_push($data_productsizes['all_sizes'], $attribute); } } sort($data_productsizes['all_sizes']); //get available sizes for chosen initial color $available_attributes = $this->db->select('attributes, stock')->from('product_details')->where('product_id', $product_id)->like('attributes', $initial_colorname)->get()->result_array(); $data_productsizes['available_sizes'] = array(); foreach($available_attributes as $attribute) { $attr_array = explode(',', $attribute['attributes']); array_push($data_productsizes['available_sizes'], $attr_array[0]); } $data_productsizes['initial_size'] = $size; $product_sizes_html = $this->load->view('ajax_product_sizes', $data_productsizes, TRUE); return $this->output ->set_content_type('application/json') ->set_status_header(200) ->set_output(json_encode([ 'initial_colorname' => $initial_colorname, 'initial_colorcode' => $initial_colorcode, 'initial_size' => $size, 'product_prices_html' => $product_prices_html, 'product_sizes_html' => $product_sizes_html ])); } //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 details $data['product_details'] = $this->db->select('price, discounted_price, sku, attributes, stock')->from('product_details')->where('product_id', $data['product']['id_products'])->order_by('id_product_details', 'ASC')->get()->result_array(); //get all available colors for this product $data['available_colors'] = array(); foreach($data['product_details'] as $detail) { $attr = explode(',', $detail['attributes']); //get color code $color_code = $this->db->select('color_code')->from('product_attributes')->where('product_attributes', $attr[1])->get()->row()->color_code; $color_data = array( 'color_text' => $attr[1], 'color_code' => $color_code ); $color_exist = FALSE; //check if color_text exist inside $data['available_colors'] foreach($data['available_colors'] as $color) { if($color['color_text'] == $color_data['color_text']) { $color_exist = TRUE; break; } } if(!$color_exist) { array_push($data['available_colors'], $color_data); } } //get all Sizes from database $data['all_sizes'] = array(); $sizes = $this->db->select('product_attributes')->from('product_attributes')->where('id_product_size', 3)->get()->result_array(); foreach($sizes as $size) { $attribute = (int) $size['product_attributes']; if($attribute != 0) { array_push($data['all_sizes'], $attribute); } } sort($data['all_sizes']); if(count($data['product_details']) > 0) { //get first item of product detail $data['product_detail'] = $data['product_details'][0]; } else { $data['product_detail'] = NULL; } if(isset($data['product_detail']['attributes'])) { $initial_attr = explode(',', $data['product_detail']['attributes']); //get first color name & code $data['initial_colorname'] = ucwords(trim($initial_attr[1])); $data['initial_colorcode'] = $this->db->select('color_code')->from('product_attributes')->where('product_attributes', trim($initial_attr[1]))->get()->row()->color_code; $data['initial_size'] = $initial_attr[0]; //get available sizes for chosen initial color $available_attributes = $this->db->select('attributes, stock')->from('product_details')->where('product_id', $data['product']['id_products'])->like('attributes', $initial_attr[1])->get()->result_array(); $data['available_sizes'] = array(); foreach($available_attributes as $attribute) { $attr_array = explode(',', $attribute['attributes']); array_push($data['available_sizes'], $attr_array[0]); } } else { $initial_attr = NULL; //get first color name & code $data['initial_colorname'] = 'Not available'; $data['initial_colorcode'] = '#fff'; $data['available_sizes'] = array(); } //Get options of attribute Heels Type $data['heels_types'] = $this->db->select('id_attribute, product_attributes, additional_price, image')->from('attribute_product')->join('product_attributes', 'product_attributes.id_product_attributes = attribute_product.id_attribute')->where('id_product', $data['product']['id_products'])->where('type', 'heels type')->get()->result_array(); //Get options of attribute Heels height $data['heels_height'] = $this->db->select('id_attribute, product_attributes, additional_price, image')->from('attribute_product')->join('product_attributes', 'product_attributes.id_product_attributes = attribute_product.id_attribute')->where('id_product', $data['product']['id_products'])->where('type', 'heels height')->get()->result_array(); //Get options of attribute platform style $data['platform_style'] = $this->db->select('id_attribute, product_attributes, additional_price, image')->from('attribute_product')->join('product_attributes', 'product_attributes.id_product_attributes = attribute_product.id_attribute')->where('id_product', $data['product']['id_products'])->where('type', 'platform style')->get()->result_array(); //Get options of attribute platform height $data['platform_height'] = $this->db->select('id_attribute, product_attributes, additional_price, image')->from('attribute_product')->join('product_attributes', 'product_attributes.id_product_attributes = attribute_product.id_attribute')->where('id_product', $data['product']['id_products'])->where('type', 'platform height')->get()->result_array(); //get initial name additional prices $data['initialname_price'] = 0; $initialname_price = $this->db->select('additional_price')->from('product_attributes')->where('id_product_size', 8)->where('additional_price !=', 0)->get()->row_array(); if($initialname_price) { $data['initialname_price'] = $initialname_price['additional_price']; } //get initial name pictures $data['initialname_images'] = $this->db->select('image, image2, image3')->from('product_attributes')->where('id_product_size', 8)->where('additional_price > ', 0)->get()->row_array(); //get product on same category (you may like) $this->db->select_max('id_category')->from('category_product')->where('id_product', $data['product']['id_products']); $category_id = $this->db->get()->row()->id_category; //select $products by given $category_id $this->db->select('id_product')->from('category_product')->where('id_category', $category_id)->order_by('id_product', 'RANDOM')->limit(3); $id_products = $this->db->get()->result_array(); $data['similar_products'] = array(); $count = 0; foreach($id_products as $id) { //get similar product $this->db->select('alias, image1')->from('products')->where('id_products', $id['id_product'])->where('product_status', '1'); $data['similar_products'][$count] = $this->db->get()->row_array(); $count++; } //get greeting card price $data['greetingcard_price'] = $this->db->select('greetingcard_price')->from('configuration')->where('id_configuration', 1)->get()->row()->greetingcard_price; $this->load->helper('cms_helper'); $this->load->view('template/header', $this->data_header); $this->load->view('product-custom', $data); $this->load->view('template/footer', $this->data_footer); } }