|
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/helpers/ |
Upload File : |
<?php
function HTMLToRGB($htmlCode){
if($htmlCode[0] == '#')
$htmlCode = substr($htmlCode, 1);
if (strlen($htmlCode) == 3)
{
$htmlCode = $htmlCode[0] . $htmlCode[0] . $htmlCode[1] . $htmlCode[1] . $htmlCode[2] . $htmlCode[2];
}
$r = hexdec($htmlCode[0] . $htmlCode[1]);
$g = hexdec($htmlCode[2] . $htmlCode[3]);
$b = hexdec($htmlCode[4] . $htmlCode[5]);
return $b + ($g << 0x8) + ($r << 0x10);
}
function RGBToHSL($RGB) {
$r = 0xFF & ($RGB >> 0x10);
$g = 0xFF & ($RGB >> 0x8);
$b = 0xFF & $RGB;
$r = ((float)$r) / 255.0;
$g = ((float)$g) / 255.0;
$b = ((float)$b) / 255.0;
$maxC = max($r, $g, $b);
$minC = min($r, $g, $b);
$l = ($maxC + $minC) / 2.0;
if($maxC == $minC)
{
$s = 0;
$h = 0;
}
else
{
if($l < .5)
{
$s = ($maxC - $minC) / ($maxC + $minC);
}
else
{
$s = ($maxC - $minC) / (2.0 - $maxC - $minC);
}
if($r == $maxC)
$h = ($g - $b) / ($maxC - $minC);
if($g == $maxC)
$h = 2.0 + ($b - $r) / ($maxC - $minC);
if($b == $maxC)
$h = 4.0 + ($r - $g) / ($maxC - $minC);
$h = $h / 6.0;
}
$h = (int)round(255.0 * $h);
$s = (int)round(255.0 * $s);
$l = (int)round(255.0 * $l);
return (object) Array('hue' => $h, 'saturation' => $s, 'lightness' => $l);
}
function get_varian_data($varian_id, $product_id) {
$ci = & get_instance();
//get varian name
$ci->db->select('product_attribute, is_color, product_attribute_en')->from('product_attributes')->where('id', $varian_id);
$varian_name_data = $ci->db->get()->row();
if($ci->session->userdata('site_lang') == 'english') {
$varian_array['varian_name'] = $varian_name_data->product_attribute_en;
} else {
$varian_array['varian_name'] = $varian_name_data->product_attribute;
}
$varian_array['is_color'] = $varian_name_data->is_color;
//get initial varian detail
if($ci->session->userdata('site_lang') == 'english') {
$ci->db->select('product_attributes_detail.color_hex, product_attributes_detail.product_attribute_id, attribute_detail_id, product_details_id, attribute_detail_en as attribute_detail, image')
->from('product_combination')
->join('product_attributes_detail', 'product_attributes_detail.id = product_combination.attribute_detail_id')
->where('attribute_id', $varian_id)
->where('product_id', $product_id)
->group_by('attribute_detail_id')
->order_by('product_attributes_detail.priority', 'ASC');
} else {
$ci->db->select('product_attributes_detail.color_hex, product_attributes_detail.product_attribute_id, attribute_detail_id, product_details_id, attribute_detail, image')
->from('product_combination')
->join('product_attributes_detail', 'product_attributes_detail.id = product_combination.attribute_detail_id')
->where('attribute_id', $varian_id)
->where('product_id', $product_id)
->group_by('attribute_detail_id')
->order_by('product_attributes_detail.priority', 'ASC');
}
$varian_array['varian_details'] = $ci->db->get()->result();
return $varian_array;
}
function check_current_stock($id_product) {
$ci = & get_instance();
$ci->db->select('id')->from('product_details')->where('product_id', $id_product)->where('stock !=', 0);
$count_current_stock = $ci->db->get()->num_rows();
return $count_current_stock;
}
function category_discount($id_product) {
$ci = & get_instance();
//check this product belong to which categories
$ci->db->select('id_category')->from('category_product')->where('id_product', $id_product);
$categories = $ci->db->get()->result_array();
$product_existing_categories = array();
foreach($categories as $key => $category) {
$product_existing_categories[] = $category['id_category'];
}
$level1_category = NULL;
$level2_category = NULL;
$level3_category = NULL;
foreach($product_existing_categories as $category_id) {
//check if this category_id has parent
$ci->db->select('parent')->from('categories')->where('id_categories', $category_id);
$parent_category_id = $ci->db->get()->row()->parent;
if($parent_category_id != NULL) {
//this category still have parent
//check if the parent category still have parent
$ci->db->select('parent')->from('categories')->where('id_categories', $parent_category_id);
$parent2_category_id = $ci->db->get()->row()->parent;
if($parent2_category_id != NULL) {
//this is level 3 category
$level3_category = $category_id;
} else {
//this is level 2 category
$level2_category = $category_id;
}
} else {
//this category is parent (level 1)
$level1_category = $category_id;
}
}
if($level3_category != NULL) {
//check if this category has category discount
$ci->db->select('discount_active, percentage_discount')->from('categories')->where('id_categories', $level3_category);
$category_discount = $ci->db->get()->row();
if($category_discount->discount_active == 'yes') {
$category_discount_percentage = $category_discount->percentage_discount;
} else {
$category_discount_percentage = NULL;
}
} else {
//$level3_category == NULL
if($level2_category != NULL) {
//check if this category has category discount
$ci->db->select('discount_active, percentage_discount')->from('categories')->where('id_categories', $level2_category);
$category_discount = $ci->db->get()->row();
if($category_discount->discount_active == 'yes') {
$category_discount_percentage = $category_discount->percentage_discount;
} else {
$category_discount_percentage = NULL;
}
} else {
//$level2_category == NULL
if($level1_category != NULL) {
//check if this category has category discount
$ci->db->select('discount_active, percentage_discount')->from('categories')->where('id_categories', $level1_category);
$category_discount = $ci->db->get()->row();
if($category_discount->discount_active == 'yes') {
$category_discount_percentage = $category_discount->percentage_discount;
} else {
$category_discount_percentage = NULL;
}
}
}
}
return $category_discount_percentage;
}
function get_product_price($id_product) {
$ci = & get_instance();
$product_price_array = array();
if(isset($ci->session->userdata('customer')['customer_id'])) {
//get product detail id (for 1st detail only)
$ci->db->select('id')->from('product_details')->where('product_id', $id_product)->limit(1);
$id_product_detail = $ci->db->get()->row()->id;
//check if customer is a reseller. if reseller use reseller price
$ci->db->select('reseller_id')->from('customers')->where('id_customers', $ci->session->userdata('customer')['customer_id']);
$reseller_id = $ci->db->get()->row()->reseller_id;
//check if reseller price already available (already input by admin)
$ci->db->select('price')->from('resellers_price')->where('reseller_id', $reseller_id)->where('product_detail_id', $id_product_detail);
$count_reseller = $ci->db->get()->num_rows();
if($reseller_id != NULL && $count_reseller > 0) {
//customer is reseller. use reseller price
$ci->db->select('price')->from('resellers_price')->where('reseller_id', $reseller_id)->where('product_detail_id', $id_product_detail);
$product_price = $ci->db->get()->row();
$product_price_array['reseller_id'] = $reseller_id;
$product_price_array['count_reseller'] = $count_reseller;
} else {
//get product price and discount price (retail prices)
$ci->db->select('price, discounted_price')->from('product_details')->where('product_id', $id_product)->limit(1);
$product_price_array['reseller_id'] = NULL;
$product_price_array['count_reseller'] = 0;
$product_price = $ci->db->get()->row();
}
$product_price_array['product_price'] = $product_price;
} else {
//get product price and discount price (retail prices)
$ci->db->select('price, discounted_price')->from('product_details')->where('product_id', $id_product)->limit(1);
$product_price = $ci->db->get()->row();
$product_price_array['product_price'] = $product_price;
$product_price_array['reseller_id'] = NULL;
$product_price_array['count_reseller'] = 0;
}
return $product_price_array;
}
function get_product_thumbnail($product_id) {
$ci = & get_instance();
//get product image 1
$ci->db->select('priority,image')->from('product_images')->where('product_id', $product_id)->where('status', '1')->order_by('product_details_id', 'ASC')->order_by('priority', 'ASC');
$product_image = $ci->db->get()->row();
if(count($product_image) > 0) {
//get product image 2
$ci->db->select('image')->from('product_images')->where('product_id', $product_id)->where('status', '1')->where('priority >', $product_image->priority)->where('status', '1')->order_by('product_details_id', 'ASC')->order_by('priority', 'ASC');
$product_image2 = $ci->db->get()->row();
} else {
$product_image2 = NULL;
}
//get placeholder image
$ci->db->select('image_not_available')->from('configuration')->where('id_configuration', 1);
$placeholder_image = $ci->db->get()->row()->image_not_available;
if(count($product_image) == 0) {
$src1 = base_url() . 'uploads/' . $placeholder_image;
} else {
$src1 = base_url() . 'uploads/product/small/' . $product_image->image;
}
if(!isset($product_image2) || count($product_image2) == 0) {
$src2 = base_url() . 'uploads/' . $placeholder_image;
} else {
$src2 = base_url() . 'uploads/product/small/' . $product_image2->image;
}
$thumbnails_array = array(
'image1' => $src1,
'image2' => $src2
);
return $thumbnails_array;
}
function get_lowest_price($product_id) {
$ci = & get_instance();
//get lowest normal price
$ci->db->select('price, id, discounted_price')->from('product_details')->where('product_id', $product_id)->where('price !=', 0)->order_by('price', 'ASC')->limit(1);
$lowest_price = $ci->db->get()->row();
return $lowest_price;
}