|
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 get_product_id($item_id) {
$ci = & get_instance();
//get product id
$ci->db->select('product_id')->from('product_details')->where('id', $item_id);
$product_id = $ci->db->get()->row()->product_id;
return $product_id;
}
function calculate_shipping_fee($shipping_id, $warehouse_id, $product_id, $item_id, $qty, $shipping_id_subdistrict) {
/* echo $shipping_id . '-<br>';
echo $warehouse_id . '-<br>';
echo $product_id . '-<br>';
echo $item_id . '-<br>';
echo $qty . '-<br>';
echo $shipping_id_subdistrict . '-<br>';
exit(); */
$ci = & get_instance();
//get shipping method name
$ci->db->select('name,shipper,carrier, service_code1, service_code2')->from('shipment_method')->where('id', $shipping_id);
$shipping_method = $ci->db->get()->row();
$shipping_name = $shipping_method->name;
$shipping_carrier = $shipping_method->carrier;
$shipping_shipper = $shipping_method->shipper;
$service_code1 = $shipping_method->service_code1;
$service_code2 = $shipping_method->service_code2;
//get warehose sub district id
$ci->db->select('id_subdistrict')->from('warehouse')->where('id', $warehouse_id);
$warehouse_subdistrict_id = $ci->db->get()->row()->id_subdistrict;
//get product weight
$ci->db->select('weight, length, width, height')->from('product_details')->where('product_id', $product_id)->where('id', $item_id);
$product_dimension = $ci->db->get()->row();
$product_weight = $product_dimension->weight; //gram
$product_length = $product_dimension->length; //cm
$product_width = $product_dimension->width; //cm
$product_height = $product_dimension->height; //cm
//check if volume is bigger than weight
$volume_weight = $product_length * $product_width * $product_height / 6000; //kg
if(($volume_weight * 1000) >= $product_weight) {
$weight = $volume_weight * 1000;
} else {
$weight = $product_weight;
}
$total_weight_gram = ceil($weight * $qty); //gram
//calculate shipping rate
$rajaongkir_cost = get_rajaongkir_ongkos($warehouse_subdistrict_id, $shipping_id_subdistrict, $total_weight_gram, $shipping_carrier);
/* echo '<pre>';
print_r($rajaongkir_cost);
echo '</pre>';
exit(); */
//check if weight is zero. If zero, then rajaongkir cannot proceed..
if($total_weight_gram > 0) {
//check which key has carrier name
if($service_code2 != NULL) {
if(count($rajaongkir_cost['rajaongkir']['results'][0]['costs']) != 0) {
foreach($rajaongkir_cost['rajaongkir']['results'][0]['costs'] as $key => $result) {
if($result['service'] == $service_code1 || $result['service'] == $service_code2) {
$total_shipping_fee = $result['cost'][0]['value'];
break;
} else {
$total_shipping_fee = 0; //service is not available
}
}
} else {
$total_shipping_fee = 0; //service is not available
}
} else {
if(count($rajaongkir_cost['rajaongkir']['results'][0]['costs']) != 0) {
foreach($rajaongkir_cost['rajaongkir']['results'][0]['costs'] as $key => $result) {
if($result['service'] == $service_code1) {
$total_shipping_fee = $result['cost'][0]['value'];
break;
} else {
$total_shipping_fee = 0; //service is not available
}
}
} else {
$total_shipping_fee = 0; //service is not available
}
}
} else {
//total weight gram is zero
$total_shipping_fee = 0; //service is not available
}
if($ci->session->userdata('customer') && $ci->session->userdata('customer')['customer_type'] == 'regular') {
//check if there is regional free shipping, if 0, then total_shipping_fee is 0
$free_shipping_price = $ci->db->select('free_shipping_type_subsidi')->from('configuration')->where('id_configuration',1)->get()->row()->free_shipping_type_subsidi;
$free_shipping_type = $ci->db->select('free_shipping_type')->from('configuration')->where('id_configuration',1)->get()->row()->free_shipping_type;
$get_grand_total = 0;
foreach ($ci->session->userdata('shipping_cart') as $item){
$get_grand_total = $get_grand_total + $item['subtotal'];
}
$q_config_cond = $ci->db->select('type_cond_prov_free_shipping, cond_more_prov_free_shipping, cond_less_prov_free_shipping')->from('configuration')->where('id_configuration',1)->get()->row();
$shipping_info = array();
if($free_shipping_type == 'region') {
$selected_region_province = $ci->db->select('province_id')->from('free_shipping_region')->where('configuration_id',1)->get()->result();
//get destination province_id
$shipping_id_district = $ci->db->select('indonesia_id_district')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $shipping_id_subdistrict)->get()->row()->indonesia_id_district;
$shipping_id_province = $ci->db->select('indonesia_id_province')->from('indonesia_districts')->where('rajaongkir_id_district', $shipping_id_district)->get()->row()->indonesia_id_province;
$act_cond_free_shipping = false;
switch ($q_config_cond->type_cond_prov_free_shipping) {
case 'more_than':
if ($get_grand_total >= $q_config_cond->cond_more_prov_free_shipping) {
$act_cond_free_shipping = true;
}
break;
case 'less_than':
if ($get_grand_total <= $q_config_cond->cond_less_prov_free_shipping) {
$act_cond_free_shipping = true;
}
break;
default:
$act_cond_free_shipping = true;
break;
}
if ($act_cond_free_shipping == true) {
foreach ($selected_region_province as $region_province) {
if($region_province->province_id == $shipping_id_province) {
if($free_shipping_price == 0) {
$shipping_info['free_shipping_applied'] = 'yes';
$total_shipping_fee = 0;
break;
}
}
}
}
}
}
$shipping_info['total_shipping_fee'] = $total_shipping_fee;
$shipping_info['shipping_name'] = $shipping_name;
return $shipping_info;
}
function get_province_name($province_id) {
$ci = & get_instance();
$province_name = $ci->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', $province_id)->get()->row()->province;
return $province_name;
}
function get_district_name($district_id) {
$ci = & get_instance();
$district_name = $ci->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', $district_id)->get()->row()->district;
return $district_name;
}
function get_subdistrict_name($subdistrict_id) {
$ci = & get_instance();
$subdistrict_name = $ci->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $subdistrict_id)->get()->row()->subdistrict;
return $subdistrict_name;
}