/* * Created on Sep 26, 2006 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ include_once 'dataset.php'; include_once 'global.php'; include_once 'modules.mailer.php'; include_once 'modules.orders.php'; include_once 'modules.products.php'; include_once 'modules.upsOnline.php'; include_once 'modules.new_cart_v2.php'; include_once 'modules.address.php'; include_once 'modules.utils.php'; include_once 'modules.googlecheckout.php'; class shipping_v2 { public $zones; public $verbose = ''; public $max_ships_in_days_val = array(); function shipping_carrier_from_shipping_type($order_id) { global $pdo_db1; $shipping_infos = $pdo_db1->pquery( " SELECT orders.website, orders.shipping_type, shipping_types.carrier, (SELECT address.state from address where address.id=orders.shipping_address_id) as state FROM orders INNER JOIN shipping_types ON orders.shipping_type = shipping_types.id WHERE orders.id = '" . $order_id . "' " ); $shipping_info = $shipping_infos[0]; $carrier_id = $shipping_info['carrier']; if ( $shipping_info['website'] == '2' || $shipping_info['website'] == '3' || $shipping_info['website'] == '5' || $shipping_info['website'] == '6' || $shipping_info['website'] == '7' || $shipping_info['website'] == '21' || $shipping_info['website'] == '24' || $shipping_info['website'] == '26' ) { // over-write ARTTOFRAMES $carrier_id = '2'; // FEDEX $state = ['NY', 'PA', 'CT', 'NH', 'NJ']; if ( ($shipping_info['website'] == '2' || $shipping_info['website'] == '3') && in_array($shipping_info['state'], $state) ) { //SAMA DAY $carrier_id = '1'; // USPS SAME DAY } if ($shipping_info['shipping_type'] == '28') { //SAMA DAY $carrier_id = '3'; // USPS SAME DAY } } return $carrier_id; } function update_status($order_id, $status, $fields) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); //print_r($fields); $fields_ship = []; $fields_ship['order_id'] = $order_id; $fields_ship['status_id'] = $status; $fields_ship['price'] = $fields['price']; $fields_ship['cost_price'] = $fields['cost_price']; $fields_ship['fld1'] = $fields['carrier']; $fields_ship['fld2'] = $fields['tracking_number']; $shipping_info_id = $data1->add_record( 'shipping_history', $fields_ship ); $fields_ord = []; $fields_ord['shipping_status'] = $status; $fields_ord['shipping_info_id'] = $shipping_info_id; $fields_ord['shipping_cost'] = $fields['price']; $o = new orders(); $res = $o->update_order($order_id, $fields_ord); if ($res === false) { return false; } else { return $res; } } function shipping_info($shipping_info_id) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); //$res = $data1->get_record("shipping_history", "id", $shipping_info_id); $res = $pdo_db1->pquery( "SELECT * FROM shipping_history WHERE id = '" . $shipping_info_id . "' ", 'FETCH_BOTH' ); if ($pdo_db1->pdo_num_rows($res) > 0) { $info = $res[0]; return $info; } else { return false; } } function order_shipped( $order_id, $status_code, $user_id, $tracking_num, $carrier, $shipping_price, $force_email = false ) { global $pdo_db1; $o = new orders(); $order_info = $o->order_info($order_id); $fields = []; $fields['price'] = $order_info['shipping_cost']; $fields['carrier'] = $carrier; $fields['cost_price'] = $shipping_price; $fields['tracking_number'] = $tracking_num; $order_shipping_info = $o->shipping_info($order_id); $add_traking = 'yes'; if (isset($order_shipping_info) && $order_shipping_info != '') { foreach ($order_shipping_info as $key => $shipping_info) { if ($shipping_info['tracking_number'] == $tracking_num) { // commented add tracking because the orders.ship_date is updating Null in orders DB table. // Update on 2021/03/10 Farhan Qazi //$add_traking = 'no'; // echo '1'; } else { // echo '2'; } } } if ($add_traking == 'no') { return false; } else { $res = $this->update_status($order_id, $status_code, $fields); $fields = []; if ( $order_info['ship_date'] == '0000-00-00' || $order_info['ship_date'] == '' || $order_info['ship_date'] == null ) { $fields['ship_date'] = date('Y-m-d'); $d = new DataSet(); $d->update_record('orders', $fields, 'id', $order_id); } else { echo '
Ship date already assign
'; } if ($order_info['payment_type'] != '2' || $force_email == true) { //check if orders.admin_status = 15 then ignore shipping email $allow_to_send_shipping_email = 1; //send if ($order_info['admin_status'] == 15) { //Ready for Pickup / Waiting for Pickup $allow_to_send_shipping_email = 0; //not send } if ($allow_to_send_shipping_email) { /*new code: need to confirm*/ //$sqlSelCarrier = "SELECT tracking_number, carrier_id FROM `end_of_day` WHERE `order_id` LIKE '$order_id' LIMIT 1";//commented on 20-01-2016 ssd /*$sqlSelCarrier = "SELECT end_of_day.tracking_number, end_of_day.carrier_id, end_of_day.order_id, orders.website FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE `order_id` LIKE '$order_id' AND orders.website = '2' ORDER BY end_of_day.id DESC LIMIT 1 ";*/ //Query changed date 24th Jan, 2017 //Task: on repalcemtn tracking email the custome got the original tracking information //damages sent with an additional "a" or "A" //Exclude void tracking numbers as well and only get valid tracking number - 19Apr2022 $sqlSelCarrier = "SELECT end_of_day.tracking_number, end_of_day.carrier_id, end_of_day.order_id, orders.website FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE end_of_day.order_id = '$order_id' AND orders.website = '2' AND end_of_day.void = '0' ORDER BY end_of_day.id DESC LIMIT 1"; $resSelCarrier = $pdo_db1->pquery($sqlSelCarrier); if ($pdo_db1->pdo_num_rows($resSelCarrier) > 0) { foreach ($resSelCarrier as $rowSelCarrier) { $carrier = $rowSelCarrier['carrier_id']; $tracking_num = $rowSelCarrier['tracking_number']; } } /*new code: need to confirm*/ $this->email_shipping_notification( $order_id, $carrier, $tracking_num ); } //if($allow_to_send_shipping_email) } if ($order_info['payment_type'] == '2') { $g = new googlecheckout(); $g->deliver_order($order_id, $carrier, $tracking_num); } //echo $add_traking . ' = ' ; //exit; return true; } } function email_shipping_notification( $order_id, $carrier, $tracking_num = '' ) { global $pdo_db1; $a = new art(); $isdamage_order = 0; /******************code added on 11march 2016 ssd*******************/ $mailer = new mailer(); $a = new address(); $o = new orders(); $p = new products(); $carriers = $this->list_carriers(); $order_info = $o->order_info($order_id); $date_array = $o->getDeliveryDateWithLabel($order_id); $isdamage_order = $order_info['damaged']; $product_weight = $o->product_weight( $order_id, 'weight', $isdamage_order ); $due_date_array = explode('-', $order_info['due_date']); $pdo_db1->pquery('SET character_set_results=utf8'); $pdo_db1->pquery('SET NAMES utf8'); // DD/MM/YY an in database it store as YY-MM-DD //$due_date = $due_date_array[2].'/'.$due_date_array[1].'/'.$due_date_array[0]; // now changes to MM/DD/YY -- 9 MAY 17 - $due_date = $due_date_array[1] . '/' . $due_date_array[2] . '/' . $due_date_array[0]; $shipping_types = $this->list_shipping_types(); $shipping_info = $a->address_info($order_info['shipping_address_id']); //$to = $order_info['user_info']['username']; // Updated the below code set the username if array exist on 2024-07-24 if(isset($order_info['user_info']['username']) && !empty($order_info['user_info']['username'])){ $to = $order_info['user_info']['username']; } //$to = 'atf_programmers@arttoframes.com'; ################# //START - To Check Is Tracking Number is Valid and Not Voided (i.e. end_of_day.void = '1')... If voided then stop shipping notification... 19Apr2022 if (strlen(trim($tracking_num)) > 0) { $is_tracking_num_voided = $p->specific_select( 'end_of_day', 'tracking_number', $tracking_num, 'void' ); if ($is_tracking_num_voided == '1') { $tracking_num = ''; //Made tracking number... In this case following if($tracking_num == '') will take care of valid tracking number } } //End - To Check Is Tracking Number is Valid and Not Voided (i.e. end_of_day.void = '1')... If voided then stop shipping notification... 19Apr2022 ################# if ($tracking_num == '') { //$tracking_num = $p->specific_select("end_of_day","order_id",$order_id,"tracking_number"); $sqlSelTrackNo = "SELECT end_of_day.tracking_number FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE end_of_day.order_id = '$order_id' AND orders.website = '2' AND end_of_day.void = '0' ORDER BY end_of_day.id DESC LIMIT 1"; $resSelTrackNo = $pdo_db1->pquery($sqlSelTrackNo); if ($pdo_db1->pdo_num_rows($resSelTrackNo) > 0) { $rowSelTrackNo = $resSelTrackNo[0]; $tracking_num = $rowSelTrackNo['tracking_number']; } else { $tracking_num = $p->specific_select( 'end_of_day', 'order_id', $order_id, 'tracking_number', " AND void = '0' ORDER BY id DESC" ); } } ################# //START - If $tracking_num == '' / empty then stop shipping notification... 19Apr2022 if (strlen(trim($tracking_num)) == 0 || $tracking_num == '') { return true; } //End - If $tracking_num == '' / empty then stop shipping notification... 19Apr2022 ################# $estimated_delivery_date = ''; $estimated_delivery_date = $p->specific_select( 'orders', 'id', $order_id, 'estimated_delivery_date' ); $style_date = ''; if ( $estimated_delivery_date == '' or $estimated_delivery_date == '0000-00-00 00:00:00' ) { $style_date = 'display: none;'; } $allow_send_email = $p->specific_select( 'website', 'id', $order_info['website'], 'allow_send_email' ); //allow_send_email having values 0,1 /****************allow_send_email code added on 19Jan18 by ssd *********************/ ###########START DT: 11Oct2019 SSG - website.shipped_to_email########### /****************shipped_to_email code added on 11Oct19 by ssg *********************/ $shipped_to_email = $p->specific_select( 'website', 'id', $order_info['website'], 'shipped_to_email' ); //shipped_to_email addresses if ($allow_send_email == 0 && strlen(trim($shipped_to_email)) > 0) { $allow_send_email = 1; //allow to send email to as per field value website.shipped_to_email $to = $shipped_to_email; //Email to website.shipped_to_email } ###########END DT: 11Oct2019 SSG - website.shipped_to_email########### $arry = get_time_on_pickup_conf_new(); $arry1 = $arry[1]; if ($allow_send_email == 1) { //$allow_send_email == 1 then send email based on block if ($order_info['website'] == '3') { //commented the code as requirement of client on date - 19 Oct 2015 //AMAZON arttoframe /*$subject = "Your Amazon.com order #".$order_info['third_party_order_number']." with ArtToFrames #$order_id has shiped !"; $body = "Hello " . $order_info["user_info"]["firstname"] . ",\n" . " Your amazon order #".$order_info['third_party_order_number']." (ArtToFrames #$order_id ) has shipped." . "\n"; # $body.= " It has been shipped with " . $carriers[$carrier]["carrier_name"] . ". \n"; if($carriers[$carrier]["tracking_num"]=="1"){ $body.=" The tracking number is $tracking_num" . "." . "\n"; } $body.= " Thank you for choosing ArtToFrames at amazon for your Art and Framing needs.". " If you have any questions please call 1-718-788-6200 \n"; $body.= "Shipping Department ". "ArtToFrame"; $headers = '' ; // "From: shipping@arttoframes.com" . "\r\n" . "Bcc: shipping@arttoframes.com"; $email_id = $mailer->send_email($to, $subject, $body, $headers,"","","amazon_shipping");*/ } elseif ($order_info['website'] == '24') { //AMAZON WindowPix $subject = 'Your Amazon.com order #' . $order_info['third_party_order_number'] . " with WindowPix #$order_id has shiped !"; $body = 'Hello ' . $order_info['user_info']['firstname'] . ",\n" . ' Your amazon order #' . $order_info['third_party_order_number'] . " (WindowPix #$order_id ) has shipped." . "\n"; # $body.= " It has been shipped with " . $carriers[$carrier]["carrier_name"] . ". \n"; if ($carriers[$carrier]['tracking_num'] == '1') { $body .= " The tracking number is $tracking_num" . '.' . "\n"; } $body .= ' Thank you for choosing WindowPix at Amazon.' . ' If you have any questions please call ' . $arry1 . " \n"; $body .= 'WindowPix Shipping Department '; $headers = ''; // "From: shipping@arttoframes.com" . "\r\n" . "Bcc: shipping@arttoframes.com"; $email_id = $mailer->send_email( $to, $subject, $body, $headers, '', '', 'amazon_shipping', $order_id ); } else { $subject = "Your ArtToFrames.com order #$order_id has shipped!"; $headers = 'From: shipping@arttoframes.com' . "\r\n" . 'Bcc: shipping@arttoframes.com'; $userfirstname = $order_info['user_info']['firstname']; $CarrierName = $trackYourOrder = $url = $style = ''; //This new function implemented to get dynamic url from db table as on 15Apr2022 $url = $this->get_shipping_tracking_url( $tracking_num, $order_id, 'url_only' ); $CarrierName = ' Your order was shipped with ' . $carriers[$carrier]['carrier_name'] . " tracking $tracking_num"; //START=> code added if anything wrong with carrier id or user id by SSD $end_of_day_user_id = $p->specific_select( 'end_of_day', 'order_id', $order_id, 'user_id' ); if ($end_of_day_user_id == '' or $end_of_day_user_id == null) { $url = 'https://www.google.com/search?q=' . $tracking_num; $CarrierName = ' Your order was shipped with ' . $carriers[$carrier]['carrier_name'] . " tracking $tracking_num"; } //END=> code added if anything wrong with carrier id or user id by SSD $order_items = $order_info['order_items']; $total_qty = 0; if ($isdamage_order) { foreach ($order_items as $key => $item) { if ($item['order_item_details_new'][0]['damage']) { $qty = $item['qty']; $total_qty = $qty + $total_qty; } } } else { foreach ($order_items as $key => $item) { $qty = $item['qty']; $total_qty = $qty + $total_qty; } } $sql_footer_banners = $pdo_db1->pquery( 'SELECT * FROM `email_template_footer_banners` WHERE in_stock = 1 ORDER BY rand() limit 1' ); foreach ($sql_footer_banners as $row_img) { $banner_title = $row_img['banner_title']; $banner_url = $row_img['banner_image_link']; $banner_hyperlink = $row_img['banner_hyperlink']; } /*$body='

DEAR '. strtoupper($order_info["user_info"]["firstname"]).'

YOUR ORDER IS BEING SHIPPED.

TRACK YOUR ORDER

SHIPPING DETAILS


TRACKING NUMBER:'.$tracking_num.'
DELIVERY ADDRESS:





'.$shipping_info["name"].'
'.$shipping_info["address"].'
'.$shipping_info["address2"].'
'.$shipping_info["address3"].'
'.$shipping_info["city"] . " " . $shipping_info["state"] . ", " . $shipping_info["zip"].'
Phone #'.$shipping_info["phone"].'
'.$shipping_info["country"].'
SHIP METHOD:'.$shipping_types[$order_info["shipping_type"]]["name"].'
PARCEL QTY:'.$total_qty.'
TOTAL WEIGHT:'.$product_weight.' lbs
ESTIMATED TIME:'.$due_date.'
ORDER NUMBER:'.$order_id.'


TRACK YOUR ORDER


Become a part of our family and share your finished product on our Facebook page!

https://www.facebook.com/ArtToFrames

If you have any questions concerning your art,please call our customer service department at 718.788.6200.

Many Thanks.

'.$o->getCustomerServiceUserName($order_id).'

Customer service manager

Mail: cs@arttoframes.com
Phone #: 718.788.6200
770 5TH AVE
BROOKLYN, NY 11232
UNITED STATES


';*/ $email_header_button = ''; // Set value in Below File include_once $_SERVER['DOCUMENT_ROOT'] . '/admin/order_confirmation_email_header.php'; $arry = get_time_on_pickup_conf_new(); $arry1 = $arry[1]; $body = '
' . $email_header_button . '

DEAR ' . strtoupper($order_info['user_info']['firstname']) . '

YOUR ORDER IS BEING SHIPPED.

TRACK YOUR ORDER

SHIPPING DETAILS


TRACKING NUMBER:' . $tracking_num . '
DELIVERY ADDRESS:





' . $shipping_info['name'] . '
' . $shipping_info['address'] . '
' . $shipping_info['address2'] . '
' . $shipping_info['address3'] . '
' . $shipping_info['city'] . ' ' . $shipping_info['state'] . ', ' . $shipping_info['zip'] . '
Phone #' . $shipping_info['phone'] . '
' . $shipping_info['country'] . '
SHIP METHOD:' . $shipping_types[$order_info['shipping_type']]['name'] . '
' . strtoupper($date_array['date_label']) . '' . $date_array['date'] . '
PARCEL QTY:' . $total_qty . '
TOTAL WEIGHT:' . $product_weight . ' lbs
ORDER NUMBER:' . $order_id . '


TRACK YOUR ORDER


Become a part of our family and share your finished product on our Facebook page!

https://www.facebook.com/ArtToFrames

If you have any questions concerning your art,please call our customer service department at ' . $arry1 . '

Many Thanks.

' . $o->getCustomerServiceUserName($order_id) . '

Customer service manager

Mail: cs@arttoframes.com
Phone #: ' . $arry1 . '
770 5TH AVE
BROOKLYN, NY 11232
UNITED STATES


'; // below shipped email send to user when order shipped is commented because we are sending the email through the listrak-34524260 - 2023October27 // $email_id = $mailer->send_email($to, $subject, $body, $headers,"","","atf_orders_shipment",$order_id); } //echo $body; } else { //do not send email /* if($order_info["website"] == '4' or $order_info["website"] == '9' or $order_info["website"] == '10' or $order_info["website"] == '38'){ } elseif( $order_info["website"] == '26'){ // As per client requirment on 02 Jan 2018. No Need to send email for Houzz order shipped. } */ } //end $allow_send_email email else block } function shipping_ups($info) { $ups = new upsOnline(); return $ups->rates_get_rate($info); } function calculate_shipping_cart($cart, $zip) { global $pdo_db1; $reuven = '1'; if ($reuven == '1') { return $this->calculate_shipping_static($cart, '', $shipping_type1); } $a = new address(); $zip_info = $a->zip_code_info($zip); //print_r($zip_info); $cart_obj = new new_cart_v2(); if ($zip_info === false) { } else { $dim = $cart_obj->get_largest_item_in_cart($cart); //print_r($dim); $cart['zip_code'] = $zip; $cart['ship_state'] = $zip_info['statecode']; $shipping = new shipping_v2(); $info['length'] = $dim['length']; $info['width'] = $dim['width'] + 4; $info['height'] = $dim['height'] + 4; $info['zip'] = $zip; $info['weight'] = '23'; $info['type'] = '03'; $ship_price = $this->shipping_ups($info); $cart['shipping_cost'] = (string) $ship_price; $cart = $cart_obj->calculate_cart_totals($cart); } return $cart; } function validate_cart_shipping_info($cart) { global $pdo_db1; //print_r($cart); if ($cart['addressInfo']['ship']['zip'] != $cart['zip_code']) { //$cart = $this->calculate_shipping_cart($cart, $cart["addressInfo"]["ship"]["zip"]); $cart['zip_code'] = $cart['addressInfo']['ship']['zip']; $cart['shipping_changed'] = true; if (isset($cart['shipping_type'])) { //echo "shipping type = $shipping_type"; $cart = $this->calculate_shipping( $cart, $cart['shipping_type'], true ); //print_r($cart["shipping_prices"]); } else { $cart = $this->calculate_shipping($cart); } $cart_obj = new new_cart_v2(); $cart = $cart_obj->change_state($cart); $cart = $cart_obj->calculate_cart_totals($cart); if ($cart['shipping_cost'] == 0) { header('Location: cart.php?error=4'); exit(); } } return $cart; } function calculate_shipping_rates() { } function list_carriers() { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $q = 'SELECT * FROM shipping_carriers'; $res = $pdo_db1->pquery($q, 'FETCH_BOTH'); $u = new utils(); $carriers = $u->res_to_array_id($res, $pdo = 1); return $carriers; } function list_shipping_types() { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $q = 'SELECT * FROM shipping_types'; $res = $pdo_db1->pquery($q, 'FETCH_BOTH'); $u = new utils(); $shipping_types = $u->res_to_array_id($res, $pdo = 1); return $shipping_types; } function over_size_item_shipping($over_size_arr) { global $pdo_db1; $shipping_price = 0; foreach ($over_size_arr as $key => $value) { $shipping_infos = $pdo_db1->pquery( " SELECT * FROM over_size_shipping_prices WHERE item_group = '" . $pdo_db1->pdo_real_escape_string($value['group']) . "' ", 'FETCH_BOTH' ); $shipping_info = $shipping_infos[0]; $shipping_price = $shipping_price + ($shipping_info['shipping_price_base'] + $shipping_info['shipping_price_per_item'] * $value['qty']); if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo 'oversize item no=' . $key . 'oversize item price=' . $shipping_price; } } if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { die(); } return $shipping_price; } function regular_size_item_shipping($toatl_items) { global $pdo_db1; if ($toatl_items > 0) { $shipping_infos = $pdo_db1->pquery( " SELECT * FROM shipping_types WHERE id = '1' ", 'FETCH_BOTH' ); $shipping_info = $shipping_infos[0]; $shipping_price = $shipping_info['base_price'] + $shipping_info['price_per_item'] * $toatl_items; } if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo 'regular size item shipping=' . $shipping_price; } return $shipping_price; } function over_size_check($frame_id, $mat_id, $item_qty, $over_size_arr) { global $pdo_db1; $a = explode('#', $frame_id); if ($a[1]) { $frame_id = trim($a[1]); } $found_item_group = 'no'; $over_size_arr['this_item_found'] = 'no'; $shipping_infos = $pdo_db1->pquery( " SELECT * FROM over_size_shipping_prices WHERE frame_id = '" . $pdo_db1->pdo_real_escape_string($frame_id) . "' AND multi_mat_id = '" . $pdo_db1->pdo_real_escape_string($mat_id) . "' ", 'FETCH_BOTH' ); $shipping_info = $shipping_infos[0]; if ($shipping_info) { //item found //check for group id foreach ($over_size_arr as $key => $value) { if ($value['group'] == $shipping_info['item_group']) { $value['order_item_details_new'][0]['qty'] = $value['order_item_details'][0]['qty'] + 1 * $item_qty; $found_item_group = 'yes'; $over_size_arr['this_item_found'] = 'yes'; } } //no group id if ($found_item_group == 'no') { $arr_return = []; $arr_return['group'] = $shipping_info['item_group']; $arr_return['qty'] = 1 * $item_qty; $over_size_arr['this_item_found'] = 'yes'; $over_size_arr[] = $arr_return; } } // end if item found return $over_size_arr; } //without ups function calculate_shipping_static( $cart, $static_price = '', $shipping_type1 = '1', $shipping_name = 'Shipping', $callGoogleAPI = '',$call_from='', $skip_internal_cart_totals = false ) { $cart_obj = new new_cart_v2(); // Preserve the admin-entered static shipping values before reloading the v2 cart. // This keeps the custom quote price/type/zip from being replaced by the existing saved address data. $custom_static_price = $static_price; $custom_static_shipping_type = $shipping_type1; $custom_static_shipping_name = $shipping_name; $custom_static_zip = ''; if (isset($cart['zip_code']) && $cart['zip_code'] != '') { $custom_static_zip = $cart['zip_code']; } elseif (isset($cart['ship_zip']) && $cart['ship_zip'] != '') { $custom_static_zip = $cart['ship_zip']; } $custom_static_shipping_prices = (isset($cart['shipping_prices']) && is_array($cart['shipping_prices'])) ? $cart['shipping_prices'] : array(); $custom_static_shipping_price_flag = isset($cart['custom_shipping_price']) ? $cart['custom_shipping_price'] : ''; if (isset($cart['cart_id']) && $cart['cart_id'] > 1) { $cart = $cart_obj->get_new_cart_v2($cart['cart_id'],'','','1'); if ($custom_static_price != '' && (float)$custom_static_price > 0) { $cart['static_shipping_price'] = $custom_static_price; $cart['custom_shipping_price'] = ($custom_static_shipping_price_flag != '') ? $custom_static_shipping_price_flag : 1; if ($custom_static_zip != '') { $cart['zip_code'] = $custom_static_zip; $cart['ship_zip'] = $custom_static_zip; $cart['ship_zip_dashcode'] = $custom_static_zip; if (!isset($cart['shipping_vars']) || !is_array($cart['shipping_vars'])) { $cart['shipping_vars'] = array(); } $cart['shipping_vars']['zip'] = $custom_static_zip; } if ($custom_static_shipping_type == '' && isset($custom_static_shipping_prices[1]['code'])) { $custom_static_shipping_type = $custom_static_shipping_prices[1]['code']; } if (($custom_static_shipping_name == '' || $custom_static_shipping_name == 'Shipping') && isset($custom_static_shipping_prices[1]['name']) && $custom_static_shipping_prices[1]['name'] != '') { $custom_static_shipping_name = $custom_static_shipping_prices[1]['name']; } if ($custom_static_shipping_type != '') { $cart['shipping_type'] = $custom_static_shipping_type; $cart['shipping_cost'] = $custom_static_price; $cart['shipping_prices'][1]['code'] = $custom_static_shipping_type; $cart['shipping_prices'][1]['name'] = $custom_static_shipping_name; $cart['shipping_prices'][1]['zip'] = $custom_static_zip; $cart['shipping_prices'][1]['price'] = $custom_static_price; $cart['shipping_prices'][1]['custom_shipping_price'] = 1; } } } $this->write_cart_debug_log($cart['cart_id'], "Start shipping_prices=>".json_encode($cart['shipping_prices'])); //// echo __LINE__."
";print_r($cart['shipping_prices']);

  //   //echo __LINE__."
";echo ($cart['shipping_cost']);
        // echo "test 583"; exit;
        // echo "
";print_r($cart); exit;
        //include_once("../getStateAndCity_api.php");
        global $pdo_db1;
        // Set default value (10-10-2023)
        $over_size_values_shipping = [];
        $over_size_values_shipping1 = [];
        // End
        $data1 = new dataset();
        $data1->db_connect();
        $total_items = 0;
        $over_size_arr = [];
        $p = new products();
        

        $availShipOptArr = [];
        $availShipOpt = $pdo_db1->pquery(
            "SELECT shipping_types_id FROM pickup_return_addresses WHERE is_active=1 and address_type = 'Pickup'"
        );

        array_push($availShipOptArr, 10);

        foreach ($availShipOpt as $key => $value) {
            array_push($availShipOptArr, $value['shipping_types_id']);
        }

        $availShipOptStr = implode(',', $availShipOptArr);

        // echo "
";print_r($availShipOptStr); exit;

        if (
            $static_price == '' &&
            !empty($cart['static_shipping_price']) && (float)$cart['static_shipping_price'] != 0.0 &&
            $cart['custom_shipping_price'] == '1'
        ) {
            $static_price = $cart['static_shipping_price'];
        }
        $x = 1;
        $partner_id = $cart['partner_id'];
        $zip = $cart['zip_code'];
        //{ Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in } so we have check isset and of not then declare as empty array for db9 on 13 oct 2023
        $order_items = is_array($cart['order_items'])
            ? $cart['order_items']
            : [];

        // $order_items = $cart["order_items"];
        //echo "here 
";print_r($cart["order_items"]);exit;
        $bigest_width = 0;
        $bigest_height = 0;
        $over_size_items_total = 0;
        $regular_size_items_total = 0;
        $long_box_size_items_total = 0;
        $oversize_box_items_total = 0;
        $regular_size_items_total_1 = 0;
        $long_box_size_items_total_1 = 0;
        $oversize_box_items_total_1 = 0;
        $windowshade_shipp_price = 0;
        $we_have_a_big_item = 'no';
        $item_ctr = 0;
        $offer_ctr = 0;
        $oversizeitem = '';
        $val_set_oval_allowpickup = 1;
        $partner_id_flag = 0;

        if ($partner_id != '') {
            $partner_id_flag = 1;
        }
        if ($zip != 'US' && $zip != '') {
            //$zip = str_replace(" ","%20",$zip);
            $zip = urlencode($zip);
            $endpoint =
                'https://www.arttoframe.com/getStateAndCity_api.php?zipcode=' .
                $zip .
                '&method_type=file';
            //echo 'PayflowNVPAPI_ssn = '.$endpoint;
            //Initialize our cURL handle.
            // echo 'PayflowNVPAPI_ssn = '.$endpoint;
            $curl = curl_init($endpoint);

            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

            // If you get connection errors, it may be necessary to uncomment
            // the following two lines:
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

            // $zipPrice = '';
            // declare as array on 31 oct 2023
            $zipPrice = [];
            $result = curl_exec($curl);

            if ($result === false) {
                echo curl_error($curl);
                //exit;
                //return FALSE;
            } else {
                // Below Code commented on 29-06-2022 Because of Canada zipcode country not set properly so add below code to set country on cart array.

                /*$zipPrice =   get_object_vars(json_decode($result));
        $zipPrice =   get_object_vars($zipPrice['zip_data']);
        $zipPrice =   get_object_vars($zipPrice[1]);*/

//code added on 20240227 task 33682097>> fatal error on get_object_vars()function
        $decodedResult = json_decode($result);
        if ($decodedResult === null) {
          //  echo "Error decoding JSON";
        } else {
            if (is_object($decodedResult)) {
                $zipPrice = get_object_vars($decodedResult);
             //   $zipPrice = get_object_vars(json_decode($result));
            } else {
             //   echo "Decoded JSON is not an object";
            }
        }
  //// echo __LINE__."
";print_r($cart['shipping_prices']);
                //$zipPrice =   get_object_vars($zipPrice['zip_data']);
                // {Uncaught TypeError: get_object_vars(): Argument #1 ($object) must be of type object, array given in} so we have check is_object($zipPrice['zip_data']) on 13 oct 2023

                //condition added on 20240110 #TW34283182:if canadian zipcode not exist in cities_extended table then set country as CA
                if ($zipPrice['status'] == 'failed' && ctype_alnum($zip) && strlen($zip)>=6) { 
                 $zipPrice['country'] = "CA";
                 $zipPrice['state'] = '';
                 $zipPrice['city'] ='';

                }else if (
                    is_object($zipPrice['zip_data']) &&
                    is_array(get_object_vars($zipPrice['zip_data']))
                ) {
                    $zipPrice = get_object_vars($zipPrice['zip_data']);
                    $zipPrice = get_object_vars($zipPrice[1]);
                } else {
                    $zipPrice = $zipPrice['zip_data'];
                    // check is_arrayand is_object on 31 oct 2023
                    if (
                        is_object($zipPrice[0]) &&
                        is_array(get_object_vars($zipPrice[0]))
                    ) {
                        $zipPrice = get_object_vars($zipPrice[0]);
                    }
                }
            }

                $ship_country = $zipPrice['country'];

            $cart['ship_country'] = $ship_country;
            //echo "set ship country at 1
"; //START: code added on 20240206 #TW35156577:Set shipping details correclty due to random character issue if(empty($cart['shipping_vars'])){ $cart['shipping_vars'] = array(); } if(!isset($cart['shipping_vars']['state'])){ $cart['shipping_vars']['state'] =''; } if(!isset($cart['shipping_vars']['country'])){ $cart['shipping_vars']['country'] =''; } if(!isset($cart['shipping_vars']['city'])){ $cart['shipping_vars']['city'] =''; } if(!isset($cart['shipping_vars']['zip'])){ $cart['shipping_vars']['zip'] =''; } //END $cart['shipping_vars']['state'] = $zipPrice['state']; $cart['shipping_vars']['country'] = $ship_country; $cart['shipping_vars']['city'] = $zipPrice['city']; //added on 20240408 #tw - 35979907 if(isset($zipPrice['zip']) && !empty($zipPrice['zip'])){ $cart['shipping_vars']['zip'] = $zipPrice['zip']; } //end // echo __LINE__."
";print_r($cart['shipping_prices']);

    // //echo __LINE__."
";echo ($cart['shipping_cost']);
            if (function_exists('atf_checkout_shipping_cost_debug_step')) {
                atf_checkout_shipping_cost_debug_step('modules_shipping_v2_before_save_cart', array('cart_summary' => atf_checkout_shipping_cost_debug_cart_summary($cart), 'line' => __LINE__));
            }
            $cart = $cart_obj->save_cart($cart);
            if (function_exists('atf_checkout_shipping_cost_debug_step')) {
                atf_checkout_shipping_cost_debug_step('modules_shipping_v2_after_save_cart', array('cart_summary' => atf_checkout_shipping_cost_debug_cart_summary($cart), 'line' => __LINE__));
            }
        }
        if (!$skip_internal_cart_totals) {
            $cart = $cart_obj->calculate_cart_totals($cart);
        }

             if($call_from == "process_cart"){
                $cart=$cart_new_v2->get_new_cart_v2($cart['cart_id'],'','','1');
                
            }else{
                $cart = $cart_obj->get_new_cart_v2($cart['cart_id'],'','','1');
          
            }
        // echo __LINE__."
";print_r($cart); exit;
            if($call_from == "process_cart"){
                $cart=$cart_new_v2->get_new_cart_v2($cart['cart_id'], 'yes');
            
            }else{
                $cart = $cart_obj->get_new_cart_v2($cart['cart_id'], 'yes','','1');
          
            }

      if (!empty($cart['order_items'])) {
            foreach ($cart['order_items'] as $key => $item) {
                if (
                    isset($item['order_item_details_new'][0]['item_cost']) &&
                    (float)$item['order_item_details_new'][0]['item_cost'] == 0
                ) {
                    unset($cart['order_items'][$key]);
                }
            }
            // Re-index the array to keep indexes sequential
            $cart['order_items'] = array_values($cart['order_items']);
            }
        //    check is_array for db9 on 13 oct 2023
        if (is_array($order_items) && count($order_items) == 0) {
        } else {
            $cart['disallow_coupon'] = null;
            if (
                isset($_GET['check_shipping']) &&
                $_GET['check_shipping'] == '1'
            ) {
                //echo '
';print_r($order_items);echo'
'; } $total_standard_regular_qty = 0; $total_standard_longbox_qty = 0; $total_standard_oversizebox_qty = 0; $total_standard_largesizebox_qty = 0; $customprice_shipping_oversize = 0; $customprice_shipping_standardsize = 0; $customprice_shipping_longboxsize = 0; $customprice_shipping_largesize = 0; $oversizeitem_array = []; $shippingitem_windowarray = []; $amazon_shipping_cost_reg = 0; $amazon_shipping_cost_long = 0; $amazon_shipping_cost_over = 0; $free_shipping_cf_prod = 0; $regular_size_items_total_1_free = 0; $amazon_shipping_cost_other = 0; $giftCardShippingTextStatus = $otherProducts = 0; $box_res_new = []; $product_types_arr = []; $allow_economy_shipping = []; if ( $cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' || $cart['ship_state'] == 'VI' || $cart['ship_country'] == 'CA' || $cart['ship_state'] == 'PR' || $cart['ship_country'] == 'Canada' ) { } elseif (isset($_SESSION['hide_economy_shipping'])) { unset($_SESSION['hide_economy_shipping']); } $cart['is_box_not_available_request_quote']=0; //echo __LINE__.$cart['is_box_not_available_request_quote']."
"; foreach ($order_items as $key => $value) { if ( $value['order_item_details_new'][0]['product_type'] == '33' ) { $giftCardShippingTextStatus++; } else { $otherProducts++; $product_types_arr[] = $value['order_item_details_new'][0]['product_type']; } if ( $value['order_item_details_new'][0]['finished_width'] != '' && $value['order_item_details_new'][0]['finished_height'] != '' ) { /** * * Commented Frame query and lip_widht calculations based on frame_widht and frame_height . * By erlier logic thier are many conditions for multiple products we removed this and added a flexible approach. * Refrenced as globally available $selected_finished_width and $selected_finished_height for all product types finished_width an finished_height directly from cart array . * Removed conditions for product type 38/ 43/ 79/ 76/ 69/ 87/ 77 / 75/ 57/ 87/ 88/ 84/ 85/ 80 and their else conditions. * Task : https://arttoframes.teamwork.com/#/tasks/30093519 Date : 14112022 * */ $selected_finished_width = $value['order_item_details_new'][0]['finished_width']; $selected_finished_height = $value['order_item_details_new'][0]['finished_height']; } $this_width = $selected_finished_width; $this_height = $selected_finished_height; $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 0; $total_items = $total_items + $value['order_item_details_new'][0]['qty']; // echo __LINE__."
";print_r($cart); exit;

                $product_type =
                    $value['order_item_details_new'][0]['product_type'];
                if ($product_type == '84' || $product_type == '85') {
                    $this_width = 8;
                    $this_height = 8;
                }
                if (
                    $_GET['print_box_queries'] == 1 &&
                    $_SESSION['permissions'] > 1
                ) {
                    echo '
###' . __LINE__ . '==>this_width===' . $this_width . '&this_height===' . $this_height . '&product_type===' . $product_type; } if ( ($this_width != null && $this_width != '' && $this_height != null && $this_height != '' && $product_type != null && $product_type != '') || (isset($cart['order_items'][$key]['sku_base_products']) && $cart['order_items'][$key]['sku_base_products'] == '1') ) { $box_res = $this->get_box_info_from_sizes( $this_width, $this_height, $product_type, $value ); if ($box_res == false) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 1; #$box_res['allow_economy_shipping'] = 0; } /*if($box_res['allow_economy_shipping'] != ''){ $allow_economy_shipping[] = $box_res['allow_economy_shipping']; }*/ $allow_economy_shipping[] = $box_res['allow_economy_shipping']; $box_res_new[] = $box_res; } // echo __LINE__."
";print_r($cart); exit;

                /** Commented code not in use.
                 * Task : https://arttoframes.teamwork.com/#/tasks/30093519 Date : 14112022
                 */
                // if($value['order_item_details_new'][0]['product_type'] == 57 && $value["order_item_details_new"][0]['hardware_id'] == '' && $value["order_item_details_new"][0]['mat_one_spacing'] == '') {
                //  //$value['order_item_details_new'][0]['product_type'] = 69;  //commented for CF Android api affecting shipping price
                // }
                $vvv = 0;

                if (isset($_GET['show_details'])) {
                    print_r($value);
                    echo 'product_type==>>' .
                        $value['order_item_details_new'][0]['product_type'];
                    if (
                        $value['order_item_details_new'][0]['product_type'] ==
                        36
                    ) {
                        echo $val_set_oval_allowpickupe = $this->to_return_allow_pickup(
                            $value['order_item_details_new'][0]['product_type']
                        );
                        exit();
                    }
                }
                $val_set_oval_allowpickupe = $this->to_return_allow_pickup(
                    $value['order_item_details_new'][0]['product_type']
                );
                if ($val_set_oval_allowpickupe == 1) {
                } else {
                    $val_set_oval_allowpickup = $val_set_oval_allowpickupe;
                }
                /** For product lampix radius calculation is coming from frame_width and height so we need to refer frame_widht and height instead of finished_width a,d finished_height
                 * Task : Task : https://arttoframes.teamwork.com/#/tasks/30093519 Date : 14112022
                 */
                if ($value['order_item_details_new'][0]['product_type'] == 70) {
                    $this_width =
                        $value['order_item_details_new'][0]['frame_width'];
                    $this_height =
                        $value['order_item_details_new'][0]['frame_height'];
                }

                if (
                    ($value['order_item_details_new'][0]['product_type'] ==
                        57 &&
                        !isset($value['sku_base_products'])) ||
                    $value['order_item_details_new'][0]['product_type'] == 87 ||
                    $value['order_item_details_new'][0]['product_type'] == 88 ||
                    $value['order_item_details_new'][0]['product_type'] == 84 ||
                    $value['order_item_details_new'][0]['product_type'] == 85 ||
                    $value['order_item_details_new'][0]['product_type'] == 80
                ) {
                    $this_width = $selected_finished_width;
                    $this_height = $selected_finished_height;
                    $this_width_1 =
                        $value['order_item_details_new'][0]['frame_width'];
                    $this_height_1 =
                        $value['order_item_details_new'][0]['frame_height'];
                    $sizer = $this_width_1 . 'x' . $this_height_1;
                    $standard_non_sizes_flag = 0;

                    $framewidthpro_size = $pdo_db1->pquery(
                        'SELECT size,standard_sizes FROM pre_made_size_all WHERE size="' .
                            $sizer .
                            '" and standard_sizes="1"'
                    );
                    if ($pdo_db1->pdo_num_rows($framewidthpro_size) > 0) {
                        $standard_non_sizes_flag = 1;
                    } else {
                        $standard_non_sizes_flag = 0;
                    }

                    $framewidthpro_sql = $pdo_db1->pquery(
                        'SELECT  free_shipping,free_shipping_oversize FROM product_types WHERE id="' .
                            $value['order_item_details_new'][0]['product_type'] .
                            '"'
                    );
                    $framewidthpro = $framewidthpro_sql[0];

                    if (
                        $framewidthpro['free_shipping'] == '1' &&
                        $box_res['oversize_item'] == 0
                    ) {
                        $customprice_shipping_standardsize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 1
                    ) {
                        $customprice_shipping_longboxsize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 2
                    ) {
                        $customprice_shipping_oversize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 6
                    ) {
                        $customprice_shipping_largesize = 1;
                    }
                }
                // echo __LINE__."
";print_r($cart); exit;

                //added else part if on 20240117 #TW35282133: If line item is not sku_based and free-shipping then $free_shipping flag should set 0 due to that shipping cost get calculated correclty
                if (
                    isset($value['sku_base_products']) &&
                    $value['sku_base_products'] == '1'
                ) {
                    $free_shipping = $p->specific_select(
                        'sku_base_products',
                        'id',
                        $value['sku_base_products_id'],
                        'free_shipping'
                    );
                }else{ 
                    $free_shipping =0;
                }
                if ($free_shipping == 1) {
                    $this_width = $selected_finished_width;
                    $this_height = $selected_finished_height;
                    $this_width_1 =
                        $value['order_item_details_new'][0]['frame_width'];
                    $this_height_1 =
                        $value['order_item_details_new'][0]['frame_height'];
                    $sizer = $this_width_1 . 'x' . $this_height_1;
                    $standard_non_sizes_flag = 0;

                    //echo 'SELECT size,standard_sizes FROM pre_made_size_all WHERE size="'.$sizer.'" and standard_sizes="1"';exit;
                    //die;
                    $framewidthpro_size = $pdo_db1->pquery(
                        'SELECT size,standard_sizes FROM pre_made_size_all WHERE size="' .
                            $sizer .
                            '" and standard_sizes="1"'
                    );
                    if ($pdo_db1->pdo_num_rows($framewidthpro_size) > 0) {
                        $standard_non_sizes_flag = 1;
                    } else {
                        $standard_non_sizes_flag = 0;
                    }

                    $framewidthpro_sql = $pdo_db1->pquery(
                        'SELECT  free_shipping,free_shipping_oversize FROM product_types WHERE id="' .
                            $value['order_item_details_new'][0]['product_type'] .
                            '"'
                    );
                    $framewidthpro = $framewidthpro_sql[0];

                    if (
                        $framewidthpro['free_shipping'] == '1' &&
                        $box_res['oversize_item'] == 0
                    ) {
                        $customprice_shipping_standardsize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 1
                    ) {
                        $customprice_shipping_longboxsize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 2
                    ) {
                        $customprice_shipping_oversize = 1;
                    } elseif (
                        $framewidthpro['free_shipping_oversize'] == '1' &&
                        $box_res['oversize_item'] == 6
                    ) {
                        $customprice_shipping_largesize = 1;
                    }
                }

                if (
                    $value['order_item_details_new'][0]['product_type'] == 84 ||
                    $value['order_item_details_new'][0]['product_type'] == 85 ||
                    $value['order_item_details_new'][0]['product_type'] == 80
                ) {
                    $free_shipping = $framewidthpro['free_shipping'];
                }

                if ($value['order_item_details_new'][0]['product_type'] == 77) {
                    $this_width = $selected_finished_width;
                    $this_height = $selected_finished_height;
                }
                if ($value['order_item_details_new'][0]['product_type'] == 75) {
                    $queryt = $pdo_db1->pquery(
                        'SELECT oversize_item FROM shipping_box_choices WHERE ( (' .
                            $this_width .
                            ' <= max_width AND  ' .
                            $this_height .
                            ' <= max_height) OR (' .
                            $this_width .
                            ' <= max_height AND ' .
                            $this_height .
                            " <= max_width))  AND product_type_allowed LIKE '%75%' ORDER BY sort LIMIT 1"
                    );
                    $framewidthtq = $queryt[0];
                    $oversizeitem = $framewidthtq['oversize_item'];

                    if ($oversizeitem == '0') {
                        $this_width = 40.5;
                        $this_height = 28.5;
                    } elseif ($oversizeitem == '1') {
                        $this_width = 57.5;
                        $this_height = 15.5;
                    } elseif ($oversizeitem != '') {
                        $this_width = 62;
                        $this_height = 44;
                    } else {
                        $this_width = 40.5;
                        $this_height = 28.5;
                    }

                    //  echo "
"; print_r($shippingitem_windowarray); die;
                }
                if (
                    isset($_GET['check_shipping']) &&
                    $_GET['check_shipping'] == '1'
                ) {
                    echo $this_height . ' - ' . $this_width . ' 
'; echo 'check_shipping_largesize=' . $customprice_shipping_largesize; //exit; } //set w/h to big/small if ($this_width < $this_height) { $temp_info = $this_width; $this_width = $this_height; $this_height = $temp_info; } $test = 0; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { //echo $this_height . ' - ' . $this_width . '
' ; // exit; } if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { //print_r($framewidthq); echo '

' . $this_height . ' x ' . $this_width . '
'; echo '(' . $this_height . ' < 29.5 && ' . $this_width . ' < 41.5) Regular
'; echo '(' . $this_height . ' < 16.5 && ' . $this_width . ' < 58.5 ) long_box_size
'; echo '(' . $this_height . ' < 45 && ' . $this_width . ' < 63) Oversize_box_size
'; // echo $this_height . ' - ' . $this_width . '
' ; } // for oversize item free shipping /*updated condition for free shipping hardware product on 2022-02-23*/ // if($box_res['oversize_item']==0){ if ( $value['sku_base_products'] == 1 && in_array($box_res['oversize_item'], [0, 4, 5]) ) { $box_res['oversize_item'] = 0; } if ($box_res['oversize_item'] == 0) { // echo __LINE__; exit; if ( $value['order_item_details_new'][0]['product_type'] == 33 ) { $regular_size_items_total_1_free = 0; $free_shipping_cf_prod = $free_shipping_cf_prod + 1; } else { if ($free_shipping == 1) { $total_standard_regular_qty = 0; $regular_size_items_total = 0; $customprice_shipping_standardsize = 1; $free_shipping_cf_prod = $free_shipping_cf_prod + $value['order_item_details_new'][0]['qty']; //echo '111'.$free_shipping_cf_prod; exit; } //} } if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo '
' . __LINE__ . '#free_shipping=>' . $free_shipping . '<==>free_shipping_cf_prod=>' . $free_shipping_cf_prod; } if ($box_res['oversize_item'] == '') { $box_res['oversize_item'] = 0; } $over_size_values_shipping[] = $box_res['oversize_item']; $regular_size_items_total = $regular_size_items_total + $value['order_item_details_new'][0]['qty']; $regular_size_items_total_1 = $regular_size_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $regular_size_items_total_1; if ( $value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products']) ) { $regular_size_items_total_1_free = $free_shipping_cf_prod + $value['order_item_details_new'][0]['qty']; $free_shipping_cf_prod = $regular_size_items_total_1_free; } if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { echo ' Satisfied Condition4 (' . $this_height . ' <= ' . $box_res['max_height'] . ' && ' . $this_width . ' <= ' . $box_res['max_width'] . ') Regular
'; } if ( ($customprice_shipping_standardsize == 1 && $zip == 'US' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) || ($customprice_shipping_standardsize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_regular_qty = 0; $regular_size_items_total = 0; } } else { if ($box_res['oversize_item'] == 1) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 1; $over_size_values_shipping[] = $box_res['oversize_item']; $long_box_size_items_total = $long_box_size_items_total + $value['order_item_details_new'][0]['qty']; $long_box_size_items_total_1 = $long_box_size_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $long_box_size_items_total_1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo 'Satisfied Condition2 (' . $this_height . ' < ' . $box_res['max_height'] . ' && ' . $this_width . ' < ' . $box_res['max_width'] . ' ) long_box_size
'; } if ( ($customprice_shipping_longboxsize == 1 && $zip == 'US' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) || ($customprice_shipping_longboxsize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_longbox_qty = $total_standard_longbox_qty + $value['order_item_details_new'][0]['qty']; $long_box_size_items_total = $long_box_size_items_total - $value['order_item_details_new'][0]['qty']; } else { if ($free_shipping == 1) { $total_standard_longbox_qty = $total_standard_longbox_qty + $value['order_item_details_new'][0]['qty']; $long_box_size_items_total = $long_box_size_items_total - $value['order_item_details_new'][0]['qty']; } } } elseif ($box_res['oversize_item'] == 2) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 1; $over_size_values_shipping[] = $box_res['oversize_item']; $oversize_box_items_total = $oversize_box_items_total + $value['order_item_details_new'][0]['qty']; $oversize_box_items_total_1 = $oversize_box_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $oversize_box_items_total_1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { echo 'Satisfied Condition3 (' . $this_height . ' < ' . $box_res['max_height'] . ' && ' . $this_width . ' < ' . $box_res['max_width'] . ') Oversize_box_size
'; } if ( ($customprice_shipping_oversize == 1 && $zip == 'US' && $value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products']) && $partner_id_flag == 0) || ($customprice_shipping_oversize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_oversizebox_qty = $total_standard_oversizebox_qty + $value['order_item_details_new'][0]['qty']; $oversize_box_items_total = $oversize_box_items_total - $value['order_item_details_new'][0]['qty']; } else { if ($free_shipping == 1) { $total_standard_oversizebox_qty = $total_standard_oversizebox_qty + $value['order_item_details_new'][0]['qty']; $oversize_box_items_total = $oversize_box_items_total - $value['order_item_details_new'][0]['qty']; } } } elseif ($box_res['oversize_item'] == 4) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 1; $over_size_values_shipping[] = $box_res['oversize_item']; $_12_inchsize_box_items_total = $_12_inchsize_box_items_total + $value['order_item_details_new'][0]['qty']; $_12_inchsize_box_items_total_1 = $_12_inchsize_box_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $_12_inchsize_box_items_total_1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { echo 'Satisfied Condition3 (' . $this_height . ' < ' . $box_res['max_height'] . ' && ' . $this_width . ' < ' . $box_res['max_width'] . ') Oversize_box_size
'; } if ( ($customprice_shipping_12inchsize == 1 && $zip == 'US' && $value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products']) && $partner_id_flag == 0) || ($customprice_shipping_12inchsize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_12inchsizebox_qty = $total_standard_12inchsizebox_qty + $value['order_item_details_new'][0]['qty']; $_12_inchsize_box_items_total = $_12_inchsize_box_items_total - $value['order_item_details_new'][0]['qty']; } else { if ($free_shipping == 1) { $total_standard_12inchsizebox_qty = $total_standard_12inchsizebox_qty + $value['order_item_details_new'][0]['qty']; $_12_inchsize_box_items_total = $_12_inchsize_box_items_total - $value['order_item_details_new'][0]['qty']; } } } elseif ($box_res['oversize_item'] == 5) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 0; $over_size_values_shipping[] = $box_res['oversize_item']; $envelopsize_box_items_total = $envelopsize_box_items_total + $value['order_item_details_new'][0]['qty']; $envelopsize_box_items_total_1 = $envelopsize_box_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $envelopsize_box_items_total_1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { echo 'Satisfied Condition3 (' . $this_height . ' < ' . $box_res['max_height'] . ' && ' . $this_width . ' < ' . $box_res['max_width'] . ') Oversize_box_size
'; } if ( ($customprice_shipping_envelopsize == 1 && $zip == 'US' && $value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products']) && $partner_id_flag == 0) || ($customprice_shipping_envelopsize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_envelopsizebox_qty = $total_standard_envelopsizebox_qty + $value['order_item_details_new'][0]['qty']; $envelopsize_box_items_total = $envelopsize_box_items_total - $value['order_item_details_new'][0]['qty']; } else { if ($free_shipping == 1) { $total_standard_envelopsizebox_qty = $total_standard_envelopsizebox_qty + $value['order_item_details_new'][0]['qty']; $envelopsize_box_items_total = $envelopsize_box_items_total - $value['order_item_details_new'][0]['qty']; } } } elseif ($box_res['oversize_item'] == 6) { $cart['order_items'][$key]['order_item_details_new'][0]['over_size_item'] = 1; $over_size_values_shipping[] = $box_res['oversize_item']; $largesize_box_items_total = $largesize_box_items_total + $value['order_item_details_new'][0]['qty']; $largesize_box_items_total_1 = $largesize_box_items_total_1 + $value['order_item_details_new'][0]['qty']; $over_size_values_shipping1[] = $largesize_box_items_total_1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' && $_SESSION['permissions'] == 3 ) { echo 'Satisfied Condition6 (' . $this_height . ' < ' . $box_res['max_height'] . ' && ' . $this_width . ' < ' . $box_res['max_width'] . ') Oversize_box_size
'; } if ( ($customprice_shipping_largesize == 1 && $zip == 'US' && $value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products']) && $partner_id_flag == 0) || ($customprice_shipping_largesize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 && empty($value['sku_base_products'])) && $partner_id_flag == 0) ) { $total_standard_largesizebox_qty = $total_standard_largesizebox_qty + $value['order_item_details_new'][0]['qty']; $largebox_size_items_total = $largebox_size_items_total - $value['order_item_details_new'][0]['qty']; } else { if ($free_shipping == 1) { $total_standard_largesizebox_qty = $total_standard_largesizebox_qty + $value['order_item_details_new'][0]['qty']; $largebox_size_items_total = $largebox_size_items_total - $value['order_item_details_new'][0]['qty']; } } } elseif ( $value['item_sub_type'] == 'cluster' || $value['item_sub_type'] == 'split' ) { $over_size_values_shipping[] = $box_res['oversize_item']; $test = 1; $regular_size_items_total = $regular_size_items_total + $value['order_item_details_new'][0]['qty']; $regular_size_items_total_1 = $regular_size_items_total_1 + $value['order_item_details_new'][0]['qty']; if ( ($customprice_shipping_standardsize == 1 && $zip == 'US' && ($value['order_item_details_new'][0]['product_type'] == 57 || $value['order_item_details_new'][0]['product_type'] == 87 || $value['order_item_details_new'][0]['product_type'] == 88 || $value['order_item_details_new'][0]['product_type'] == 80) && $partner_id_flag == 0) || ($customprice_shipping_standardsize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 || $value['order_item_details_new'][0]['product_type'] == 87 || $value['order_item_details_new'][0]['product_type'] == 88 || $value['order_item_details_new'][0]['product_type'] == 80) && $partner_id_flag == 0) ) { $total_standard_regular_qty = $total_standard_regular_qty + $value['order_item_details_new'][0]['qty']; $regular_size_items_total = $regular_size_items_total - $value['order_item_details_new'][0]['qty']; } } else { $we_have_a_big_item = 'yes'; $over_size_items_total = $over_size_items_total + $value['order_item_details_new'][0]['qty']; $over_size_items_total_1 = $over_size_items_total_1 + $value['order_item_details_new'][0]['qty']; if ( ($customprice_shipping_oversize == 1 && $zip == 'US' && ($value['order_item_details_new'][0]['product_type'] == 57 || $value['order_item_details_new'][0]['product_type'] == 87 || $value['order_item_details_new'][0]['product_type'] == 88 || $value['order_item_details_new'][0]['product_type'] == 80) && $partner_id_flag == 0) || ($customprice_shipping_oversize == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada' && ($value['order_item_details_new'][0]['product_type'] == 57 || $value['order_item_details_new'][0]['product_type'] == 87 || $value['order_item_details_new'][0]['product_type'] == 88 || $value['order_item_details_new'][0]['product_type'] == 80) && $partner_id_flag == 0) ) { $total_standard_oversizebox_qty = $total_standard_oversizebox_qty + $value['order_item_details_new'][0]['qty']; $over_size_items_total = $over_size_items_total - $value['order_item_details_new'][0]['qty']; } } /* Added a new flag into cart array for getting shipping quote of oversize item base on the standard box Code Added date 20-04-2022 */ if ( sizeof($box_res) > 0 && $box_res['is_pickup_box'] == '1' ) { $boxCount = sizeof($box_res); } else { $boxCount = 0; } if ($boxCount > 0) { // $cart['order_items'][$key]['order_item_details_new'][0]['is_box_not_available_request_quote'] = 1; $cart['is_box_not_available_request_quote'] = 1; // echo __LINE__."
"; } else { //$cart['order_items'][$key]['order_item_details_new'][0]['is_box_not_available_request_quote'] = 0; $cart['is_box_not_available_request_quote'] = 0; //echo __LINE__."
"; } if ( isset($_GET['check_shipping']) && $_GET['check_shipping'] == '1' ) { //echo $over_size_items_total; //exit; } if (!is_array($box_res)) { // $cart['order_items'][0]['order_item_details_new'][0]['is_box_not_available_request_quote'] = 1; $cart['is_box_not_available_request_quote'] = 1; // echo __LINE__."
"; } } // offer related changes - Solace $offer_ctr += (int) $value['offer_apply']; $item_ctr++; } if (in_array(0, $allow_economy_shipping)) { $_SESSION['hide_economy_shipping'] = 1; if ($cart['shipping_type'] == 1) { $cart['shipping_type'] = 2; } } if ( $_GET['show_allow_economy_shipping'] == 1 || $_GET['show_box_details'] == 1 ) { echo '
';
                print_r($box_res_new);
                exit();
            }
        }
        //print_r($over_size_values_shipping);
        //print_r($over_size_values_shipping1);
        $over_size_values_final = array_combine(
            $over_size_values_shipping,
            $over_size_values_shipping1
        );

        if (
            isset($_GET['shipping_options']) &&
            $_GET['shipping_options'] == '1'
        ) {
            echo ' regular_size_items_total - ' .
                $regular_size_items_total .
                ' - long_box_size_items_total - ' .
                $long_box_size_items_total .
                ' - large_box_size_items_total - ' .
                $large_box_size_items_total .
                ' - we_have_a_big_item - ' .
                $we_have_a_big_item .
                ' oversizeitem total -' .
                $over_size_items_total .
                ' 
'; } $flag_box = 0; foreach ($box_res_new as $box_info) { if ($box_info['id'] == '33') { $flag_box = 1; $val_set_oval_allowpickup = 1; } } // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);

        // echo "1136
";print_r($cart); exit;
        //echo "
"; print_r($shippingitem_windowarray); die;
        if ($static_price != '' or  $cart['static_shipping_price'] > 0) {
            $cart['disallow_coupon'] = 'yes';
            if ($static_price != '') {
                $this_shipping_price = $static_price;
            } elseif ($cart['static_shipping_price'] > 0 ) {
                $this_shipping_price = $cart['static_shipping_price'];
            }

            $shipping_prices = [];
            $shipping_method = [];
            $shipping_method['code'] = '1';
            // If this is an admin-entered custom static quote, use the selected v2 shipping type directly.
            if ($cart['custom_shipping_price'] == 1 && $shipping_type1 != '') {
                $shipping_method['code'] = $shipping_type1;
            } elseif($cart['shipping_prices'][1]['code']!='' && $cart['custom_shipping_price']==1){
               $shipping_method['code'] = $cart['shipping_prices'][1]['code'];
            }
           
  // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);
            // echo __LINE__."
";
            // print_r($shipping_prices);
        
            if (
                $cart['shipping_prices'][1]['code'] != '' &&
                $cart['static_shipping_price'] > 0
            ) {
                $shipping_infos_1 = $pdo_db1->pquery(
                    "SELECT id,name,code FROM shipping_types WHERE  name='" .
                        $cart['shipping_prices'][1]['name'] .
                        "' and in_use = '1'"
                );
                if ($shipping_infos_1 != '') {
                    $shipping_method['code'] = $shipping_infos_1[0]['code'];
                    // $shipping_infos_1 = $pdo_db1->pquery("SELECT id,name FROM shipping_types WHERE  id='".$cart['shipping_prices'][1]['code']."' and in_use = '1'");
                    $shipping_name = $shipping_infos_1[0]['name'];
                    // echo "
";print_r($shipping_method); exit;
                } else {
                    $shipping_method['code'] =
                        $cart['shipping_prices'][1]['code'];
                    $shipping_infos_1 = $pdo_db1->pquery(
                        "SELECT id,name FROM shipping_types WHERE  id='" .
                            $cart['shipping_prices'][1]['code'] .
                            "' and in_use = '1'"
                    );
//added on 20240405 #tw-35979907 >> fetch shipping name when shipping type is Freight (we call truck)
                    $freight_flag = 0;
                    foreach ($cart['shipping_prices'] as $key => $shipping_price_code) {
                         if($shipping_price_code['code'] == '30'){
                                $freight_flag = 1;
                            }
                     }
                    if ($freight_flag == 1 && $cart['static_shipping_price'] >0  && $cart['custom_shipping_price'] == '1')
                    {
                       $shipping_infos_1 = $pdo_db1->pquery("SELECT id,name FROM shipping_types WHERE  id='" .$cart['shipping_prices'][1]['code'] ."' and in_use in ('1','2')");
                    }

                    $shipping_name = $shipping_infos_1[0]['name'];
                }

                /*$shipping_method["code"] = $cart['shipping_prices'][1]['code'];
                     $shipping_infos_1 = $pdo_db1->pquery("SELECT id,name FROM shipping_types WHERE  id='".$cart['shipping_prices'][1]['code']."' and in_use = '1'");
                     $shipping_name = $shipping_infos_1[0]['name'];*/
            }
               $this->write_cart_debug_log($cart['cart_id'],"Mid shipping_prices=>".json_encode($cart['shipping_prices']));
            if (
                strstr($shipping_name, 'Pickup') &&
                $val_set_oval_allowpickup == 0
            ) {
            } else {

   // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);
            // print_r($shipping_prices);
        
                
                /*$shipping_method['name'] = $shipping_name;
                $shipping_method['zip'] = $zip;
                $shipping_method['price'] = $this_shipping_price;
                $shipping_prices['1'] = $shipping_method;*/

                $shipping_method['name'] = $shipping_name;
                $shipping_method['zip'] = $zip;
                $shipping_method['price'] = $this_shipping_price;

                if((isset($cart['shipping_prices'][1])) || (is_array($cart['shipping_prices'][1]))){
                    $shipping_prices['1'] = $shipping_method;
                }

//// echo __LINE__."
";print_r($cart['shipping_prices']);


                $found = 0;
                foreach ($cart['order_items'] as $orderItem) {
                    // Check the 'over_size_item' in 'order_item_details_new'
                    foreach ($orderItem['order_item_details_new'] as $details) {
                        if (isset($details['over_size_item']) && $details['over_size_item'] == 0) {
                            $found = 1;
                            break 2; // Exit both loops
                        }
                    }
                }

                $shipping_prices['1'] = $shipping_method;
                if(($cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  || $cart['ship_country'] == 'CA') && $found == 1 ){

                }else{
                    
                    if ((is_array($cart['shipping_prices'][0]) && (array_key_exists("package_dimension", $cart['shipping_prices'][0]))) || (is_array($cart['shipping_prices'][1] && (!array_key_exists("package_dimension", $cart['shipping_prices'][1])))) || ((is_array($cart['shipping_prices'][2])) && (!array_key_exists("package_dimension", $cart['shipping_prices'][2])))){
                         $this->write_cart_debug_log($cart['cart_id'],"At place 1 set incentive"); 
                        $shipping_method['name'] = $shipping_name;
                        $shipping_method['zip'] = $zip;
                        $shipping_method['price'] = $this_shipping_price;
                        $shipping_method['in_use'] = $cart['shipping_prices'][0]['in_use'];
                        $shipping_method['is_exist'] = $cart['shipping_prices'][0]['is_exist'];
                        $shipping_method['is_set_in_cart_at'] = $cart['shipping_prices'][0]['is_set_in_cart_at'];
                        $shipping_method['api_price'] = $cart['shipping_prices'][0]['api_price'];
                        $shipping_method['requestXMLpath'] = $cart['shipping_prices'][0]['requestXMLpath'];
                        $shipping_method['responseXMLpath'] = $cart['shipping_prices'][0]['responseXMLpath'];
                        $shipping_method['original_api_shipping_cost'] = $cart['shipping_prices'][0]['original_api_shipping_cost'];
                        $shipping_method['incentive'] = $cart['shipping_prices'][0]['incentive'];
                        $shipping_method['package_weight'] = $cart['shipping_prices'][0]['package_weight'];
                        $shipping_method['package_dimension'] = $cart['shipping_prices'][0]['package_dimension'];

                        $shipping_prices['0'] = $shipping_method;

                    } 
                    
                    if ((is_array($cart['shipping_prices'][1]) && (array_key_exists("package_dimension", $cart['shipping_prices'][1]))) || (is_array($cart['shipping_prices'][0] && (!array_key_exists("package_dimension", $cart['shipping_prices'][0])))) || ((is_array($cart['shipping_prices'][2])) && (!array_key_exists("package_dimension", $cart['shipping_prices'][2])))){
                         $this->write_cart_debug_log($cart['cart_id'],"At place 2 set incentive"); 
                        $shipping_method['name'] = $shipping_name;
                        $shipping_method['zip'] = $zip;
                        $shipping_method['price'] = $this_shipping_price;
                        $shipping_method['in_use'] = $cart['shipping_prices'][1]['in_use'];
                        $shipping_method['is_exist'] = $cart['shipping_prices'][1]['is_exist'];
                        $shipping_method['is_set_in_cart_at'] = $cart['shipping_prices'][1]['is_set_in_cart_at'];
                        $shipping_method['api_price'] = $cart['shipping_prices'][1]['api_price'];
                        $shipping_method['requestXMLpath'] = $cart['shipping_prices'][1]['requestXMLpath'];
                        $shipping_method['responseXMLpath'] = $cart['shipping_prices'][1]['responseXMLpath'];
                        $shipping_method['original_api_shipping_cost'] = $cart['shipping_prices'][1]['original_api_shipping_cost'];
                        $shipping_method['incentive'] = $cart['shipping_prices'][1]['incentive'];
                        $shipping_method['package_weight'] = $cart['shipping_prices'][1]['package_weight'];
                        $shipping_method['package_dimension'] = $cart['shipping_prices'][1]['package_dimension'];

                        $shipping_prices['1'] = $shipping_method;

                    } 
                    
                    if ((is_array($cart['shipping_prices'][2]) && (array_key_exists("package_dimension", $cart['shipping_prices'][2]))) || (is_array($cart['shipping_prices'][0] && (!array_key_exists("package_dimension", $cart['shipping_prices'][0])))) || ((is_array($cart['shipping_prices'][1])) && (!array_key_exists("package_dimension", $cart['shipping_prices'][1])))){
                         $this->write_cart_debug_log($cart['cart_id'],"At place 3 set incentive"); 
                        $shipping_method['name'] = $shipping_name;
                        $shipping_method['zip'] = $zip;
                        $shipping_method['price'] = $this_shipping_price;
                        $shipping_method['in_use'] = $cart['shipping_prices'][2]['in_use'];
                        $shipping_method['is_exist'] = $cart['shipping_prices'][2]['is_exist'];
                        $shipping_method['is_set_in_cart_at'] = $cart['shipping_prices'][2]['is_set_in_cart_at'];
                        $shipping_method['api_price'] = $cart['shipping_prices'][2]['api_price'];
                        $shipping_method['requestXMLpath'] = $cart['shipping_prices'][2]['requestXMLpath'];
                        $shipping_method['responseXMLpath'] = $cart['shipping_prices'][2]['responseXMLpath'];
                        $shipping_method['original_api_shipping_cost'] = $cart['shipping_prices'][2]['original_api_shipping_cost'];
                        $shipping_method['incentive'] = $cart['shipping_prices'][2]['incentive'];
                        $shipping_method['package_weight'] = $cart['shipping_prices'][2]['package_weight'];
                        $shipping_method['package_dimension'] = $cart['shipping_prices'][2]['package_dimension'];

                        $shipping_prices['2'] = $shipping_method;
                    }

                    if(is_array($cart['shipping_prices'][0]) && ((!array_key_exists("package_dimension", $cart['shipping_prices'][0])) || (is_array($cart['shipping_prices'][1]) && (!array_key_exists("package_dimension", $cart['shipping_prices'][1]))) || (is_array($cart['shipping_prices'][2]) && (!array_key_exists("package_dimension", $cart['shipping_prices'][2]))))){

                        $shipping_method['name'] = $shipping_name;
                        $shipping_method['zip'] = $zip;
                        $shipping_method['price'] = $this_shipping_price;
                        $shipping_method['package_dimension'] = $_POST['package_dimension'];
                        $shipping_prices['0'] = $shipping_method;
                    }
                }
                
            }
      // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);
            // print_r($shipping_prices);
        
        } else {
               ////echo __LINE__."
";print_r($cart['shipping_prices']);
            if (
                isset($_GET['shipping_options']) &&
                $_GET['shipping_options'] == '1'
            ) {
                //  echo "here in over sizes";
            }

            $shipping_infos_pickup = $pdo_db1->pquery(
                'SELECT * FROM shipping_types WHERE  id IN(' .
                    $availShipOptStr .
                    ") and in_use = '1' ORDER BY shipping_types.cart_page_order ASC "
            );
            if (
                $we_have_a_big_item == 'yes' ||
                ($flag_box == 1 &&
                    $pdo_db1->pdo_num_rows($shipping_infos_pickup) == 0)
            ) {
                //over_size
                if ($over_size_items_total > 0 || $flag_box == 1) {
                    //items_over_size not found in datebase
                    $shipping_prices = [];
                    $shipping_method = [];
                    $shipping_method['code'] = '1';
                    $shipping_method['name'] = 'Size to big.';
                    $shipping_method['zip'] = $zip;
                    $shipping_method['error'] = 'Size to big.';
                    $shipping_method['price'] = 0;
                    $shipping_prices['1'] = $shipping_method;
                    if (
                        isset($_GET['check_shipping']) &&
                        $_GET['check_shipping'] == '1'
                    ) {
                        //echo '
';print_r($shipping_prices);
                        //exit;
                    }
                } else {
                    //items_over_size FOUND in datebase
                    $shipping_prices = [];
                    $shipping_method = [];
                    $shipping_method['code'] = '1';
                    $shipping_method['name'] = 'UPS Ground';
                    $shipping_method['zip'] = $zip;
                    $shipping_method['price'] =
                        $this->over_size_item_shipping($over_size_arr) +
                        $this->regular_size_item_shipping(
                            $regular_size_items_total
                        );
                    $shipping_prices['1'] = $shipping_method;
                }
// echo __LINE__."
";
//             print_r($shipping_prices);
                if (
                    isset($_SESSION['permissions']) &&
                    $_SESSION['permissions'] == 3
                ) {
                    //print_r($over_size_arr);
                    //print_r($this->over_size_item_shipping( $over_size_arr ));
                    //echo '-';
                    //print_r($this->regular_size_item_shipping($regular_size_items_total));
                    //exit;
                }
            } else {
                //regular_size
                //print_r($over_size_values_shipping);exit;
                $wherecondition = '';
                if ($flag_box == 1) {
                    $wherecondition = 'id IN(' . $availShipOptStr . ') AND ';
                }
                // echo "SELECT * FROM shipping_types WHERE ".$wherecondition."in_use = '1' ORDER BY shipping_types.cart_page_order ASC "; exit;
                $shipping_infos_query =
                    'SELECT * FROM shipping_types WHERE ' .
                    $wherecondition .
                    "in_use = '1' ORDER BY shipping_types.cart_page_order ASC ";
                if (
                    isset($_GET['shipping_options']) &&
                    $_GET['shipping_options'] == '1'
                ) {
                    echo '
' . __LINE__ . '#shipping_infos_query=>' . $shipping_infos_query; } $shipping_infos = $pdo_db1->pquery( $shipping_infos_query, 'FETCH_BOTH' ); if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { } // echo __LINE__."
";
            // print_r($shipping_prices);
                 ////echo __LINE__."
";print_r($cart['shipping_prices']);
                foreach ($shipping_infos as $shipping_info) {
                    $ship_flag = 0;
                    // if((strstr($shipping_info['name'],"Pickup Brooklyn") || strstr($shipping_info['name'],"Pickup test")) && $val_set_oval_allowpickup == 0) {
                    if (
                        strstr($shipping_info['name'], 'Pickup') &&
                        $val_set_oval_allowpickup == 0
                    ) {
                        // echo "in 1233=====================
"; } else { // echo "in 1225=====================
"; $shipping_method = []; #$free_shipping = $shipping_info['free_shipping']; /* Below free shipping value updated on 20220602 By Savata B. Reference Task link.: https://arttoframes.teamwork.com/#/tasks/28161831 */ $free_shipping = isset($_SESSION['hide_economy_shipping']) && $_SESSION['hide_economy_shipping'] == '1' && $shipping_info['id'] == 2 ? '1' : $shipping_info['free_shipping']; $shipping_method['code'] = $shipping_info['code']; $shipping_method['name'] = $shipping_info['name']; $shipping_method['in_use_canada'] = $shipping_info['in_use_canada']; $shipping_method['zip'] = $zip; $shipping_method['allow_free_shipping'] = $shipping_info['allow_free_shipping']; $shipping_method['free_shipping_minimum'] = $shipping_info['free_shipping_minimum']; if ($flag_box == 1) { $shipping_method['error'] = 'Size to big.'; } // if(($customprice_shipping == 1 && $zip =='US') || ($customprice_shipping == 1 && $cart["ship_country"]!='CA' && $ship_country != 'CA' && $ship_country != 'Canada') ) { $shipping_type = $shipping_info['id']; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo '
' . __LINE__ . '#free_shipping=>' . $free_shipping; echo '
' . __LINE__ . '#zip=>' . $zip; echo '
' . __LINE__ . '#ship_country=>' . $cart['ship_country']; var_dump( ($free_shipping == 1 && $zip == 'US') || ($free_shipping == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada') ); } if ( ($free_shipping == 1 && $zip == 'US') || ($free_shipping == 1 && $cart['ship_country'] != 'CA' && $ship_country != 'CA' && $ship_country != 'Canada') ) { if ($customprice_shipping_standardsize == 1) { $regular_size_items_total_1 = $regular_size_items_total_1 - $total_standard_regular_qty; } if ($customprice_shipping_longboxsize == 1) { $long_box_size_items_total_1 = $long_box_size_items_total_1 - $total_standard_longbox_qty; } if ($customprice_shipping_oversize == 1) { $over_size_items_total_1 = $over_size_items_total_1 - $total_standard_oversizebox_qty; } if ($customprice_shipping_largesize == 1) { $largesize_box_items_total_1 = $largesize_box_items_total_1 - $total_standard_largesizebox_qty; } $regular_size_items_price = $this->get_atf_shipping_price( $over_size_values_final, $shipping_type, $free_shipping_cf_prod ); if ($customprice_shipping_standardsize == 1) { $regular_size_items_total_1 = $regular_size_items_total_1 + $total_standard_regular_qty; } if ($customprice_shipping_longboxsize == 1) { $long_box_size_items_total_1 = $long_box_size_items_total_1 + $total_standard_longbox_qty; } if ($customprice_shipping_oversize == 1) { $over_size_items_total_1 = $over_size_items_total_1 + $total_standard_oversizebox_qty; } if ($customprice_shipping_largesize == 1) { $largesize_box_items_total_1 = $largesize_box_items_total_1 + $total_standard_largesizebox_qty; } } else { $regular_size_items_price = $this->get_atf_shipping_price( $over_size_values_final, $shipping_type ); } if ( isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3 ) { //echo $shipping_info['name'] . ' - ' . $regular_size_items_price . ' - ' .$long_box_items_price ; //exit; } //offer related changes - Solace if ($item_ctr == $offer_ctr && $x == 1) { // echo "in offer ctr"; $shipping_method['price'] = 0; } else { // echo "in else"; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { $extra_shipping_cost_va = $this->validateStateForShipping( $cart['ship_state'] ); if ( $giftCardShippingTextStatus > 0 && $otherProducts == 0 ) { $extra_ship_cost = 0; } $extra_ship_cost = $extra_shipping_cost_va; echo '
Shipping type=' . $shipping_method['name'] . ''; echo '
regular size item price=' . $regular_size_items_price; echo ' +long size item price=' . $long_box_items_price; echo ' +over size item price=' . $oversize_box_items_price; echo ' +large size item price=' . $largesize_box_items_price; echo ' +Extra Shipping cost=' . $extra_ship_cost; /* No Need to override shipping price from shipping_types table if shipping_types.quote_needed flag is set to 1 in DB table set cart price date : 08June2022 */ if ($shipping_info['quote_needed_field'] == 1) { $shipping_method['price'] = $cart['shipping_prices'][$x]['price']; } else { echo '
Total Price=' . ($shipping_method['price'] = $regular_size_items_price + $long_box_items_price + $oversize_box_items_price + $large_box_items_price + $extra_ship_cost); } } /* No Need to override shipping price from shipping_types table if shipping_types.quote_needed flag is set to 1 in DB table set cart price date : 08June2022 */ /*if (isset($cart['shipping_prices'][$x]['api_price'])) { $shipping_method["price"] = $cart['shipping_prices'][$x]['price']; }else{ $shipping_method["price"] = $regular_size_items_price; }*/ $getBoxCount = $cart['no_of_box']; // {Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in } so we have check isset and of not then declare as empty array for db9 on 13 oct 2023 $order_items = is_array($cart['order_items']) ? $cart['order_items'] : []; $order_items_count = count($order_items); $is_oversized_item = $order_items[0]['order_item_details_new'][0]['over_size_item']; //foreach ($order_items as $order_items_key => $order_items_value) { if ( $cart['is_box_not_available_request_quote'] == '1' ) { $is_box_not_available_request_quote = $cart['is_box_not_available_request_quote']; } // } $is_quote_needed_shipping_method = ( (isset($shipping_info['quote_needed_field']) && $shipping_info['quote_needed_field'] == 1) || in_array((string)$shipping_info['code'], array('3', '5', '36'), true) ); $has_rateshop_api_price = ( isset($cart['shipping_prices'][$x]['api_price']) && $cart['shipping_prices'][$x]['api_price'] !== '' && (float)$cart['shipping_prices'][$x]['api_price'] > 0 ); $has_rateshop_request_path = ( !empty($cart['shipping_prices'][$x]['requestXMLpath']) || !empty($cart['shipping_prices'][$x]['responseXMLpath']) ); if ( ($has_rateshop_api_price || $has_rateshop_request_path) && ($cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' || $cart['ship_state'] == 'VI' || $cart['ship_state'] == 'PR' || $cart['ship_country'] == 'CA' || $cart['isRateShopForAvailableBox'] == 'RATE_SHOP' || $is_box_not_available_request_quote == 1 || $is_quote_needed_shipping_method) && $boxCount < 1 ) { $shipping_method['price'] = $cart['shipping_prices'][$x]['price']; $shipping_method['api_price'] = $cart['shipping_prices'][$x]['api_price']; $shipping_method['requestXMLpath'] = $cart['shipping_prices'][$x]['requestXMLpath']; $shipping_method['responseXMLpath'] = $cart['shipping_prices'][$x]['responseXMLpath']; } elseif ($is_quote_needed_shipping_method) { // Quote-needed services should not persist static large-box fallback prices // before a real rateshop/API quote is saved. Keep them at the configured base price. $shipping_method['price'] = isset($shipping_info['base_price']) ? $shipping_info['base_price'] : 0; } else { $shipping_method['price'] = $regular_size_items_price; } } $shipping_prices[$x] = $shipping_method; $x++; } } } //end if bigest } //end $static_price //echo "
";print_r($cart);exit;
// echo __LINE__."
";
           // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);

        
        /*if($flag_box == 1){
            //$cart["shipping_type"] = 10;
        }elseif($flag_box == 0 && $val_set_oval_allowpickup == 0){
            //$cart["shipping_type"] = 1;
        }*/

        // {Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in } so we have check isset and of not then declare as empty array for db9 on 13 oct 2023
        $order_items = is_array($cart['order_items'])
            ? $cart['order_items']
            : [];

        $order_items_count = count($order_items);
        //commented for loop 
        //foreach ($order_items as $order_items_key => $order_items_value)
         //{
            if ($cart['is_box_not_available_request_quote'] == '1') {
                //$is_box_not_available_request_quote =$cart['is_box_not_available_request_quote'];
            }
        //}
        $qty_oversized_item =
            $order_items[0]['order_item_details_new'][0]['qty'];
        //Modified below condtion on 20240206 #TW35156577 :added '&& empty($cart['custom_shipping_price'])' in if condition to avoid setting pickup shipping method via admin custom shipping
        if (
            $flag_box == 1 &&
            $is_box_not_available_request_quote == 1 &&
            ($qty_oversized_item > 2 || $order_items_count > 1) &&
           (float)$cart['static_shipping_price'] == 0.0 && empty($cart['custom_shipping_price'])
        ) {
            //added below condition on 20240530 #TW36599155: To set pick heaven(57) if changed shipping method from  pick-up brooklyn(10) to pick-up heaven(57)
            if($cart['shipping_type'] !=57)
                $shipping_type = $cart['shipping_type'] = 10;
        } else {
            $shipping_type = $cart['shipping_type'];
        }


        // echo __LINE__."
";
        //     print_r($cart['shipping_prices']);



        /*if($flag_box == 1 && $cart['static_shipping_price'] == ""){
            $shipping_type = $cart["shipping_type"] = 10;
        }else{
            $shipping_type = $cart["shipping_type"];
        }*/

           ////echo __LINE__."
";print_r($cart['shipping_prices']);

        //$shipping_type = $cart["shipping_type"];
        $extra_ship_cost = '';
        //echo "$callGoogleAPI"; die;
        if ($callGoogleAPI != '') {
            $extra_shipping_cost = $this->calculate_extra_shipping_cost(
                $zip,
                $cart
            );

            $extra_ship_cost = $extra_shipping_cost['added_cost'];
            $shipping_type = $cart['shipping_type'];

            // if($shipping_type == 10 || $shipping_type == 57 || $shipping_type == 58){
            if (in_array($shipping_type, $availShipOptArr)) {
                $cart['ship_country'] = $extra_shipping_cost['country'];

                $cart['shipping_cost'] =
                    $shipping_prices['10']['price'] + $extra_ship_cost;
                $cart['shipping_type'] = $shipping_type;
            } elseif (
                $cart['ship_state'] == 'AK' ||
                $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  ||
                $cart['ship_country'] == 'CA' ||
                $cart['ship_country'] == 'Canada'
            ) {
                $cart['ship_country'] = $extra_shipping_cost['country'];
                /*No Need to Add extra ship Cost we have already added extra cost while get shipping quote api called so set as 0 Date : 02-02-2023*/
                $extra_ship_cost = 0;
                $cart['shipping_cost'] =
                    $shipping_prices['2']['price'] + $extra_ship_cost;
                $cart['shipping_type'] = $shipping_prices['2']['code'];
            } else {
                $cart['ship_country'] = $extra_shipping_cost['country'];

                $cart['shipping_cost'] =
                    $shipping_prices['1']['price'] + $extra_ship_cost;
                $cart['shipping_type'] = $shipping_prices['1']['code'];
            }
            //echo "
"; print_r($shipping_prices); die;
            if (
                $cart['ship_country'] == 'CA' ||
                $cart['ship_country'] == 'Canada'
            ) {
                //echo "
"; print_r($shipping_prices); die;
                foreach ($shipping_prices as $key => $ship_price) {
                    if ($ship_price['in_use_canada'] == 1) {
                        $cart['shipping_cost'] =
                            $shipping_prices[$key]['price'] + $extra_ship_cost;
                        $cart['shipping_type'] = $shipping_prices[$key]['code'];

                        break;
                    }
                }
            }

            // echo __LINE__."
";
            // print_r($cart['shipping_prices']);
        } else {
            //if($callGoogleAPI=='' && $zip !='US')
            if ($zip == 'US') {
            } else {
                if (
                    $cart['ship_country'] == 'CA' ||
                    $cart['ship_country'] == 'Canada'
                ) {
                    /*No Need to Add extra ship Cost we have already added extra cost while get shipping quote api called so set as 0 Date : 02-02-2023*/
                    $extra_ship_cost = 0;
                    //$extra_ship_cost = 50;
                } else {
                    $extra_shipping_cost_va = $this->validateStateForShipping(
                        $cart['ship_state']
                    );
                    $extra_ship_cost = $extra_shipping_cost_va;
                }
            }
        }

        if ($giftCardShippingTextStatus > 0 && $otherProducts == 0) {
            $extra_ship_cost = 0;
        }

        //if($zip =='US') //old condition
        if ($extra_ship_cost > 0 || $zip == 'US') {
            //new condition added as on 20190808
            if ($cart['shipping_type'] == '' || $cart['shipping_type'] == 1) {
                // Use type casting (10-10-2023)
                $cart['shipping_cost'] =
                    (float) $shipping_prices['1']['price'] +
                    (float) $extra_ship_cost;
                $cart['shipping_type'] = $shipping_prices['1']['code'];
            }
        }
        $shipping_type = $cart['shipping_type'];
   //// echo __LINE__."
";print_r($cart['shipping_prices']);

        if (
            $cart['ship_country'] == 'CA' ||
            $cart['ship_country'] == 'Canada'
        ) {
            foreach ($shipping_prices as $key => $ship_price) {
                // if($shipping_prices[$key]['code']!=10 && $shipping_type !=10 && $shipping_prices[$key]['code']!=57 && $shipping_type !=57 && $shipping_prices[$key]['code']!=58 && $shipping_type !=58)
                if (
                    !in_array(
                        $shipping_prices[$key]['code'],
                        $availShipOptArr
                    ) &&
                    !in_array($shipping_type, $availShipOptArr)
                ) {
                    if ($ship_price['in_use_canada'] == 1) {
                        $cart['shipping_type'] = $ship_price['code'];
                        $shipping_type = $ship_price['code'];
                    }
                }
            }

            foreach ($shipping_prices as $key => $ship_price) {
                // if($shipping_prices[$key]['code']!=10 && $shipping_prices[$key]['code']!=57 && $shipping_prices[$key]['code']!=58)
                if (
                    !in_array($shipping_prices[$key]['code'], $availShipOptArr)
                ) {
                    $shipping_prices[$key]['price'] = floatval($shipping_prices[$key]['price']);
                    $extra_ship_cost = floatval($extra_ship_cost);

                    $shipping_prices[$key]['price'] += $extra_ship_cost;
                }
                if ($ship_price['in_use_canada'] == 1) {

                //Changed code on 20231229 #TW35116704: added if condition same as for regular zip code and already exist code is added in else
                if (
                    $ship_price['allow_free_shipping'] == '1' &&
                    $cart['subtotal'] >= $ship_price['free_shipping_minimum']
                ) {
                    if (
                        $cart['shipping_type'] == $shipping_prices[$key]['code']
                    ) {
                        $cart['shipping_cost'] = 0;
                          
                    }
                    $shipping_prices[$key]['price'] = 0;
                } else {

                    if ($callGoogleAPI != '') {
                        if ($shipping_type == $ship_price['code']) {
                            $cart['shipping_cost'] =
                                $shipping_prices[$key]['price'];
                            $cart['shipping_type'] = $shipping_type;
                        }
                    } else {
                        if ($cart['shipping_type'] == $ship_price['code']) {
                             /** Added The new if condition to avoid the shipping calculation when update the qty of giftcard on cartpage Dt:20240103 */
                             if($giftCardShippingTextStatus > 0 && $otherProducts == 0){
                                $cart['shipping_cost'] = 0;
                            }else{
                              $cart['shipping_cost'] = $shipping_prices[$key]['price'];
                            }
                        }
                    }
                }
                }

                //$shipping_prices[$key]["price"] = number_format($shipping_rate, 2);
            } // END FOR
        } else {
            foreach ($shipping_prices as $key => $ship_price) {
                // if($shipping_prices[$key]['code']!=10 && $shipping_prices[$key]['code']!=57 && $shipping_prices[$key]['code']!=58)
                if (
                    !in_array($shipping_prices[$key]['code'], $availShipOptArr)
                ) {
                    // Use type casting (10-10-2023)
                    (float) ($shipping_prices[$key]['price'] += (float) $extra_ship_cost);
                }

                if (
                    $ship_price['allow_free_shipping'] == '1' &&
                    $cart['subtotal'] >= $ship_price['free_shipping_minimum']
                ) {
                    if (
                        $cart['shipping_type'] == $shipping_prices[$key]['code']
                    ) {
                        $cart['shipping_cost'] = 0;
                    }
                    $shipping_prices[$key]['price'] = 0;
                } else {
                    if ($callGoogleAPI != '') {
                        if ($shipping_type == $ship_price['code']) {
                            $cart['shipping_cost'] =
                                $shipping_prices[$key]['price'];
                            $cart['shipping_type'] = $shipping_type;
                        }
                    } else {
                        if ($cart['shipping_type'] == $ship_price['code']) {
                            /** Added The new if condition to avoid the shipping calculation when update the qty of giftcard on cartpage Dt:20240104 */
                            if($giftCardShippingTextStatus > 0 && $otherProducts == 0){
                                $cart['shipping_cost'] = 0;
                            }else{
                              $cart['shipping_cost'] = $shipping_prices[$key]['price'];
                            }
                        }
                    }
                }
                //$shipping_prices[$key]["price"] = number_format($shipping_rate, 2);
            } // END FOR
        }
   // echo __LINE__."
";print_r($cart['shipping_prices']);

    //echo __LINE__."
";echo ($cart['shipping_cost']);
        //do not consider the shipping types 1,3,5,36 for CA country
        //$ship_not_in_array = array(1,3,5,36);
        $ship_not_in_array = [3, 5, 36];
        $ship_count = 1;
        //echo "123"; die;
        //commented below code on 20240108 #TW35156577: $ship_response is not defined so preapred shipping_prices array become empty
        // if (
        //     $cart['ship_country'] == 'CA' ||
        //     $cart['ship_country'] == 'Canada'
        // ) {
        //     
        //     foreach ($shipping_prices as $ship_key => $ship_value) {
        //         //if(!in_array($ship_value["code"], $ship_not_in_array))
        //         //{
        //         if ($ship_value['in_use_canada'] == 1) {
        //             $ship_response[$ship_count] = $ship_value;
        //             $ship_count++;
        //         }
        //         //}
        //     }

         //  $shipping_prices = $ship_response;
        //    
        // }

        if ($shipping_prices['1']['name'] == 'Pickup Brooklyn, NY - 5-7 days') {
            $shipping_prices['1']['code'] = '10';
        }
        // echo "1500
";print_r($shipping_prices); exit;
        // if($static_price > 0 && ($shipping_prices['1']['code'] != '10' && $shipping_prices['1']['code'] != '57' && $shipping_prices['1']['code'] != '58')){
        // echo "1502
";print_r($cart); exit;
        // if($static_price > 0 && !in_array($shipping_prices['1']['code'], $availShipOptArr)){
        // echo __LINE__."
"; print_r($cart); exit;
        if ($static_price > 0 || $cart['static_shipping_price'] > 0) {
            // echo "in"; exit;
            $shipping_infos = $pdo_db1->pquery(
                'SELECT * FROM shipping_types WHERE id IN(' .
                    $availShipOptStr .
                    ") and in_use = '1' ORDER BY shipping_types.cart_page_order ASC "
            );
            // echo "
";print_r($shipping_infos); exit;
            foreach ($shipping_infos
                as $shipping_infoKey => $shipping_infoValue) {
                $shipping_info = $shipping_infoValue;
                $shipping_method = [];
                $shipping_method['code'] = $shipping_infoValue['code'];
                $shipping_method['name'] = $shipping_infoValue['name'];
                $shipping_method['in_use_canada'] =
                    $shipping_infoValue['in_use_canada'];
                $shipping_method['zip'] = $zip;
                $shipping_method['allow_free_shipping'] =
                    $shipping_infoValue['allow_free_shipping'];
                $shipping_method['free_shipping_minimum'] =
                    $shipping_infoValue['free_shipping_minimum'];

                if (
                    $shipping_infoValue['allow_free_shipping'] == '1' &&
                    $cart['subtotal'] >=
                    $shipping_infoValue['free_shipping_minimum']
                ) {
                    if (
                        $cart['shipping_type'] == $shipping_prices[$key]['code']
                    ) {
                        $cart['shipping_cost'] = 0;
                    }
                    $regular_size_items_price = 0;

                    // echo "============Price in if==========".$regular_size_items_price;
                } else {
                    $regular_size_items_price = $this->get_atf_shipping_price(
                        $over_size_values_final,
                        $shipping_info['code']
                    );
                    // echo "============Price in else==========".$regular_size_items_price;
                }
                  $shipping_method['price'] = $regular_size_items_price;
                //removed array_push and added below code on 20240103 #TW35116704
                $shipping_prices[]= $shipping_method;
                
                // $shipping_prices['2'] = $shipping_method;
            }

            $ship_i = 1;
            foreach ($shipping_prices
                as $shipping_pricekey => $shipping_priceValue) {
                if ($ship_i > 1) {
                    if (
                        $shipping_priceValue['code'] ==
                        $shipping_prices[1]['code']
                    ) {
                        unset($shipping_prices[$shipping_pricekey]);
                    }
                }
                $ship_i++;
            }
            // echo "1533
";print_r($shipping_prices); exit;

            // $shipping_info   = $shipping_infos[0];
            /* $shipping_method = array();
              $shipping_method["code"] = $shipping_info['code'];
                $shipping_method["name"] = $shipping_info['name'];
                $shipping_method["in_use_canada"] = $shipping_info['in_use_canada'];
                $shipping_method["zip"] = $zip;
                $shipping_method["allow_free_shipping"] = $shipping_info['allow_free_shipping'];
                $shipping_method["free_shipping_minimum"] = $shipping_info['free_shipping_minimum'];*/

            /*if($shipping_info["allow_free_shipping"] == '1' && $cart['subtotal'] >= $shipping_info["free_shipping_minimum"]) {
            if($cart['shipping_type'] == $shipping_prices[$key]['code']) {
                $cart["shipping_cost"] = 0;
            }*/
            // $regular_size_items_price =  0;

            /*echo "============Price in if==========".$regular_size_items_price;*/

            /*}else{
                  $regular_size_items_price = $this->get_atf_shipping_price($over_size_values_final,$shipping_info['code']);
              }
                $shipping_method["price"] = $regular_size_items_price;
                $shipping_prices['2'] = $shipping_method;*/
        }
        /*echo "1556 Cart
";print_r($cart);
         echo "
1556 shipping_prices
";print_r($shipping_prices); exit;*/
        // echo "out"; exit;

            ////echo __LINE__."
";print_r($cart['shipping_prices']);
        // if($cart['static_shipping_price'] > 0 && $cart['shipping_type'] !=10 && $cart['shipping_type'] !=57 && $cart['shipping_type'] !=58){
        if (
            $cart['static_shipping_price'] > 0 &&
            !in_array($cart['shipping_type'], $availShipOptArr)
        ) {
            $cart['shipping_cost'] = $cart['static_shipping_price'];
        }

        $cart['static_shipping_price'] = $static_price;
        /*if (isset($cart["shipping_prices"][0]['requestXMLpath']) || isset($cart["shipping_prices"][3]['requestXMLpath']) || isset($cart["shipping_prices"][4]['requestXMLpath']) || isset($cart["shipping_prices"][5]['requestXMLpath'])) {
            
        }else{
            $cart["shipping_prices"]=$shipping_prices;  
        }*/

        /*if(($cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  || $cart['ship_country'] == 'CA') || ($is_box_not_available_request_quote==1)){

        }else{
            $cart["shipping_prices"]=$shipping_prices;  
        }*/

        /*if ((isset($cart["shipping_prices"][0]['requestXMLpath']) || isset($cart["shipping_prices"][3]['requestXMLpath']) || isset($cart["shipping_prices"][4]['requestXMLpath']) || isset($cart["shipping_prices"][5]['requestXMLpath'])) && (($cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  || $cart['ship_country'] == 'CA') || ($is_box_not_available_request_quote==1))) {
            
        }else{
            $cart["shipping_prices"]=$shipping_prices;  
        }*/
//echo __LINE__."
";print_r($cart['shipping_prices']);
        foreach ($cart['order_items']
            as $order_items_key => $order_items_value) {
            if (
                $order_items_value['order_item_details_new'][0]['is_box_not_available_request_quote'] == '1'
            ) {
                $is_box_not_available_request_quote =
                    $order_items_value['order_item_details_new'][0]['is_box_not_available_request_quote'];
            }
        }

        $qty_oversized_item =
            $cart['order_items'][0]['order_item_details_new'][0]['qty'];

        $flg_get_shipping = 0;
        if ($cart['custom_shipping_price'] == 0) {
            $flg_get_shipping = 1;
        } elseif (
            $cart['custom_shipping_price'] > 0 &&
            isset($cart['shipping_quote_source']) && $cart['shipping_quote_source']!=''
        ) {
            $flg_get_shipping = 1;
        } else {
            $flg_get_shipping = 0;
        }

        $getBoxCount = $cart['no_of_box'];
        $availShiptoGetQuoteOptArr = [];

        $availShiptoGetQuoteOpt = $pdo_db1->pquery(
            'SELECT id,code FROM shipping_types WHERE quote_needed_field=1'
        );

        foreach ($availShiptoGetQuoteOpt as $key => $value) {
            array_push($availShiptoGetQuoteOptArr, $value['code']);
        }
        // {Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in } so we have check isset and of not then declare as empty array for db9 on 13 oct 2023
        $order_items = is_array($cart['order_items'])
            ? $cart['order_items']
            : [];

        $order_items_count = count($order_items);

        if (
            (isset($cart['shipping_vars']['city']) &&
                isset($cart['shipping_vars']['zip']) &&
                $is_box_not_available_request_quote == 1 &&
                $qty_oversized_item <= 2 &&
                $order_items_count == 1 &&
                $flg_get_shipping == 1) ||
            (($cart['ship_state'] == 'AK' ||
                $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  ||
                $cart['ship_country'] == 'CA' ||
                $cart['ship_country'] == 'Canada') &&
                $getBoxCount <= 1 &&
                $is_box_not_available_request_quote != 1 &&
                $order_items_count > 0) ||
            (is_array($availShiptoGetQuoteOptArr) &&
                $getBoxCount <= 1 &&
                $is_box_not_available_request_quote != 1 &&
                $cart['zip_code'] != '' &&
                $cart['zip_code'] != 'US' &&
                $order_items_count > 0)
        ) {
            if (
                $cart['ship_state'] == 'AK' ||
                $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  ||
                $cart['ship_country'] == 'CA' ||
                $cart['ship_country'] == 'Canada' ||
                (isset($cart['shipping_vars']['city']) &&
                    isset($cart['shipping_vars']['zip']) &&
                    $is_box_not_available_request_quote == 1 &&
                    $qty_oversized_item <= 2 &&
                    $order_items_count == 1 &&
                    $flg_get_shipping == 1)
            ) {
               

                $new_array =array();
                if(is_array($cart['shipping_prices']) && count($cart['shipping_prices'])){
                    $shipping_type_flag = false;
                    $shipping_type_arr = array();

                     // echo "
",print_r($shipping_prices);
                     // echo "
",print_r($cart['shipping_prices']);
                     if(count($shipping_prices)> count($cart['shipping_prices'])){
                         foreach($shipping_prices as $k=>$method){
                           
                                foreach($cart['shipping_prices'] as $k1=>$method1){
                                    if($method1['code'] ==$method['code'] ){
                                       $cart['shipping_prices'][$k] = $method;
                                    }else if(!empty($method1['code'])){
                                         $cart['shipping_prices'][$k] = $method;
                                    }
                                }
                           
                        }
                    }else{
                        foreach($cart['shipping_prices'] as $k=>$method){
                           
                                foreach($shipping_prices as $k1=>$method1){
                                    if($method1['code'] ==$method['code'] ){
                                       $cart['shipping_prices'][$k] = $method;
                                    }
                                }
                           
                        }
                       
                    }
                    // echo "==============>
"; // echo "
",print_r($cart['shipping_prices']);
                   
                     if($cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' ||  $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  || $cart['ship_country'] == 'CA' || $cart['ship_country'] == 'Canada' ){
                         foreach($cart['shipping_prices'] as $k=>$method){
                                if(!isset($method['api_price']) && !in_array($method['code'],array('10', '57')) && $getBoxCount >1){
                                        unset($cart['shipping_prices'][$k]);
                                        continue;
                                }
                                
                            }
                     }
                     
                     
               
                }else{
                     //code added on 20241011 #TW37997634: set the calculated shipping methods to $cart['shipping_prices'], also set the shipping_type and shipping_cost if shipping_type is empty
                    if(is_array($shipping_prices) && count($shipping_prices)){
                        $t_shipping_type = '';
                        $t_shipping_cost = '';
                        $shipping_type_exist =false;
                        foreach($shipping_prices as $k1=>$method1){
                             if($k1==0){
                            $t_shipping_type = $method1['code'];
                            $t_shipping_cost = $method1['price'];
                            }
                            if($cart['shipping_type']==$method1['code']){
                                $shipping_type_exist = true;
                            }
                        }
                        if(!$shipping_type_exist){
                            $cart['shipping_type'] = $t_shipping_type;
                            $cart['shipping_cost'] = $t_shipping_cost;

                        }
                    }
                    $cart['shipping_prices'] = $shipping_prices;

                }
            
               
               
            } else {

          

                foreach ($shipping_prices as $key => $option) {
//added on 20240404 #tw-35979907 >> add shipping_prices of Freight (we call truck)
                    if ($cart['shipping_type'] =='30' &&  $cart['static_shipping_price'] >0  && (float)$cart['static_shipping_price'] != 0.0 && $cart['custom_shipping_price'] == '1'){
                        $shipping_code = [1, 2, 10, 57,30];
                    }else{
                        $shipping_code = [1, 2, 10, 57];
                    }
                    if (in_array($option['code'], $shipping_code)) {
                        if (
                            $cart['ship_state'] == 'AK' ||
                            $cart['ship_state'] == 'HI' ||
                             $cart['ship_state'] == 'VI'  ||  $cart['ship_state'] == 'PR'  ||
                            $cart['ship_country'] == 'CA' ||
                            $cart['ship_country'] == 'Canada'
                        ) {
                            $new_array[] = $cart['shipping_prices'][$key];
                        } else {
                            $new_array[] = $shipping_prices[$key];
                        }
                    } else {
                          $new_array[] = $shipping_prices[$key];
                    }
                }
                array_unshift($new_array, '');
                unset($new_array[0]);
                $cart['shipping_prices'] = $new_array;
    
            }

            // echo __LINE__."
";
            // print_r($cart['shipping_prices']);


        } elseif (
            ($is_box_not_available_request_quote == 1 && $getBoxCount > 1) ||
            (($cart['ship_state'] == 'AK' ||
                $cart['ship_state'] == 'HI' ||
                 $cart['ship_state'] == 'VI' ||  $cart['ship_state'] == 'PR'  ||
                $cart['ship_country'] == 'CA' ||
                $cart['ship_country'] == 'Canada') &&
                $getBoxCount > 1 &&
                $is_box_not_available_request_quote != 1 &&
                $order_items_count > 0) ||
            (is_array($availShiptoGetQuoteOptArr) &&
                $getBoxCount > 1 &&
                $is_box_not_available_request_quote != 1 &&
                $order_items_count > 0)
        ) {
            foreach ($shipping_prices as $key => $option) {
                if (in_array($option['code'], [3, 5, 36])) {
                    continue;
                } else {
                    $new_array[] = $shipping_prices[$key];
                    array_unshift($new_array, '');
                    unset($new_array[0]);
                }
            }
            $cart['shipping_prices'] = $new_array;
            // echo __LINE__."
";
            // print_r($cart['shipping_prices']);
            
        } else {
            $cart['shipping_prices'] = $shipping_prices;
        }



//echo __LINE__."
";print_r($shipping_prices);

// echo __LINE__."
";print_r($new_array);

        /*$cart["test"]=$test;*/
        if (isset($_GET['check_shipping']) && $_GET['check_shipping'] == '1') {
            echo '
';
            print_r($cart);
            exit();
        }
        if (
            isset($_GET['shipping_options']) &&
            $_GET['shipping_options'] == '1'
        ) {
            echo '
';
            print_r($shipping_prices);
            exit();
        }
// For admin custom shipping quotes, make sure the selected static method remains in the v2 shipping_prices array.
         if ($cart['custom_shipping_price'] == 1 && $cart['static_shipping_price'] > 0) {
            $custom_static_code = $cart['shipping_type'];
            if (($custom_static_code == '' || $custom_static_code == 0) && $shipping_type1 != '') {
                $custom_static_code = $shipping_type1;
            }
            $custom_static_name = $shipping_name;
            if (($custom_static_name == '' || $custom_static_name == 'Shipping') && isset($cart['shipping_prices'][1]['name']) && $cart['shipping_prices'][1]['name'] != '') {
                $custom_static_name = $cart['shipping_prices'][1]['name'];
            }
            if ($custom_static_name == '' || $custom_static_name == 'Shipping') {
                $shipping_type_info = $pdo_db1->pquery("SELECT name FROM shipping_types WHERE code='" . $custom_static_code . "' LIMIT 1");
                if (isset($shipping_type_info[0]['name']) && $shipping_type_info[0]['name'] != '') {
                    $custom_static_name = $shipping_type_info[0]['name'];
                }
            }
            $cart['shipping_type'] = $custom_static_code;
            $cart['shipping_cost'] = $cart['static_shipping_price'];
            $cart['shipping_prices'][1]['code'] = $custom_static_code;
            $cart['shipping_prices'][1]['name'] = $custom_static_name;
            $cart['shipping_prices'][1]['zip'] = $zip;
            $cart['shipping_prices'][1]['price'] = $cart['static_shipping_price'];
            $cart['shipping_prices'][1]['custom_shipping_price'] = 1;
         }
//added on 20240416 #tw - issue on db 9  remove the null values from shipping_prices array 
         $cart['shipping_prices'] = is_array($cart['shipping_prices'])?array_filter($cart['shipping_prices']):array();
         if(is_array($cart['shipping_prices']) && count((array)$cart['shipping_prices'])){
            $temp_array=array();
            foreach($cart['shipping_prices'] as $k=>$v){
               if(in_array($v['code'], $temp_array)){
                 unset($cart['shipping_prices'][$k]);
               }else{
                 $temp_array[]=$v['code'];
               }
               if(($v['code']=='10') || ($v['code']=='57')){
                 $cart['shipping_prices'][$k]['price']=0;
              
               }
                if(($v['code']=='10') && ($cart['subtotal']<100)){
                    $cart['shipping_prices'][$k]['price']=10;
                }
                if(($v['code']=='57') && ($cart['subtotal']<100)){
                    $cart['shipping_prices'][$k]['price']=0;
                }
            }
            $cart['shipping_prices'] = $cart['shipping_prices'];
         }
         $this->write_cart_debug_log($cart['cart_id'],"End of function=>".json_encode($cart['shipping_prices']));
        $cart = $cart_obj->save_cart($cart);
        if(!empty($cart['website']) && $cart['website'] == 7 && $cart['website'] == '7' && empty($cart['cart_id']))
        {
            return $cart;
        }
        if($call_from == "process_cart"){
            $cart=$cart_new_v2->get_new_cart_v2($cart['cart_id'],'','','1');
        }else{
            $cart = $cart_obj->get_new_cart_v2($cart['cart_id'],'','','1');
        }
        return $cart;
    }


    /******* Function to return allow pickup from product_types table ***/
    function to_return_allow_pickup($product_type)
    {
        global $pdo_db1;
        $allow_pickup = '';
        if ($product_type != '') {
            $allow_pickup_results = $pdo_db1->pquery(
                "SELECT allow_pickup FROM product_types WHERE  id='" .
                    $product_type .
                    "'"
            );
            $row_alp = $allow_pickup_results[0];
            $allow_pickup = $row_alp['allow_pickup'];
        }

        return $allow_pickup;
    }
    function generate_google_api_log($cart_id, $string, $type = '')
    {
        global $pdo_db1;
        $p = new products();
        $status = $p->specific_select('system_log_files', 'id', 3, 'status');
        if ($status == 1 && (is_int($cart_id) && $cart_id > 0)) {
            $log_file_name =
                '/data/vhosts/arttoframe.com/http/logs/google_map_api/google_api_' .
                $cart_id .
                '.txt';

            $myfile = fopen($log_file_name, 'a+');
            $textToWrite = '';
            $textToWrite .= $string . " \r\n
"; $textToWrite .= date('Y-m-d H:i:s') . ' || ZIP ID# ' . $cart_id . ' || REF URL : ' . $_SERVER['HTTP_REFERER'] . "\r\n
"; $textToWrite .= "***************************************************************************************************\r\n
"; fwrite($myfile, $textToWrite); fclose($myfile); } } function calculate_extra_shipping_cost($zip, $cart = '') { global $pdo_db1; $added_cost = 0; $zip_details_state = ''; $zip_details_country = ''; $data = $this->getZipDetailsFromGoogleAPI($zip, $cart); $cost_details = []; if ($data['status'] == 'success') { foreach ($data['zip_data'] as $key => $value) { if ($key == 1) { $zip_details = $value; break; } } if (trim($zip_details['country']) == 'CA') { $added_cost = 50; $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'CA'; } elseif ( $zip_details['state'] == 'AK' || $zip_details['state'] == 'HI' ) { $added_cost = $this->validateStateForShipping( $zip_details['state'] ); $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'US'; } } else { if (strlen($zip) == 6) { $strzip1 = substr($zip, 0, 3); $strzip2 = substr($zip, 3, 3); $zipn = $strzip1 . ' ' . $strzip2; $data = $this->getZipDetailsFromGoogleAPI($zipn, $cart); if ($data['status'] == 'success') { foreach ($data['zip_data'] as $key => $value) { if ($key == 1) { $zip_details = $value; break; } } if (trim($zip_details['country']) == 'CA') { $added_cost = 50; $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'CA'; } elseif ( $zip_details['state'] == 'AK' || $zip_details['state'] == 'HI' ) { $added_cost = $this->validateStateForShipping( $zip_details['state'] ); $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'US'; } } else { $cart_obj = new new_cart_v2(); $cart = $cart_obj->get_new_cart_v2('','','','1'); if ($zip != '') { $searchKeyword = " zip like '%" . str_replace(' ', '', $zip) . "%' or zip like '%" . $zip . "%' "; $query_get_res_sql = $pdo_db1->pquery( 'SELECT zip, country FROM cities_extended where ' . $searchKeyword . ' ' ); $query_get_res = $query_get_res_sql[0]; $zipcountry = $query_get_res['country']; if ($zipcountry != '') { $cart['ship_country'] = $zipcountry; $cart_obj->save_cart($cart); $_SESSION['cart'] = $cart; $cart = $cart_obj->get_new_cart_v2('','','','1'); } if ( trim($zipcountry) == 'CA' || trim($zipcountry) == 'canada' || trim($zipcountry) == 'Canada' ) { $added_cost = 50; $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'CA'; } } } } else { $strzip1 = substr($zip, 0, 3); $zipn = $strzip1; $data = $this->getZipDetailsFromGoogleAPI($zipn, $cart); if ($data['status'] == 'success') { foreach ($data['zip_data'] as $key => $value) { if ($key == 1) { $zip_details = $value; break; } } if (trim($zip_details['country']) == 'CA') { $added_cost = 50; $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'CA'; } elseif ( $zip_details['state'] == 'AK' || $zip_details['state'] == 'HI' ) { $added_cost = $this->validateStateForShipping( $zip_details['state'] ); $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'US'; } } else { $cart_obj = new new_cart_v2(); $cart = $cart_obj->get_new_cart_v2('','','','1'); if ($zip != '') { $searchKeyword = " zip like '%" . str_replace(' ', '', $zip) . "%' or zip like '%" . $zip . "%' "; $query_get_res_sql = $pdo_db1->pquery( 'SELECT zip, country FROM cities_extended where ' . $searchKeyword . ' ' ); $query_get_res = $query_get_res_sql[0]; $zipcountry = $query_get_res['country']; if ($zipcountry != '') { $cart['ship_country'] = $zipcountry; $cart_obj->save_cart($cart); $_SESSION['cart'] = $cart; $cart = $cart_obj->get_new_cart_v2('','','','1'); } if ( trim($zipcountry) == 'CA' || trim($zipcountry) == 'canada' || trim($zipcountry) == 'Canada' ) { $added_cost = 50; $cost_details['added_cost'] = $added_cost; $cost_details['country'] = 'CA'; } } } } } return $cost_details; } /*function getZipDetailsFromGoogleAPI($zip_code,$cart='') { $this->generate_google_api_log($cart['cart_id'],"CALLING GOOGLE API"); $zip_code = str_replace(' ','%20',$zip_code); //$zip_code = 'K1A%200C1'; $google_maps_api = "https://maps.googleapis.com/maps/api/geocode/json?address=".$zip_code."&sensor=true&key=AIzaSyB_U7nhfvFHV3SkeuShtMfcCKj61rGiH3g"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $google_maps_api); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ch, CURLOPT_TIMEOUT, 560);; $result = curl_exec($ch); curl_close($ch) ; $zip_code = str_replace('%20',' ',$zip_code); $result_arr = json_decode($result, True); //echo "
";print_r($result_arr);exit;
            $result_array = $result_arr['results'];
            $address_details = array();
            $response = array();
            $flag = false;
            $counterAddress = 0;
            //echo "
";print_r($result_arr['status']);exit;
            if($result_arr['status']=='OK')
            {
                
                $this->generate_google_api_log($cart['cart_id'],"GOOGLE RESPONSE SUCCESS");
                foreach($result_array as $key => $value)
                {
                    $address_arr = $value['address_components'];
                    if(isset($value['postcode_localities']) && $value['postcode_localities']!='')
                    {
                        $flag = true;
                        $postcode_localities = $value['postcode_localities'];
                        //echo "
";print_r($address_arr);
                        $counterLocality = 0;
                        foreach($postcode_localities as $localities_key => $localities_value)
                        {
                            if($localities_value)
                            {
                                $response['city']                   = $localities_value;
                                $response['city_long_name'] = $localities_value;
                            }       
                            
                            foreach($address_arr as $add_key => $add_value)
                            {
                                if($add_value['types'][0] == 'postal_code')
                                {
                                    $response['zip']                     = $add_value['short_name'];
                                    $response['zip_long_name'] = $add_value['long_name'];
                                }
                                if($add_value['types'][0] == 'street_number')
                                {
                                    $response['street_number']                   = $add_value['short_name'];
                                    $response['street_number_long_name'] = $add_value['long_name'];
                                }
                                if($add_value['types'][0] == 'route')
                                {
                                    $response['route']                   = $add_value['short_name'];
                                    $response['route_long_name'] = $add_value['long_name'];
                                }
                                if($add_value['types'][0] == 'administrative_area_level_1')
                                {
                                    $response['state']                   = $add_value['short_name'];
                                    $response['state_long_name'] = $add_value['long_name'];
                                }
                                if($add_value['types'][0] == 'country')
                                {
                                    $response['country']            = $add_value['short_name'];
                                    $response['country_long'] = $add_value['long_name'];
                                    //$response['city'][] = $add_value['long_name'];
                                    //$response['city_long_name'][] = $add_value['long_name'];
                                }
                            }
                            $counterLocality++;
                            //echo "
";print_r($response);
                            if($response['country']=='US' or $response['country'] =='CA')
                            {
                                $address_details['status'] = 'success';
                                $address_details['message'] = ($counterLocality).' records found.';
                                $address_details['zip_data'][$counterLocality] = $response;
                            }else
                            {
                                $address_details['status'] = 'outofUSA';
                                $address_details['message'] ='Sorry, we do not ship to '.$response['country_long'].'.';
                            }
                        }                                   
                    }else
                    {
                        //echo "
";print_r($address_arr);
                        foreach($address_arr as $add_key => $add_value)
                        {
                            if($add_value['types'][0] == 'postal_code')
                            {
                                $response['zip']                     = $add_value['short_name'];
                                $response['zip_long_name'] = $add_value['long_name'];
                            }
                            if($add_value['types'][0] == 'street_number')
                            {
                                $response['street_number']                   = $add_value['short_name'];
                                $response['street_number_long_name'] = $add_value['long_name'];
                            }
                            if($add_value['types'][0] == 'route')
                            {
                                $response['route']                   = $add_value['short_name'];
                                $response['route_long_name'] = $add_value['long_name'];
                            }
                            //echo $add_value['types'][0]."
"; if($add_value['types'][0] == 'locality') { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; }elseif($add_value['types'][0] == 'neighborhood') { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; }elseif($add_value['types'][0] == 'administrative_area_level_3') { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; }else { if($add_value['types'][1] == 'sublocality') { $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; } } if($add_value['types'][0] == 'administrative_area_level_1') { $response['state'] = $add_value['short_name']; $response['state_long_name'] = $add_value['long_name']; } if($add_value['types'][0] == 'country') { $response['country'] = $add_value['short_name']; $response['country_long'] = $add_value['long_name']; } } $counterAddress++; if($response['country']=='US' or $response['country'] =='CA') { $address_details['status'] = 'success'; $address_details['message'] = ($counterAddress).' records found.'; $address_details['zip_data'][$counterAddress] = $response; }else { $address_details['status'] = 'outofUSA'; $address_details['message'] ='Sorry, we do not ship to '.$response['country_long'].'.'; } } } }else { $address_details['status'] = 'failed'; $address_details['message'] ='Invalid Zip code.'; } //echo "
";print_r($cities_array);
            //echo "
";print_r($address_details);exit;
            return $address_details;
    }*/

    function getZipDetailsFromGoogleAPI($zip, $cart = '')
    {
        /**
         * https://arttoframes.teamwork.com/app/tasks/31571836
         * GoogleMapApi has been disabled from google panel  - Date: 03Apr2023
         * GoogleMapApi code has been commented cause of showing very high number of requests and billing cost trends in between from 23 March 2023 to till now 03 Apr 2023 - Date: 03Apr2023
         */
        global $pdo_db1;
        if(!empty($cart['cart_id'])){
             $this->generate_google_api_log($cart['cart_id'], 'CALLING GOOGLE API');
        }
        $zip = str_replace(' ', '%20', $zip);
        $google_maps_api =
            'https://maps.googleapis.com/maps/api/geocode/json?address=' .
            $zip .
            '&sensor=true&key=AIzaSyB_U7nhfvFHV3SkeuShtMfcCKj61rGiH3g';
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $google_maps_api);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_TIMEOUT, 560);

        $result = curl_exec($ch);
        curl_close($ch);

        $json = json_decode($result, true);
        //echo "
"; print_r($json); die;
        $city = '';
        $state = '';
        $country = '';
        $response = [];
        $address_details = [];
        $formataddress = '';

        $k = 0;

        if (count($json['results']) > 0) {
            //break up the components
            if ($json['status'] == 'OK') {
                $this->generate_google_api_log(
                    $cart['cart_id'],
                    'GOOGLE RESPONSE SUCCESS'
                );
                for ($m = 0; $m < count($json['results']); $m++) {
                    if ($json['status'] == 'OK') {
                        $arrformattedaddress =
                            $json['results'][0]['formatted_address'];

                        if ($arrformattedaddress != '') {
                            $formataddress = $arrformattedaddress;
                        }

                        $arrformattedaddress_ex = explode(',', $formataddress);
                        if (count($arrformattedaddress_ex) > 1) {
                            $city =
                                $arrformattedaddress_ex[count($arrformattedaddress_ex) - 3];
                            $statezip =
                                $arrformattedaddress_ex[count($arrformattedaddress_ex) - 2];
                            $country =
                                $arrformattedaddress_ex[count($arrformattedaddress_ex) - 1];
                            $stateex = explode(' ', trim($statezip));
                            // echo "
";     print_r($stateex); die;
                            $state = $stateex[0];
                            $zipcoded = $stateex[1] . ' ' . $stateex[2];
                            $this->generate_google_api_log(
                                $cart['cart_id'],
                                'GOOGLE RESPONSE SUCCESS'
                            );
                            if ($city != '') {
                                $response['city'] = $city;
                                $response['city_long_name'] = $city;
                            }
                            if ($state != '') {
                                $response['state'] = $state;
                                $response['state_long_name'] = $state;
                            }
                            if ($country != '') {
                                if (trim($country) == 'USA') {
                                    $country = 'US';
                                }
                                if (trim($country) == 'Canada') {
                                    $country = 'CA';
                                }

                                $response['country'] = $country;
                                $response['country_long'] = $country;
                            }
                            if ($country != '') {
                                $response['zip'] = $zipcoded;
                                $response['zip_long_name'] = $zipcoded;
                            }

                            if (
                                $country == 'US' ||
                                $country == 'CA' ||
                                trim($country) == 'USA' ||
                                trim($country) == 'Canada'
                            ) {
                                $cnt = count($json['results']);
                                $address_details['status'] = 'success';
                                $address_details['message'] =
                                    $cnt . ' records found.';
                                $address_details['zip_data'][1] = $response;
                            } else {
                                $address_details['status'] = 'outofUSA';
                                $address_details['message'] =
                                    'Sorry, we do not ship to ' .
                                    $country .
                                    '.';
                            }
                        } elseif ($formataddress == '') {
                            $address_arr =
                                $json['results'][$m]['address_components'];
                            if (
                                isset(
                                    $json['results'][$m]['postcode_localities']
                                ) &&
                                $json['results'][$m]['postcode_localities'] !=
                                ''
                            ) {
                                $flag = true;
                                $postcode_localities =
                                    $json['results'][$m]['postcode_localities'];
                                //echo "
";print_r($address_arr);
                                $counterLocality = 0;
                                foreach ($postcode_localities
                                    as $localities_key => $localities_value) {
                                    if ($localities_value) {
                                        $response['city'] = $localities_value;
                                        $response['city_long_name'] = $localities_value;
                                    }

                                    foreach ($address_arr
                                        as $add_key => $add_value) {
                                        if (
                                            $add_value['types'][0] ==
                                            'postal_code'
                                        ) {
                                            $response['zip'] =
                                                $add_value['short_name'];
                                            $response['zip_long_name'] =
                                                $add_value['long_name'];
                                        }
                                        if (
                                            $add_value['types'][0] ==
                                            'street_number'
                                        ) {
                                            $response['street_number'] =
                                                $add_value['short_name'];
                                            $response['street_number_long_name'] = $add_value['long_name'];
                                        }
                                        if ($add_value['types'][0] == 'route') {
                                            $response['route'] =
                                                $add_value['short_name'];
                                            $response['route_long_name'] =
                                                $add_value['long_name'];
                                        }
                                        if (
                                            $add_value['types'][0] ==
                                            'administrative_area_level_1'
                                        ) {
                                            $response['state'] =
                                                $add_value['short_name'];
                                            $response['state_long_name'] =
                                                $add_value['long_name'];
                                        }
                                        if (
                                            $add_value['types'][0] == 'country'
                                        ) {
                                            $response['country'] =
                                                $add_value['short_name'];
                                            $response['country_long'] =
                                                $add_value['long_name'];
                                            //$response['city'][] = $add_value['long_name'];
                                            //$response['city_long_name'][] = $add_value['long_name'];
                                        }
                                    }
                                    $counterLocality++;
                                    //echo "
";print_r($response);
                                    if (
                                        $response['country'] == 'US' or
                                        $response['country'] == 'CA'
                                    ) {
                                        $address_details['status'] = 'success';
                                        $address_details['message'] =
                                            $counterLocality .
                                            ' records found.';
                                        $address_details['zip_data'][$counterLocality] = $response;
                                    } else {
                                        $address_details['status'] = 'outofUSA';
                                        $address_details['message'] =
                                            'Sorry, we do not ship to ' .
                                            $response['country_long'] .
                                            '.';
                                    }
                                }
                            } else {
                                //echo "
";print_r($address_arr);
                                foreach ($address_arr
                                    as $add_key => $add_value) {
                                    if (
                                        $add_value['types'][0] == 'postal_code'
                                    ) {
                                        $response['zip'] =
                                            $add_value['short_name'];
                                        $response['zip_long_name'] =
                                            $add_value['long_name'];
                                    }
                                    if (
                                        $add_value['types'][0] ==
                                        'street_number'
                                    ) {
                                        $response['street_number'] =
                                            $add_value['short_name'];
                                        $response['street_number_long_name'] =
                                            $add_value['long_name'];
                                    }
                                    if ($add_value['types'][0] == 'route') {
                                        $response['route'] =
                                            $add_value['short_name'];
                                        $response['route_long_name'] =
                                            $add_value['long_name'];
                                    }
                                    //echo $add_value['types'][0]."
"; if ($add_value['types'][0] == 'locality') { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; } elseif ( $add_value['types'][0] == 'neighborhood' ) { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; } elseif ( $add_value['types'][0] == 'administrative_area_level_3' ) { //$response['city'] = $add_value['long_name']; //$response['city_long_name'] = $add_value['long_name']; $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; } else { if ( $add_value['types'][1] == 'sublocality' ) { $response['city'][] = $add_value['long_name']; $response['city_long_name'][] = $add_value['long_name']; } } if ( $add_value['types'][0] == 'administrative_area_level_1' ) { $response['state'] = $add_value['short_name']; $response['state_long_name'] = $add_value['long_name']; } if ($add_value['types'][0] == 'country') { $response['country'] = $add_value['short_name']; $response['country_long'] = $add_value['long_name']; } } $counterAddress++; if ( $response['country'] == 'US' or $response['country'] == 'CA' ) { $address_details['status'] = 'success'; $address_details['message'] = $counterAddress . ' records found.'; $address_details['zip_data'][$counterAddress] = $response; } else { $address_details['status'] = 'outofUSA'; $address_details['message'] = 'Sorry, we do not ship to ' . $response['country_long'] . '.'; } } } } } } else { $address_details['status'] = 'failed'; $address_details['message'] = 'Invalid Zip code.'; } } // $address_details['status'] = 'failed'; // $address_details['message'] ='Invalid Zip code.'; return $address_details; } function validateStateForShipping($ship_state) { global $pdo_db1; //$statePriceResult = $pdo_db1->pquery("SELECT * FROM us_states WHERE ( state_code = '".$ship_state."' OR state_code = '".$ship_state."' ) AND message != '' LIMIT 1 ");//old query $statePriceResult = $pdo_db1->pquery( "SELECT * FROM us_states WHERE ( state_code = '" . $ship_state . "' OR state_code = '" . $ship_state . "' ) LIMIT 1 " ); // new query added on 20190808 if ($pdo_db1->pdo_num_rows($statePriceResult)) { //Add price into the shipping cost for extra on remote states $statePriceRow = $statePriceResult[0]; $added_cost = $statePriceRow['added_cost']; } else { $added_cost = 0; } return $added_cost; } function calculate_shipping_static_new( $cart, $static_price = '', $shipping_type1 = '1' ) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $total_items = 0; $over_size_arr = []; $x = 1; $zip = $cart['ship_zip']; $order_items = $cart['order_items']; $bigest_width = 0; $bigest_height = 0; $over_size_items_total = 0; $regular_size_items_total = 0; $long_box_size_items_total = 0; $we_have_a_big_item = 'no'; $item_ctr = 0; $offer_ctr = 0; // 6 nov 2023 check array if (is_array($order_items) && count($order_items) == 0) { } else { $cart['disallow_coupon'] = null; foreach ($order_items as $key => $value) { $total_items = $total_items + $value['order_item_details_new'][0]['qty']; $this_width = $value['width']; $this_height = $value['height']; if ( isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3 ) { // echo $this_height . ' - ' . $this_width . '
' ; // exit; } //set w/h to big/small if ($this_width < $this_height) { $temp_info = $this_width; $this_width = $this_height; $this_height = $temp_info; } $test = 0; if ( $value['order_item_details_new'][0]['product_type'] == 57 && $value['order_item_details_new'][0]['hardware_id'] == '' && $value['order_item_details_new'][0]['backing_id'] == '' ) { $value['order_item_details_new'][0]['product_type'] = 69; } if ( isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3 ) { // echo $this_height . ' - ' . $this_width . '
' ; // exit; } if ( $value['order_item_details_new'][0]['product_type'] == 43 && strpos( $value['order_item_details_new'][0]['mat_id'], 'custom' ) !== false ) { $vvv = 1; $framewidthq_sql = $pdo_db1->pquery( 'SELECT * FROM new_frames WHERE code="' . $value['order_item_details_new'][0]['frame_id'] . '"' ); $framewidthq = $framewidthq_sql[0]; $this_width = $value['width'] + ($framewidthq['width'] - $framewidthq['lip_width']) * 2; $this_height = $value['height'] + ($framewidthq['width'] - $framewidthq['lip_width']) * 2; } if ($this_height < 29.5 && $this_width < 41.5) { $regular_size_items_total = $regular_size_items_total + $value['order_item_details_new'][0]['qty']; } else { if ($this_height < 16.5 && $this_width < 58.5) { $long_box_size_items_total = $long_box_size_items_total + $value['order_item_details_new'][0]['qty']; } elseif ( $value['item_sub_type'] == 'cluster' || $value['item_sub_type'] == 'split' ) { $test = 1; $regular_size_items_total = $regular_size_items_total + $value['order_item_details_new'][0]['qty']; } else { //$we_have_a_big_item = 'yes'; //$over_size_items_total = $over_size_items_total + $value["order_item_details_new"][0]["qty"]; } } /* //find bigest width if($this_width > $bigest_width){ $bigest_width = $this_width ; } //find bigest small if($this_height > $bigest_height){ $bigest_height = $this_height ; } */ /* if($bigest_width > 29.5 or $bigest_height > 41.5 ){ if($_SESSION['permissions']== 3){ //print_r($over_size_arr); } $over_size_arr = $this->over_size_check($value["order_item_details"][0]['fld1'],$value["order_item_details"][0]['fld9'],$value["qty"],$over_size_arr); if($_SESSION['permissions'] == 3){ //print_r($over_size_arr); } if($over_size_arr['this_item_found'] == 'yes'){ //reset bigest value $bigest_width = 0; $bigest_height = 0; $we_have_a_big_item = 'yes' ; }else{ $over_size_items_total++; $we_have_a_big_item = 'yes' ; } }else{ $regular_size_items_total = $regular_size_items_total + $value["qty"]; } */ // offer related changes - Solace $offer_ctr += $value['offer_apply']; $item_ctr++; } } if (isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3) { //echo ' regular_size_items_total - ' . $regular_size_items_total . ' - long_box_size_items_total - ' . $long_box_size_items_total. ' - we_have_a_big_item - ' . $we_have_a_big_item . '
' ; // exit; } if ($static_price != '' or $cart['static_shipping_price'] != '') { $cart['disallow_coupon'] = 'yes'; if ($static_price != '') { $this_shipping_price = $static_price; } elseif ($cart['static_shipping_price'] != '') { $this_shipping_price = $cart['static_shipping_price']; } $shipping_prices = []; $shipping_method = []; $shipping_method['code'] = '1'; $shipping_method['name'] = 'Shipping'; $shipping_method['zip'] = $zip; $shipping_method['price'] = $this_shipping_price; $shipping_prices['1'] = $shipping_method; } else { if ($we_have_a_big_item == 'yes') { //over_size if ($over_size_items_total > 0) { //items_over_size not found in datebase $shipping_prices = []; $shipping_method = []; $shipping_method['code'] = '1'; $shipping_method['name'] = 'Size to big.'; $shipping_method['zip'] = $zip; $shipping_method['error'] = 'Size to big.'; $shipping_method['price'] = 0; $shipping_prices['1'] = $shipping_method; } else { //items_over_size FOUND in datebase $shipping_prices = []; $shipping_method = []; $shipping_method['code'] = '1'; $shipping_method['name'] = 'UPS Ground'; $shipping_method['zip'] = $zip; $shipping_method['price'] = $this->over_size_item_shipping($over_size_arr) + $this->regular_size_item_shipping( $regular_size_items_total ); $shipping_prices['1'] = $shipping_method; } if ( isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3 ) { //print_r($over_size_arr); //print_r($this->over_size_item_shipping( $over_size_arr )); //echo '-'; //print_r($this->regular_size_item_shipping($regular_size_items_total)); //exit; } } else { //regular_size $shipping_infos = $pdo_db1->pquery( " SELECT * FROM shipping_types WHERE in_use = '1' ORDER BY shipping_types.sorting_order ASC ", 'FETCH_BOTH' ); foreach ($shipping_infos as $shipping_info) { $shipping_method = []; $shipping_method['code'] = $shipping_info['code']; $shipping_method['name'] = $shipping_info['name']; $shipping_method['zip'] = $zip; if ($regular_size_items_total > 0) { $regular_size_items_price = $shipping_info['base_price'] + $shipping_info['price_per_item'] * $regular_size_items_total; } if ($long_box_size_items_total > 0) { $long_box_items_price = $shipping_info['long_box_base_price'] + $shipping_info['long_box_per_item'] * $long_box_size_items_total; } if ( isset($_SESSION['permissions']) && $_SESSION['permissions'] == 3 ) { //echo $shipping_info['name'] . ' - ' . $regular_size_items_price . ' - ' .$long_box_items_price ; //exit; } //offer related changes - Solace if ($item_ctr == $offer_ctr && $x == 1) { $shipping_method['price'] = 0; } else { $shipping_method['price'] = $regular_size_items_price + $long_box_items_price; } $shipping_prices[$x] = $shipping_method; $x++; } } //end if bigest } //end $static_price $cart['shipping_cost'] = $shipping_prices['1']['price']; foreach ($shipping_prices as $key => $ship_price) { if ($cart['shipping_type'] == $ship_price['code']) { $cart['shipping_cost'] = $ship_price['price']; } // $shipping_prices[$key]["price"] = number_format($shipping_rate, 2); } $cart['static_shipping_price'] = $static_price; $cart['shipping_prices'] = $shipping_prices; /*$cart["test"]=$test;*/ return $cart; } //with ups function calculate_shipping( $cart, $shipping_type1 = '0', $force_change = false, $callGoogleAPI = '', $call_from = '', $skip_internal_cart_totals = false ) { $cart_obj = new new_cart_v2(); $cart = $cart_obj->get_new_cart_v2($cart['cart_id'],'','','1'); global $pdo_db1; $reuven = '1'; if ($reuven == '1') { $cart = $this->calculate_shipping_static( $cart, '', '', '', $callGoogleAPI, $call_from = '', $skip_internal_cart_totals ); return $cart; } // shipping types; /* 1 = ground * 2 = 3 day select * */ $zip = $cart['ship_zip']; if (is_array($shipping_type1)) { $shipping_prices = $shipping_type1; } elseif ($shipping_type1 == '0') { $shipping_prices = []; $shipping_method = []; $shipping_method['code'] = '1'; $shipping_method['name'] = 'UPS Ground'; $shipping_method['zip'] = $zip; $shipping_prices['1'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '2'; $shipping_method['name'] = 'UPS 3 Day select'; $shipping_method['zip'] = $zip; $shipping_prices['2'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '7'; $shipping_method['name'] = 'UPS 2nd day Air'; $shipping_method['zip'] = $zip; $shipping_prices['7'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '6'; $shipping_method['name'] = 'UPS 2nd day Air AM'; $shipping_method['zip'] = $zip; $shipping_prices['6'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '5'; $shipping_method['name'] = 'UPS 2nd day Air Saver'; $shipping_method['zip'] = $zip; $shipping_prices['5'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '4'; $shipping_method['name'] = 'UPS Next day Air'; $shipping_method['zip'] = $zip; $shipping_prices['4'] = $shipping_method; $shipping_method = []; $shipping_method['code'] = '3'; $shipping_method['name'] = 'UPS Next day Air AM'; $shipping_method['zip'] = $zip; $shipping_prices['3'] = $shipping_method; } else { $shipping_type_info = $this->get_shipping_type_info( $shipping_type1 ); $shipping_prices = []; $shipping_method = []; $shipping_method['code'] = $shipping_type1; $shipping_method['name'] = $shipping_type_info['name']; $shipping_method['zip'] = $zip; $shipping_prices[$shipping_type1] = $shipping_method; } $cart_obj = new cart(); $item_sizes = $cart_obj->get_cart_item_sizes($cart); //print_r($item_sizes); $sizes = $item_sizes['sizes']; //echo "sizes array:"; //print_r($sizes); foreach ($shipping_prices as $key => $ship_price) { $shipping_type = $ship_price['code']; $shipping_zip = $ship_price['zip']; $boxes = $this->calculate_boxes($sizes, $shipping_type); $boxes = $this->calculate_dimensional_weight( $boxes, $shipping_type ); //print_r($boxes); $problems = $this->check_for_problems($boxes, $shipping_type); if ($problems) { echo 'we have a problem'; // deal with problem here } $boxes = $this->calculate_large_package($boxes, $shipping_type); //print_r($boxes); $boxes = $this->calculate_handling_charges($boxes, $shipping_type); //echo "boxes array with dimensional widths large + handling charges:"; //print_r($boxes); $billing_type = $this->determine_billing_method( $boxes, $shipping_type ); //echo "total billable weight = " . $this->get_total_billable_weight($boxes); //echo "billing type = " . $billing_type; //$shipping_rate = $this->get_shipping_rate($boxes, $origin_zip="11232", $shipping_zip, $shipping_type, $billing_type); $shipping_rate = $this->get_shipping_rate( $boxes, $origin_zip = '11232', $shipping_zip, $shipping_type, $billing_type ); if ($shipping_rate == false) { $this->verbose .= '
cannot calculate shipping for this item'; //$shipping_prices[$key]["price"] = $shipping_rate; $shipping_prices[$key]['error'] = 'Cannot use this method to ship to this Zip Code.'; } else { $shipping_rate = $this->calculate_gas_surcharge( $shipping_rate, $shipping_type ); $shipping_prices[$key]['price'] = number_format( $shipping_rate, 2 ); if ($force_change) { if ($shipping_type1 == $shipping_type) { $cart['shipping_type'] = $shipping_type; $cart['shipping_cost'] = $shipping_prices[$key]['price']; } } else { if (isset($cart['shipping_type'])) { if ($cart['shipping_type'] == $shipping_type) { $cart['shipping_type'] = $shipping_type; $cart['shipping_cost'] = $shipping_prices[$key]['price']; } } else { if ($shipping_type1 == '0' && $shipping_type == '1') { $cart['shipping_type'] = $shipping_type; $cart['shipping_cost'] = $shipping_prices[$key]['price']; } else { $cart['shipping_type'] = $shipping_type; $cart['shipping_cost'] = $shipping_prices[$key]['price']; } } } } $this->verbose .= "
Final Shipping price is $shipping_rate"; } $cart['shipping_prices'] = $shipping_prices; return $cart; } function get_shipping_type_info($shipping_type) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $res = $pdo_db1->pquery( "SELECT * FROM shipping_types WHERE code = '" . $shipping_type . "' ", 'FETCH_BOTH' ); //$u = new utils; $rec = $res[0]; return $rec; } function calculate_boxes($sizes, $shipping_type = '1') { // TODO: calculate Boxes global $pdo_db1; $this->verbose .= '
calculating boxes'; foreach ($sizes as $key => $size) { $sizes[$key]['price'] = 0.0; $sizes[$key][0] = ((int) $size[0]) + 4; $sizes[$key][1] = ((int) $size[1]) + 4; $sizes[$key][2] = ((int) $size[2]) + 2; } return $sizes; } function check_for_problems($sizes, $shipping_type = '1') { // TODO: calculate Boxes $problem = false; foreach ($sizes as $key => $size) { $sizes[$key]['problems'] = false; } return false; } // these are function specifc for UPS calculateions // eventually we will have this in a plug-in like architecture // TODO: plug in architectures for shipping function calculate_dimensional_weight($boxes, $shipping_type = '1') { global $pdo_db1; $this->verbose .= '
calculating dimensional weight for each box'; foreach ($boxes as $key => $box) { $l = $box[0]; $w = $box[1]; $d = $box[2]; $this->verbose .= "
length $l width $w height $d"; $cubic_size = $l * $w * $d; // TODO: This depends on GROUND or AIR / need to pull this from database, not hard code if ($shipping_type == '1' || $shipping_type == '2') { if ($cubic_size > 5184) { $dimensional_weight = $cubic_size / 194; } else { $dimensional_weight = '15'; } $boxes[$key]['dimensional_weight'] = $dimensional_weight; } else { $dimensional_weight = $cubic_size / 194; //echo $dimensional_weight; if ($dimensional_weight < 15) { $dimensional_weight = '15'; } $boxes[$key]['dimensional_weight'] = $dimensional_weight; } } return $boxes; } function calculate_large_package($boxes, $shipping_type = '1') { global $pdo_db1; $this->verbose .= '
calculating large packages'; foreach ($boxes as $key => $box) { $is_large = $this->is_large_package($box); if ($is_large) { $this->verbose .= '
we have a large package'; if ($box['dimensional_weight'] < 90) { $boxes[$key]['dimensional_weight'] = 90; } $boxes[$key]['price'] = $boxes[$key]['price'] + 40; $boxes[$key]['large_package'] = true; } else { $boxes[$key]['large_package'] = false; $boxes[$key]['price'] = $boxes[$key]['price'] + 0; } } return $boxes; } function is_large_package($box) { $l = $box[0]; $w = $box[1]; $d = $box[2]; $girth = $w * 2 + $d * 2; $total_size = $l + $girth; if ($total_size > 130 && $total_size < 165) { return true; } else { return false; } } function write_cart_debug_log($cart_id, $log_str = '') { return true; if(strlen(trim($log_str)) > 0 && is_numeric($cart_id) && $cart_id > 0) { $log_file_name = "/data/vhosts/arttoframe.com/http/logs/cart_logs/cart_logs_".$cart_id.".txt"; $myfile = fopen($log_file_name, "a+"); $textToWrite = ""; $textToWrite = date("Y-m-d H:i:s") ." || cart_id# ". $cart_id ." || Log String :".$log_str." || , REF URL : ". $_SERVER["HTTP_REFERER"] ."\r\n "; // $textToWrite .= " Back Trace Details : ".debug_backtrace().'*'.$_SERVER['HTTP_USER_AGENT']; $textToWrite .= "====================================\r\n"; fwrite($myfile, $textToWrite); fclose($myfile); } } function calculate_handling_charges($boxes, $shipping_type = '1') { $this->verbose .= '
calculating handling charges'; foreach ($boxes as $key => $box) { $l = $box[0]; $w = $box[1]; $d = $box[2]; if (($l > 60 || $w > 60) && !$box['large_package']) { $boxes[$key]['price'] = $boxes[$key]['price'] + 6; } } return $boxes; } // this function determines which billing method we should use. Standart or Hundredweight function determine_billing_method($boxes, $shipping_type = '1') { global $pdo_db1; $this->verbose .= '
determining billing method'; $box_amount = count($boxes); // first determine amount of boxes. Hundredweight only works on mutliple boxes if ($box_amount == 1) { $this->verbose .= '
we only 1 box so its standard'; return 1; } elseif ($box_amount > 1) { $this->verbose .= '
we have more than 1 box'; // determine if the total billable weight passes for hundredweight billing service $total_billable_weight = $this->get_total_billable_weight($boxes); $this->verbose .= "
total billable weight is $total_billable_weight"; $hundred_weight_minimum = $this->get_hundred_weight_minimum( $shipping_type ); if ( $hundred_weight_minimum === false || $hundred_weight_minimum == '' ) { return 1; } $this->verbose .= "
hundred wheight minimum is $hundred_weight_minimum"; if ($total_billable_weight >= $hundred_weight_minimum) { $this->verbose .= '
Billing Method is Hundredweight'; return 2; } else { $this->verbose .= '
Billing Method is Standard'; return 1; } } } // this returen the minimum weight for hundred weight service to apply the a particular shipping type function get_hundred_weight_minimum($shipping_type, $billing_type = '2') { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $q = "SELECT MIN(starting_weight) FROM ups_shipping_rates WHERE shipping_type='" . $pdo_db1->pdo_real_escape_string($shipping_type) . "' AND billing_type = '" . $pdo_db1->pdo_real_escape_string($billing_type) . "'"; $res = $pdo_db1->pquery($q, 'FETCH_BOTH'); //$u = new utils; $rec = $res[0]; //print_r($rec); if ($rec === false) { return false; } else { return $rec[0]; } } // givin a shipping type this function will return how much it would cost ship all the boxes in the $boxes array function get_shipping_rate( $boxes, $origin_zip = '11232', $zip, $shipping_type, $billing_type, $force_standard = false, $residence = true ) { global $pdo_db1; $this->verbose .= "
calulatin shipping rate for $zip originating From $origin_zip"; $zone = $this->get_zone( $zip, $origin_zip, $shipping_type, $billing_type ); $this->verbose .= "
shipping zone is=$zone, Shipping type= $shipping_type and billing type=$billing_type"; //echo "zone = " . $zone; //echo "billing = " . $billing_type; if ($zone == false || $zone == '0') { return false; } if ($billing_type == '1') { $this->verbose .= '
getting standard billing rate'; $rate = $this->get_standard_rate( $boxes, $zone, $shipping_type, $billing_type ); if ($residence) { $box_amount = count($boxes); $this->verbose .= '
calculating price for shipping to residence'; $rate = $rate + $box_amount * 1.85; } $this->verbose .= "
Price for stadard rate is $rate"; return $rate; } elseif ($billing_type == '2') { $this->verbose .= '
getting hundredweight rate'; $rate = $this->get_hundredweight_rate( $boxes, $zone, $shipping_type, $billing_type ); if ($residence) { $this->verbose .= '
calculating price for shipping to residence'; $rate = $rate + 20; } $this->verbose .= "
Price for Hundred weight is $rate"; return $rate; } } function get_standard_rate($boxes, $zone, $shipping_type) { global $pdo_db1; $this->verbose .= '
calculating standard shiprates'; $total = 0; foreach ($boxes as $key => $box) { if (isset($box['price'])) { $total = (int) $total + (int) $box['price']; } $rate_rec = $this->get_rate_record( $box['dimensional_weight'], $shipping_type, '1' ); //print_r($rec); $zone_map = $this->get_zone_map($shipping_type, '1'); if ($zone_map === false) { return false; } $rate = $rate_rec[$zone_map[$zone]]; if ($box['dimensional_weight'] > 151) { $rate2 = $box['dimensional_weight'] * $rate; $this->verbose .= '
calculating price for weight of ' . $box['dimensional_weight'] . " $rate2"; $total = $total + $rate2; $this->verbose .= "
total is now $total"; } else { $this->verbose .= '
calculating price for weight of ' . $box['dimensional_weight'] . " $rate"; $total = $total + $rate; $this->verbose .= "
total is now $total"; } //print_r($rec); } return $total; } function get_hundredweight_rate($boxes, $zone, $shipping_type) { global $pdo_db1; $total = 0; foreach ($boxes as $key => $box) { $total = $total + $box['price']; } $this->verbose .= "
price pre hundredwight calcualtion = $total"; $weight = $this->get_total_billable_weight($boxes); $this->verbose .= "
billable weight is $weight"; $rate_rec = $this->get_rate_record($weight, $shipping_type, '2'); $zone_map = $this->get_zone_map($shipping_type, '2'); if ($zone_map === false) { return false; } //print_r($rate_rec); $rate = $rate_rec[$zone_map[$zone]]; $this->verbose .= "
rate for zone $zone is $rate"; $hundreds = floor($weight / 100); if ($shipping_type == '1' || $shipping_type == '2') { $price = $hundreds * $rate; } else { $price = ceil($weight) * $rate; } $this->verbose .= "
hundred weight price is $price"; //echo "rate is $rate and hundreds is $hundreds so price is $price"; //print_r($zone_map); //print_r($rate_rec); $c = $price + $total; $this->verbose .= "
total price is $c"; return $c; } function get_zone_map($shipping_type, $billing_type) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $q = "SELECT * FROM ups_zone_map WHERE shipping_type = '" . $pdo_db1->pdo_real_escape_string($shipping_type) . "' AND billing_type = '" . $pdo_db1->pdo_real_escape_string($billing_type) . "'"; $res = $pdo_db1->pquery($q); //$u = new utils; $rec = $res[0]; if ($rec === false) { return false; } //echo "zone record map"; //print_r($rec); $rec2 = []; foreach ($rec as $key => $value) { if (!is_numeric($key)) { //echo "key = $key and value $value"; if ($value != '' || $value != '0') { $rec2[$value] = $key; } } } return $rec2; } function get_rate_record($weight, $ship_type, $bill_type) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $weight = ceil($weight); if ($bill_type == '1') { if ($weight < 151) { $q = "SELECT * FROM ups_shipping_rates WHERE shipping_type='" . $pdo_db1->pdo_real_escape_string($ship_type) . "' AND billing_type='" . $pdo_db1->pdo_real_escape_string($bill_type) . "' AND starting_weight = '" . $pdo_db1->pdo_real_escape_string($weight) . "'"; } else { $q = "SELECT * FROM ups_shipping_rates WHERE shipping_type='" . $pdo_db1->pdo_real_escape_string($ship_type) . "' AND billing_type='" . $pdo_db1->pdo_real_escape_string($bill_type) . "' AND starting_weight = '151'"; } } if ($bill_type == '2') { $q = "SELECT * FROM ups_shipping_rates WHERE shipping_type='" . $pdo_db1->pdo_real_escape_string($ship_type) . "' AND billing_type='" . $bill_type . "' AND starting_weight <= '" . $pdo_db1->pdo_real_escape_string($weight) . "' AND ending_weight >= '" . $pdo_db1->pdo_real_escape_string($weight) . "'"; } //echo $q; $res = $pdo_db1->pquery($q, 'FETCH_BOTH'); //$u = new utils; $record = $res[0]; return $record; } function get_zone( $zip, $origin_zip = '11232', $shipping_type, $billing_type ) { global $pdo_db1; if (isset($this->zones[$zip])) { $zone_record = $this->zones[$zip]; } else { $data1 = new dataset(); $data1->db_connect(); $origin_zip_start = (int) substr($origin_zip, 0, 3); $zip_start = (int) substr($zip, 0, 3); $q = "SELECT * FROM ups_zones WHERE origin_zip_start <= '" . $pdo_db1->pdo_real_escape_string($origin_zip_start) . "' AND origin_zip_end >= '" . $pdo_db1->pdo_real_escape_string($origin_zip_start) . "' AND zip_start <= '" . $pdo_db1->pdo_real_escape_string($zip_start) . "' AND zip_end >= '" . $pdo_db1->pdo_real_escape_string($zip_start) . "'"; $res = $pdo_db1->pquery($q); //$u = new utils; $zone_record = $res[0]; $this->zones[$zip] = $zone_record; } //print_r($zone_record); if (!$zone_record === false) { return $this->match_zone_to_service($zone_record, $shipping_type); } else { return '0'; } } function match_zone_to_service($zones, $shipping_type) { switch ($shipping_type) { case '1': return $zones['fld1']; case '2': return $zones['fld2']; case '7': return $zones['fld3']; case '6': return $zones['fld4']; case '5': return $zones['fld5']; case '4': return $zones['fld6']; case '3': return $zones['fld6']; } return '0'; } function valid_zone($zone, $shipping, $billing) { } function get_total_billable_weight($boxes) { $total_billable_weight = 0; foreach ($boxes as $key => $box) { $total_billable_weight = $total_billable_weight + $box['dimensional_weight']; } return $total_billable_weight; } function calculate_gas_surcharge($shipping_rate, $shipping_type) { $this->verbose .= '
calculating gas surcharge'; if ($shipping_type == '1' || $shipping_type == '2') { $surcharge = $shipping_rate * 0.045; $this->verbose .= "
surcharge is $surcharge"; $shipping_rate = $shipping_rate + $surcharge; } else { $surcharge = $shipping_rate * 0.14; $this->verbose .= "
surcharge is $surcharge"; $shipping_rate = $shipping_rate + $surcharge; } return $shipping_rate; } function insert_shipping_rates() { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $shipping_type = 2; $billing_type = 2; $list = "200-499 50.65 65.10 77.00 94.05 132.10 149.00 165.70 500-999 49.15 63.20 74.80 91.60 128.50 144.95 161.05 1000-100000 51.20 65.75 77.85 95.25 133.65 150.85 167.50"; $list_array = explode("\n", $list); foreach ($list_array as $key => $row) { $rates = explode(' ', $row); $fields = []; $fields['shipping_type'] = $shipping_type; $fields['billing_type'] = $billing_type; /* for hundred saver ground + 3 day $st = explode("-", $rates[0]); $fields["starting_weight"] = $st[0]; $fields["ending_weight"] = $st[1]; */ // for the resto of t them $fields['starting_weight'] = $rates[0]; $x = 1; while ($x < 11) { if (isset($rates[$x])) { $fields['fld' . $x] = $rates[$x]; } $x++; } print_r($fields); $res = $data1->add_record('ups_shipping_rates', $fields); } } function insert_shipping_zones() { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $origin_zip_start = 100; $origin_zip_end = 113; $list = "004-005,2,302,202,242,132,102 006-007,45,-,225,-,-,125 8,[1],-,[1],-,-,[1] 9,45,-,225,-,-,125 010-013,2,302,202,242,132,102 14,3,303,203,243,133,103 015-016,2,302,202,242,132,102 017-042,3,303,203,243,133,103 043-044,4,304,204,244,134,104 45,3,303,203,243,133,103 046-049,4,304,204,244,134,104 050-051,3,303,203,243,133,103 052-053,2,302,202,242,132,102 054-059,3,303,203,243,133,103 060-089,2,302,202,242,132,102 090-099,-,-,-,-,-,- 100-127,2,302,202,242,132,102 128-136,3,303,203,243,133,103 137-139,2,302,202,242,132,102 140-147,3,303,203,243,133,103 148-149,2,302,202,242,132,102 150-153,4,304,204,244,134,104 154-163,3,303,203,243,133,103 164-165,4,304,204,244,134,104 166-169,3,303,203,243,133,103 170-199,2,302,202,242,132,102 200-209,3,303,203,243,133,103 210-213,2,302,202,242,132,102 214-218,3,303,203,243,133,103 219,2,302,202,-,132,102 220-238,3,303,203,243,133,103 239-243,4,304,204,244,134,104 244,3,303,203,243,133,103 245-253,4,304,204,244,134,104 254,3,303,203,243,133,103 255-264,4,304,204,244,134,104 265,3,303,203,243,133,103 266,4,304,204,-,134,104 267-268,3,303,203,243,133,103 270-288,4,304,204,244,134,104 289,5,305,205,-,-,105 290-293,4,304,204,244,134,104 294,5,305,205,245,135,105 295-297,4,304,204,244,134,104 298-299,5,305,205,245,135,105 300-324,5,305,205,245,135,105 325,6,306,206,246,136,106 326-329,5,305,205,245,135,105 330-334,6,306,206,246,136,106 335-338,5,305,205,245,135,105 339,6,306,206,246,136,106 340,-,-,-,-,-,- 341,6,306,206,246,136,106 342-347,5,305,205,245,135,105 349,6,306,206,246,136,106 350-364,5,305,205,245,135,105 365-366,6,306,206,246,136,106 367-375,5,305,205,245,135,105 376-379,4,304,204,244,134,104 380-386,5,305,205,245,135,105 387,6,306,206,246,136,106 388-389,5,305,205,245,135,105 390-392,6,306,206,246,136,106 393,5,305,205,245,135,105 394-396,6,306,206,246,136,106 397-399,5,305,205,245,135,105 400-402,5,305,205,245,135,105 403-418,4,304,204,244,134,104 420-424,5,305,205,245,135,105 425-426,4,304,204,244,134,104 427,5,305,205,245,135,105 430-459,4,304,204,244,134,104 460-466,5,305,205,245,135,105 467-468,4,304,204,244,134,104 469,5,305,205,245,135,105 470,4,304,204,244,134,104 471-472,5,305,205,245,135,105 473,4,304,204,244,134,104 474-479,5,305,205,245,135,105 480-496,4,304,204,244,134,104 497-499,5,305,205,245,135,105 500-504,5,305,205,245,135,105 505,6,306,206,246,136,106 506-507,5,305,205,245,135,105 508,6,306,206,246,136,106 509,5,305,205,245,135,105 510-516,6,306,206,246,136,106 520-559,5,305,205,245,135,105 560-576,6,306,206,246,136,106 577,7,307,207,247,137,107 580-585,6,306,206,246,136,106 586-593,7,307,207,247,137,107 594,8,308,208,248,138,108 595,7,307,207,-,-,107 596-599,8,308,208,248,138,108 600-639,5,305,205,245,135,105 640-649,6,306,206,246,136,106 650-652,5,305,205,245,135,105 653,6,306,206,246,136,106 654-655,5,305,205,245,135,105 656-676,6,306,206,246,136,106 677,7,307,207,-,-,107 678,6,306,206,246,136,106 679,7,307,207,-,-,107 680-692,6,306,206,246,136,106 693,7,307,207,247,137,107 700-722,6,306,206,246,136,106 723-725,5,305,205,245,135,105 726-732,6,306,206,246,136,106 733,7,307,207,-,-,107 734-738,6,306,206,246,136,106 739,7,307,207,-,-,107 740-764,6,306,206,246,136,106 765,7,307,207,247,137,107 766-767,6,306,206,246,136,106 768-769,7,307,207,247,137,107 770-778,6,306,206,246,136,106 779-797,7,307,207,247,137,107 798-799,8,308,208,248,138,108 800-814,7,307,207,247,137,107 815,8,308,208,248,138,108 816-820,7,307,207,247,137,107 821,8,308,208,-,-,108 822-830,7,307,207,247,137,107 831-865,8,308,208,248,138,108 870-872,7,307,207,247,137,107 873-874,8,308,208,248,138,108 875-877,7,307,207,247,137,107 878-880,8,308,208,248,138,108 881-884,7,307,207,-,137,107 885-898,8,308,208,248,138,108 900-961,8,308,208,248,138,108 962-966,-,-,-,-,-,- 967-968,[2],-,[2],-,-,[2] 969,-,-,[1],-,-,[1],, 970-994,8,308,208,248,138,108,, 995-999,[3],-,[3],-,-,[3],,"; $list_array = explode("\n", $list); foreach ($list_array as $key => $row) { $rates = explode(',', $row); $fields = []; $st = explode('-', $rates[0]); if (count($st) == 1) { $fields['zip_start'] = abs($st[0]); $fields['zip_end'] = abs($st[0]); } else { $fields['zip_start'] = abs($st[0]); $fields['zip_end'] = abs($st[1]); } $fields['origin_zip_start'] = $origin_zip_start; $fields['origin_zip_end'] = $origin_zip_end; // for the resto of t them //$fields["starting_weight"] = $rates[0]; $x = 1; while ($x < 11) { if (isset($rates[$x])) { $fields['fld' . $x] = (int) $rates[$x]; } $x++; } print_r($fields); $res = $data1->add_record('ups_zones', $fields); } } function get_amazon_shipping_price( $over_size = '0', $width = '8', $height = '10' ) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $item_result = $pdo_db1->pquery( 'SELECT * FROM `shipping_types` WHERE `amazon_shipping` = 1 LIMIT 1', 'FETCH_BOTH' ); $item_row = $item_result[0]; if ($over_size == '0') { $amazon_shipping_cost = $item_row['base_price'] + $item_row['price_per_item']; } elseif ($over_size == '1') { $amazon_shipping_cost = $item_row['long_box_base_price'] + $item_row['long_box_per_item']; } elseif ($over_size == '2') { $amazon_shipping_cost = $item_row['oversize_box_base_price'] + $item_row['oversize_box_per_item']; } elseif ($over_size == '4') { $amazon_shipping_cost = $item_row['12_inch_tube_box_base_price'] + $item_row['12_inch_tube_box_per_item']; } elseif ($over_size == '5') { $amazon_shipping_cost = $item_row['envelope_box_base_price'] + $item_row['envelope_box_per_item']; } elseif ($over_size == '6') { $amazon_shipping_cost = $item_row['large_box_base_price'] + $item_row['large_box_per_item']; } return $amazon_shipping_cost; } // Get default shipping tempalte for Amazon function get_default_shipping_template( $product_type = '', $product_sub_type = '', $box_width = '', $box_height = '', $website_id = '' ) { // echo '
All arguments';print_r(func_get_args());echo '
'; die; global $pdo_db1; if (isset($_GET['show_sku_para'])) { echo "
Shipping Template query => SELECT * FROM lead_time WHERE product_id ='" . $product_type . "' AND product_sub_type = '" . $product_sub_type . "' AND website_id = '" . $website_id . "'"; } $lead_time_result = $pdo_db1->query( "SELECT * FROM lead_time WHERE product_id ='" . $product_type . "' AND product_sub_type = '" . $product_sub_type . "' AND website_id = '" . $website_id . "' LIMIT 1" ); $lead_time_count = $pdo_db1->pdo_num_rows($lead_time_result); $lead_time_row = $lead_time_result[0]; if ($lead_time_count > 0) { $qryBoxPrice = 'SELECT * FROM shipping_box_choices WHERE ( (' . $box_width . ' <= max_width AND ' . $box_height . ' <= max_height) OR (' . $box_width . ' <= max_height AND ' . $box_height . " <= max_width)) AND product_type_allowed LIKE '%" . $product_type . "%' ORDER BY sort LIMIT 1"; } else { return 0; } $box_result = $pdo_db1->query($qryBoxPrice); $box_count = $pdo_db1->pdo_num_rows($box_result); if ($lead_time_count > 0) { if ($lead_time_row['free_shipping'] == 1) { //echo "
Template => ".$box_result['free_shipping_template']; die; return $box_result['free_shipping_template']; } return $box_result['amazon_shipping_template']; } else { return 0; } } function get_atf_shipping_price( $over_size, $shipping_type, $free_shipping = 0 ) { //echo "ggg";exit; global $pdo_db1; if ( isset($_GET['shipping_options']) && $_GET['shipping_options'] == '1' ) { echo '
' . __LINE__ . '#in get_atf_shipping_price'; echo '
';
            echo '
' . __LINE__ . '#in get_atf_shipping_price::over_size'; print_r($over_size); echo '
' . __LINE__ . '#in get_atf_shipping_price::shipping_type'; print_r($shipping_type); echo '
' . __LINE__ . '#in get_atf_shipping_price::free_shipping'; var_dump($free_shipping); } //echo $over_size;exit; $data1 = new dataset(); $data1->db_connect(); $q = 'SELECT * FROM `shipping_types` WHERE `id` = ' . $shipping_type; $item_result = $pdo_db1->pquery($q); $item_row = $item_result[0]; //echo "
";print_r($over_size);
        $shipping_cost = 0;
        //echo "shipping".$free_shipping;
        foreach ($over_size as $key => $value) {
            //echo $key. "  " .$value;exit;

            if ($key == '0') {
                $qty = $value - $free_shipping;
                if ($free_shipping > 0) {
                    $qty = $value - $free_shipping;
                    if ($qty == 0 || $qty < 0) {
                        $shipping_cost = $shipping_cost + 0;
                    } else {
                        $shipping_cost =
                            $shipping_cost +
                            $item_row['base_price'] +
                            $item_row['price_per_item'] * $qty;
                    }
                } else {
                    $shipping_cost =
                        $shipping_cost +
                        $item_row['base_price'] +
                        $item_row['price_per_item'] * $value;
                }
            } elseif ($key == '1') {
                $shipping_cost =
                    $shipping_cost +
                    $item_row['long_box_base_price'] +
                    $item_row['long_box_per_item'] * $value;
            } elseif ($key == '2') {
                $shipping_cost =
                    $shipping_cost +
                    $item_row['oversize_box_base_price'] +
                    $item_row['oversize_box_per_item'] * $value;
            } elseif ($key == '4') {
                $shipping_cost =
                    $shipping_cost +
                    $item_row['12_inch_tube_box_base_price'] +
                    $item_row['12_inch_tube_box_per_item'] * $value;
            } elseif ($key == '5') {
                $shipping_cost =
                    $shipping_cost +
                    $item_row['envelope_box_base_price'] +
                    $item_row['envelope_box_per_item'] * $value;
            } elseif ($key == '6') {
                $shipping_cost =
                    $shipping_cost +
                    $item_row['large_box_base_price'] +
                    $item_row['large_box_per_item'] * $value;
            } else {
                $qty = $value - $free_shipping;
                if ($free_shipping > 0) {
                    $qty = $value - $free_shipping;
                    if ($qty == 0 || $qty < 0) {
                        $shipping_cost = $shipping_cost + 0;
                    } else {
                        $shipping_cost =
                            $shipping_cost +
                            $item_row['base_price'] +
                            $item_row['price_per_item'] * $qty;
                    }
                } else {
                    $shipping_cost =
                        $shipping_cost +
                        $item_row['base_price'] +
                        $item_row['price_per_item'] * $value;
                }
            }
        }
        //echo $shipping_cost;exit;
        if (
            isset($_GET['shipping_options']) &&
            $_GET['shipping_options'] == '1'
        ) {
            echo '
' . __LINE__ . '#in get_atf_shipping_price::shipping_cost==>' . $shipping_cost; } return $shipping_cost; } function get_box_info_from_sizes( $width = '8', $height = '10', $prod_type, $order_item = [] ) { /* if($_GET['print_box_queries'] == 1 && $_SESSION['permissions'] > 1){ echo "
";
            echo "In get_box_info_from_sizes call";
            echo "
width==>".$width; echo "
height==>".$height; echo "
prod_type==>".$prod_type; echo "
order_item==>"; print_r($order_item); echo "
"; }*/ //echo "ggg";exit; global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); /* Modified By.: Savata Bachhav Modified On.: 2021-12-03 product_sub_items condition added for checking oversize logic for gallery walls products. as we have multiple frames under that main gallery wall item. See task details: https://arttoframes.teamwork.com/#/tasks/26400930 */ if ( is_array($order_item['order_item_sub_details']) && count($order_item['order_item_sub_details']) > 0 ) { $large_item_area = 0; foreach ($order_item['order_item_sub_details'] as $value) { $prod_type = $value['product_type']; $width = $value['finished_width']; $height = $value['finished_height']; $current_item_area = ($width * $height) / 144; if ($large_item_area < $current_item_area) { if ( $prod_type == 43 || $prod_type == 84 || $prod_type == 85 ) { $box_q = "SELECT * FROM shipping_box_choices WHERE ( (8<= max_width AND 10 <= max_height) OR (10 <= max_height AND 8 <= max_width)) AND product_type_allowed LIKE '%" . $prod_type . "%' ORDER BY sort LIMIT 1"; } else { $box_q = "SELECT * FROM shipping_box_choices WHERE ( ('" . $width . "' <= max_width AND '" . $height . "' <= max_height) OR ('" . $width . "' <= max_height AND '" . $height . "' <= max_width)) AND product_type_allowed LIKE '%" . $prod_type . "%' ORDER BY sort LIMIT 1"; } $large_item_area = $current_item_area; } } } else { if ($prod_type == 43 || $prod_type == 84 || $prod_type == 85) { $box_q = "SELECT * FROM shipping_box_choices WHERE ( (8<= max_width AND 10 <= max_height) OR (10 <= max_height AND 8 <= max_width)) AND product_type_allowed LIKE '%" . $prod_type . "%' ORDER BY sort LIMIT 1"; } else if(!empty($order_item['sku_base_products_id'])){ //condition added on 20250704 #TW37921286: For TV frame we there is data fetch from sku_base_product tbl based on SBP_id or based on max height from shipping_box_choices tbl $width = 4; if($height<$width){ $height = $width; } $height =$height + 1; $box_q = 'select sbp.id as sku_base_product_id,sbc.* from sku_base_products as sbp join shipping_box_choices as sbc on sbp.default_box_id=sbc.id where sbp.id='. $order_item['sku_base_products_id']; $item_result_t = $pdo_db1->pquery($box_q); if ($pdo_db1->pdo_num_rows($item_result_t) == 0 && !empty($order_item['order_item_details_new'][0]['hardware_four_id']) && $order_item['order_item_details_new'][0]['hardware_four_id']==122) { $box_q = "SELECT * FROM shipping_box_choices WHERE ".$height." <= height and is_pickup_box=0 limit 1"; } } else { if (!empty($order_item['order_item_details_new'][0]['hardware_four_id']) && $order_item['order_item_details_new'][0]['hardware_four_id']==122) { $width1 = 4; $height1=$height; if($height<$width){ $height1 = $width; } $height1 =$height1 + 1; $box_q = "SELECT * FROM shipping_box_choices WHERE ".$height1." <= height and is_pickup_box = 0 and box_number like '%_TV_%' limit 1"; }else{ $box_q = "SELECT * FROM shipping_box_choices WHERE ( ('" . $width . "' <= max_width AND '" . $height . "' <= max_height) OR ('" . $width . "' <= max_height AND '" . $height . "' <= max_width)) AND product_type_allowed LIKE '%" . $prod_type . "%' ORDER BY sort LIMIT 1"; } //echo "box_q=>". $box_q; } } // echo "
Box Query".__LINE__."=>".$box_q;exit; // echo "
"; print_r($_SESSION); exit;
        $item_result = $pdo_db1->pquery($box_q);

        if (
            $pdo_db1->pdo_num_rows($item_result) == 0 &&
            $order_item['sku_base_products'] == 1
        ) {
            $box_q =
                "SELECT * FROM shipping_box_choices WHERE id IN(SELECT default_box_id FROM sku_base_products WHERE id = '" .
                $order_item['sku_base_products_id'] .
                "')";
            $item_result = $pdo_db1->pquery($box_q);
        }

        if ($_GET['print_box_queries'] == 1 && $_SESSION['permissions'] > 1) {
            echo '
Box Query from module shipping line number--' .
                __LINE__ .
                '=>' .
                $box_q .
                '
'; } if ($pdo_db1->pdo_num_rows($item_result) > 0) { $item_row = $item_result[0]; return $item_row; } else { return false; } // $item_row = $item_result[0]; // return $item_row; } /** * Function to get orders that are marked as opened but have been shipped after last status order update * 2nd Nov, 2018 * Param $return_data_count = count OR data (query result) */ function get_orders_that_are_shipped_but_still_open( $return_data_count = 'count' ) { global $pdo_db1; $data1 = new dataset(); $data1->db_connect(); $query_fields = ''; $query_fields = 'end_of_day.*, DATE(orders.last_order_status_date) as last_order_status_date, DATE(end_of_day.pickup_time) as pickup_time_date,'; // if($return_data_count == "count"){ // $query_fields = "COUNT( 1 ) AS total_count"; // }else{ // } $item_result = $pdo_db1->pquery( 'SELECT ' . $query_fields . "CASE WHEN DATE(last_order_status_date) > DATE(MAX(pickup_time)) THEN 'not shipped' ELSE 'shipped' END AS shipped FROM orders INNER JOIN end_of_day ON orders.id = end_of_day.order_id WHERE status = 3 AND damaged = 1 GROUP BY orders.id HAVING COUNT(end_of_day.order_id) > 1 AND shipped = 'shipped'", 'FETCH_BOTH' ); if ($return_data_count == 'count') { // $item_row = $item_result[0]; // return $item_row['total_count']; return count((array)$item_result); } else { $orders_arr = []; if ($pdo_db1->pdo_num_rows($item_result) > 0) { foreach ($item_result as $item_row) { $orders_arr[] = $item_row; } } return $orders_arr; } } //end function get_orders_that_are_shipped_but_still_open function get_pickup_address_by_shipping_type_id($shipping_type) { global $pdo_db1; $address_info = $pdo_db1->pquery( "SELECT * FROM pickup_return_addresses WHERE shipping_types_id = '" . $shipping_type . "'" ); $address_info = $address_info[0]; $state_name_info = $pdo_db1->pquery( "SELECT * FROM states_bases_zip_tax_rates WHERE state_code = '" . $address_info['state'] . "' AND zip_code = '" . $address_info['zip_code'] . "'" ); $state_name = $state_name_info[0]['state']; $res = []; $res['pickup_address'] = $address_info['address2'] . ', ' . $address_info['city'] . ',' . $state_name . ' ' . $address_info['zip_code']; $res['pickup_address_footer'] = '
' . strtoupper($address_info['address2']) . '
' . strtoupper($address_info['city']) . ', ' . strtoupper($address_info['state']) . ' ' . $address_info['zip_code'] . '
'; return $res; } function generate_tracking_number($order_id) { global $pdo_db1; $order_id_query = "SELECT * from order_tracking Where order_id='" . $order_id . "' "; if ( isset($_REQUEST['print_query']) && $_REQUEST['print_query'] == '1' ) { echo '
==>' . $order_id_query; } $order_result = $pdo_db1->pquery($order_id_query); if ($pdo_db1->pdo_num_rows($order_result) > 0) { return $order_result[0]['tracking_no']; } else { $unique_no = substr(md5(uniqid(rand(), true)), 0, 6); $order_tracking_sql = "SELECT * from order_tracking Where tracking_no='" . $unique_no . "' "; if ( isset($_REQUEST['print_query']) && $_REQUEST['print_query'] == '1' ) { echo '
==>' . $order_tracking_sql; } $order_tracking_result = $pdo_db1->pquery($order_tracking_sql); if ($pdo_db1->pdo_num_rows($order_tracking_result) > 0) { $this->generate_tracking_number($order_id); //recurssive call } else { $pquery = "INSERT INTO order_tracking(`order_id`, `tracking_no`) VALUES ('" . $order_id . "', '" . $unique_no . "')"; if ( isset($_REQUEST['print_query']) && $_REQUEST['print_query'] == '1' ) { echo '
==>' . $pquery; } $last_inserted_id = $pdo_db1->pquery($pquery); return $unique_no; } } } /** * 15April2022 * @Param $return_type = url_only / href_url / tracking_number / array_data * For e.g. * url_only = {URL} * href_url = {tracking_number} * tracking_number = {tracking_number} * array_data = i.e. query result */ function get_shipping_tracking_url( $tracking_number, $order_id, $return_type = 'url_only' ) { global $pdo_db1; $return_data = false; //Code will come here to get url using inner join query of end_of_day + shipping_carrier //Query to get tracking url dynamically if ($order_id > 0 && strlen(trim($tracking_number)) > 0) { $order_tracking_url_sql = "SELECT eod.tracking_number, eod.order_id, sc.tracking_url, IF(LENGTH(sc.tracking_url) > 0, CONCAT(sc.tracking_url, '', eod.tracking_number), eod.tracking_number) as custom_tracking_url FROM end_of_day AS eod INNER JOIN shipping_carriers AS sc ON eod.carrier_id = sc.id WHERE eod.order_id = '" . $order_id . "' AND eod.tracking_number = '" . $tracking_number . "' LIMIT 1"; if ( isset($_REQUEST['print_query']) && $_REQUEST['print_query'] == '1' ) { echo '
==> ' . $order_tracking_url_sql; } $order_tracking_url_result = $pdo_db1->pquery( $order_tracking_url_sql ); if ($pdo_db1->pdo_num_rows($order_tracking_url_result) > 0) { $order_tracking_url_info = $order_tracking_url_result[0]; if ($return_type == 'array_data') { $return_data = []; $return_data = $order_tracking_url_info; } elseif (in_array($return_type, ['url_only', 'href_url'])) { if ( strlen(trim($order_tracking_url_info['tracking_url'])) > 0 ) { if ($return_type == 'href_url') { $return_data = '' . $order_tracking_url_info['tracking_number'] . ''; } //default $return_type = 'url_only' else { $return_data = $order_tracking_url_info['custom_tracking_url']; } } else { $return_data = 'https://www.google.com/search?q=' . $order_tracking_url_info['tracking_number']; } } //default $return_type = 'tracking_number' else { $return_data = $order_tracking_url_info['tracking_number']; } } } return $return_data; } function getShippingDays($product_type_id = 0, $popup = 'no', $param = array(),$cart=array(),$type=""){ global $pdo_db1; $response = $reqArr = array(); include_once("lib/modules.new_cart_v2.php"); include_once("lib/modules.products.php"); include_once("lib/modules.tools.php"); $cart_obj = new new_cart_v2; $p = new products; $tools = new tools; if (isset($param['cart_id']) && !empty($param['cart_id'])) { // added condition on 20240105 #TW35156577: TO fetch correct cart details for admin user //$cart = $cart_obj->get_new_cart_v2($param['cart_id']); $cart_id = $param['cart_id']; } $giftCardShippingTextStatus = $otherProducts = 0; if (isset($cart['order_items']) && is_array($cart['order_items'])) { foreach ($cart['order_items'] as $order_items_key => $order_items_value) { $order_item_product_type = ''; if ( is_array($order_items_value) && isset($order_items_value['order_item_details_new']) && is_array($order_items_value['order_item_details_new']) && isset($order_items_value['order_item_details_new'][0]) && is_array($order_items_value['order_item_details_new'][0]) && isset($order_items_value['order_item_details_new'][0]['product_type']) ) { $order_item_product_type = $order_items_value['order_item_details_new'][0]['product_type']; } elseif (is_array($order_items_value) && isset($order_items_value['prod_type'])) { $order_item_product_type = $order_items_value['prod_type']; } if ($order_item_product_type == "33") { $giftCardShippingTextStatus++; } else { $otherProducts++; } } } //echo $giftCardShippingTextStatus;exit; $zip_3day_air_not = array('AK', 'HI'); $time_in_transit = 0; $ship_to_zip = ($param['pageSource'] == 'cart') ? $cart['zip_code'] : ''; $order_items = (is_array($cart["order_items"])) ? $cart["order_items"] : array(); if ($cart['zip_code_dashcode'] != '') { $findme = '-'; $pos = strpos($cart['zip_code_dashcode'], $findme); if ($pos == false) { // Nothing to do here // $cart['zip_code_dashcode'] = ''; } else { $zip_ex = explode('-', $cart['zip_code_dashcode']); $zip = trim($zip_ex[0]); unset($cart['zip_code']); // delete the show zip variable $cart['zip_code'] = $zip; $ship_to_zip = $zip; if (function_exists('atf_checkout_shipping_cost_debug_step')) { atf_checkout_shipping_cost_debug_step('modules_shipping_v2_before_save_cart', array('cart_summary' => atf_checkout_shipping_cost_debug_cart_summary($cart), 'line' => __LINE__)); } $cart = $cart_obj->save_cart($cart); if (function_exists('atf_checkout_shipping_cost_debug_step')) { atf_checkout_shipping_cost_debug_step('modules_shipping_v2_after_save_cart', array('cart_summary' => atf_checkout_shipping_cost_debug_cart_summary($cart), 'line' => __LINE__)); } $cart = $cart_obj->get_new_cart_v2($cart_id,'','','1'); } } // $setShippingPrice = "0.00"; if (empty($cart["shipping_type"]) || $cart["shipping_type"] === 0) { //echo "sdgjdd"; $cart["shipping_type"] = 1; } // Code added on 20230425: if shipping_type is blank then assign shipping values of the first array from shipping price // if (empty($cart['shipping_type']) && !empty($cart['shipping_prices'])) { // $cart["shipping_type"] = $cart['shipping_prices'][1]['code']; // $cart["shipping_cost"] = $cart['shipping_prices'][1]['price']; // echo "at A2
"; // $cart = $cart_obj->save_cart($cart); // $cart = $cart_obj->get_new_cart_v2($cart_id); // } if ($ship_to_zip == '') { $ship_to_zip = (isset($_SESSION['change_zip']) && is_numeric($_SESSION['change_zip'])) ? $_SESSION['change_zip'] : $_SESSION['zipcode']; } if ($ship_to_zip != '') { $time_in_transit = $p->specific_select("zipcode", "zipcode", $ship_to_zip, "time_in_transit"); } // exit; if (isset($cart['ship_country']) && $cart['ship_country'] == 'CA') { $time_in_transit = 7; } $max_production_time = 0; $get_max_production_time_for_cart = $p->get_max_production_time_for_cart($cart); $check_for_rush_override_arr = ( isset($get_max_production_time_for_cart['products_in_cart']) && is_array($get_max_production_time_for_cart['products_in_cart']) ) ? $get_max_production_time_for_cart['products_in_cart'] : array(); $reqArr['shipping_type'] = ($param['shipping_type'] != '') ? $param['shipping_type'] : $cart["shipping_type"]; $reqArr['product_type_id'] = $product_type_id; $reqArr['popup'] = $popup; $reqArr['time_in_transit'] = $time_in_transit; $reqArr['product_lead_time'] = $param['product_lead_time']; if ($param['pageSource'] == "header") { $this->getShippingDetails($reqArr); } else { if (is_array($order_items) && count($order_items) > 0) { foreach ($order_items as $key => $value) { $this->getShippingDetails($reqArr, $value); } } else { $this->getShippingDetails($reqArr); } } $max_production_time = (is_array($this->max_ships_in_days_val) && count($this->max_ships_in_days_val) > 0) ? max($this->max_ships_in_days_val) : 0; $rush_applied_to_cart = false; $check_for_rush_override = (is_array($check_for_rush_override_arr) && count($check_for_rush_override_arr)) ? max($check_for_rush_override_arr) : 0; if (isset($cart['cart_extra']['Rush processing']) && $cart['cart_extra']['Rush processing'] == 1 || $param['pageSource'] == "product") { $current_date_forcheck_rush = date('Y-m-d H:i:s'); $rush_applied_to_cart = true; } $response['html'] = ''; if($param['pageSource'] == 'cart'){ $shippingD = $cart["shipping_prices"]; if($_REQUEST['shipping_prices'] == 1) { echo " ===== working days =====
";
                    print_r($shippingD);
                    echo "
"; echo "
===== "; } }else{ $shipping_type = ($param['shipping_type'] != '') ? $param['shipping_type'] : $cart["shipping_type"]; $sql = "SELECT * FROM shipping_types WHERE in_use = 1 AND code = '".$shipping_type."'ORDER BY carrier ASC"; $shippingD = $pdo_db1->pquery($sql); } // echo "shipping_type >> ".$shipping_type;exit; $html=''; // $html .= '

Delivery Options

'; $response_dropdowm['html'] =$html1.$html; } if($type==1){ if (!in_array("2", $shippingOptionCodes)) { // echo "
";

          //    print_r($shippingOptionCodes);
    // Create the standard shipping HTML
    $standardShippingHtml = '';

    // Prepend it to the HTML
    $response['html'] = $standardShippingHtml . $response['html'];
}
            return $response;
        }else if($param['pageSource']=='product'){
            return $response_estimate;
        }else {
            return $response_dropdowm;
        }
        
    }



       function getShippingDays_checkout($product_type_id = 0, $popup = 'no', $param = array()){
    
        global $pdo_db1;
       
        $response = $reqArr = array();
        include_once("lib/modules.new_cart_v2.php");
        include_once("lib/modules.products.php");
        include_once("lib/modules.tools.php");
    
        $cart_obj   = new new_cart_v2;
        $p          = new products;
        $tools = new tools;
        //echo "
",print_r($param);exit;
        if(!isset($param['website']) || $param['website']==2){
           if(isset($param['cart_id']) && !empty($param['cart_id'])){ // added condition on 20240105 #TW35156577: TO fetch correct cart details for admin user
               $cart = $cart_obj->get_new_cart_demo($param['cart_id']);
            }else{
               $cart = $cart_obj->get_new_cart_demo();
            }
        }else{
           
             $cart = $param['cart'];
            
        }

    
        $zip_3day_air_not = array('AK', 'HI');
    
        $time_in_transit = 0;
        $ship_to_zip = ($param['pageSource'] == 'cart') ? $cart['ship_zip'] : '';
        $order_items = (is_array($cart["order_items"])) ? $cart["order_items"] : array();
        if ($cart['ship_zip_dashcode'] != '') {
          $findme   = '-';
          $pos = strpos($cart['ship_zip_dashcode'], $findme);
          if ($pos == false) {
            // Nothing do here
            //  $cart['ship_zip_dashcode'] = '';
          } else {
            $zip_ex = explode('-', $cart['ship_zip_dashcode']);
            $zip = trim($zip_ex[0]);
            unset($cart['ship_zip']); //delete the show zip variable    
            $cart['ship_zip'] = $zip;
            $ship_to_zip = $zip;
            $cart = $cart_obj->save_cart($cart);
            $cart = $cart_obj->get_cart();
          }
        }
       
        if (!isset($cart["shipping_type"])) {
          $cart["shipping_type"] = 1;
        }
        
        if (empty($cart['shipping_type']) && !empty($cart['shipping_prices'])) {
          $cart["shipping_type"] = $cart['shipping_prices'][1]['code'];
          $cart["shipping_cost"] = $cart['shipping_prices'][1]['price'];
          $cart = $cart_obj->save_cart($cart);
          $cart = $cart_obj->get_cart();
        }
        if($ship_to_zip == ''){
          $ship_to_zip = (isset($_SESSION['change_zip']) && is_numeric($_SESSION['change_zip'])) ? $_SESSION['change_zip'] : $_SESSION['zipcode'];
        }
        
        if ($ship_to_zip != '') {
          $time_in_transit = $p->specific_select("zipcode", "zipcode", $ship_to_zip, "time_in_transit");
        }
        if (isset($cart['ship_country']) && $cart['ship_country'] == 'CA') {
          $time_in_transit = 7;
        }
        $max_production_time = 0;
        $get_max_production_time_for_cart = $p->get_max_production_time_for_cart($cart);
    
        // $ship_time = 2;
        $check_for_rush_override_arr = $get_max_production_time_for_cart['products_in_cart'];
    
        $reqArr['shipping_type'] = ($param['shipping_type'] != '') ? $param['shipping_type'] : $cart["shipping_type"];
        $reqArr['product_type_id'] = $product_type_id;
        $reqArr['popup'] = $popup;
        $reqArr['time_in_transit'] = $time_in_transit;
        $reqArr['product_lead_time'] = $param['product_lead_time'];
        if($param['pageSource'] == "header"){
            $this->getShippingDetails($reqArr);
        }else{
            if(is_array($order_items) && count($order_items) > 0){
                foreach($order_items AS $key => $value){
                    $this->getShippingDetails($reqArr, $value);
                }
            }else{
                $this->getShippingDetails($reqArr);
            }
        }
        
        
        $max_production_time = (is_array($this->max_ships_in_days_val) && count($this->max_ships_in_days_val) > 0) ? max($this->max_ships_in_days_val) : 0;
        $rush_applied_to_cart = false;
        $check_for_rush_override = (is_array($check_for_rush_override_arr) && count($check_for_rush_override_arr)) ? max($check_for_rush_override_arr) : 0;
        if (isset($cart['cart_extra']['Rush processing']) && $cart['cart_extra']['Rush processing'] == 1 || $param['pageSource'] == "product") {
          $current_date_forcheck_rush = date('Y-m-d H:i:s');
          $rush_applied_to_cart = true;
        }
        $response['html'] = '';
    
        if($param['pageSource'] == 'cart' && !empty($cart["shipping_prices"])){
           // echo "at AAAAA
"; $shippingD = $cart["shipping_prices"]; }else{ $shipping_type = ($param['shipping_type'] != '') ? $param['shipping_type'] : $cart["shipping_type"]; if (isset($param['website']) && in_array($param['website'],array(2,7,44))) { $sql = "SELECT * FROM shipping_types WHERE code = '".$shipping_type."' ORDER BY carrier ASC"; }else{ $sql = "SELECT * FROM shipping_types WHERE id = '".$shipping_type."' ORDER BY carrier ASC"; } //$sql = "SELECT * FROM shipping_types WHERE code = '".$shipping_type."'ORDER BY carrier ASC"; //echo "at BBBBBB
"; $shippingD = $pdo_db1->pquery($sql); } $atf_allow_ak_hi_ca_multibox_rateshop_methods = false; if( isset($cart['no_of_box']) && (int)$cart['no_of_box'] > 1 && ( $cart['ship_state'] == 'AK' || $cart['ship_state'] == 'HI' || $cart['ship_state'] == 'VI' || $cart['ship_state'] == 'PR' || $cart['ship_country'] == 'CA' || $cart['ship_country'] == 'Canada' ) && isset($cart['static_shipping_price']) && is_numeric($cart['static_shipping_price']) && (float)$cart['static_shipping_price'] > 0 && isset($cart['shipping_quote_source']) && stripos((string)$cart['shipping_quote_source'], 'using_rateshop_API_State_') !== false && (empty($cart['is_box_not_available_request_quote']) || (string)$cart['is_box_not_available_request_quote'] !== '1') ){ $atf_allow_ak_hi_ca_multibox_rateshop_methods = true; } if(is_array($shippingD) && count($shippingD) > 0){ foreach ($shippingD as $key => $option) { if ($param['isZipCodeFromStateAKorHIorCountryCA'] == true && $param['getBoxCount'] > 1 && in_array($option['code'], array(1, 2)) && $cart['static_shipping_price'] == "" && !$atf_allow_ak_hi_ca_multibox_rateshop_methods) { continue; } list($name, $from, $to) = explode("-", $option["name"]); $todays_date = date("Y-m-d"); if ($option["name"] == 'Size to big.') { $size_to_big = 'yes'; } if (strpos(strtolower($to), 'days') !== false) { $chk_str = $to; } elseif (strpos(strtolower($from), 'days') !== false) { $chk_str = $from; } else { $chk_str = $name; } $shipping_types_info = $p->full_select("shipping_types", "code", $option["code"]); $use_zipcode_time_in_transit = $shipping_types_info['use_zipcode_time_in_transit']; $time_transit = $shipping_types_info['time_in_transit']; $shipping_method_additional_lead_time = $shipping_types_info['additional_lead_time']; $upto_days = (intval($time_transit) + intval($shipping_method_additional_lead_time)); $to_date_time = (intval($upto_days) + intval($max_production_time)); $workingdays_shippers_arr = array(); $workingdays_arr = array(); // ===================== Rush service =================== // if ($rush_applied_to_cart) { if ($use_zipcode_time_in_transit == 1 && $time_in_transit > 0) { $upto_days = $time_in_transit + $shipping_method_additional_lead_time; } if ($check_for_rush_override > 0) { $rush_max_production_time = $check_for_rush_override; $rush_to_date_time = $upto_days + $check_for_rush_override + $param['frame_name_lead_time']; $workingdays_arr = $tools->workingdays($current_date_forcheck_rush, true, $check_for_rush_override); $to_production_date = (end($workingdays_arr)); $workingdays_shippers_arr = $tools->busnessDaysWithShippersHoliday($to_production_date, true, $upto_days); $rush_to_date = (end($workingdays_shippers_arr)); } elseif (date('H', strtotime($current_date_forcheck_rush)) < 12) { $rush_max_production_time = 0; $rush_to_date_time = $upto_days + 0 + $param['frame_name_lead_time']; $rush_to_date = $current_date_forcheck_rush; $to_production_date = $tools->check_current_date($current_date_forcheck_rush, true); $workingdays_shippers_arr = $tools->busnessDaysWithShippersHoliday($to_production_date, true, $upto_days); $rush_to_date = (end($workingdays_shippers_arr)); } else { $rush_max_production_time = 1; $rush_to_date_time = $upto_days + 1 + $param['frame_name_lead_time']; $workingdays_arr = ($tools->workingdays($current_date_forcheck_rush, true, 1)); $to_production_date = (end($workingdays_arr)); $workingdays_shippers_arr = ($tools->busnessDaysWidoutHoliday($to_production_date, true, $upto_days)); $rush_to_date = (end($workingdays_shippers_arr)); } // ====================== End =================== // } else { // ============ For other shipping method ======================= $temp_flag = 'no'; // added below condition to handle fatal error on db9 update as on 20231218 if (isset($param['max_frame_name_lead_time_new']) && is_array($param['max_frame_name_lead_time_new'])) { if (in_array('additional_lead_time', $param['max_frame_name_lead_time_new'])) { $temp_flag = 'yes'; } } else { // Handle the case where $param['max_frame_name_lead_time_new'] is not an array } if (empty($param['max_frame_name_lead_time_new'])) { $temp_flag = 'yes'; } if ($temp_flag == 'no') { $param['frame_name_lead_time'] = 1; $max_production_time = 0; } // echo "
====".$use_zipcode_time_in_transit ."===". $time_in_transit; if ($use_zipcode_time_in_transit == 1 && $time_in_transit > 0) { $to_date_time = (intval($time_in_transit) + intval($max_production_time) + $param['frame_name_lead_time']); $workingdays_arr = ($tools->workingdays(date('Y-m-d'), true, intval($max_production_time) + $param['frame_name_lead_time'])); $to_production_date = (end($workingdays_arr)); $workingdays_arr1 = ($tools->workingdays(date("Y-m-d", strtotime($param['deliver_by_date'])), false, intval($max_production_time) + $param['frame_name_lead_time'])); $to_production_date1 = $workingdays_arr1[0]; if($_REQUEST['debug_leadtime_data'] == 1){ echo " ===== working days =====
";
                    print_r($workingdays_arr1);
                    echo "
"; echo "
===== ".$to_production_date1; } $workingdays_shippers_arr = ($tools->busnessDaysWithShippersHoliday($to_production_date, true, intval($time_in_transit))); $to_date = (end($workingdays_shippers_arr)); $workingdays_shippers_arr1 = ($tools->busnessDaysWithShippersHoliday($to_production_date1, false, intval($time_in_transit))); $orderDate = $workingdays_shippers_arr1[0]; if($_REQUEST['debug_leadtime_data'] == 1){ echo " ===== working days =====
";
                    print_r($workingdays_shippers_arr1);
                    echo "
"; echo "
===== ".$orderDate; } } else { $workingdays_arr = ($tools->workingdays(date('Y-m-d'), true, intval($max_production_time) + $param['frame_name_lead_time'])); $to_production_date = (end($workingdays_arr)); $workingdays_arr1 = ($tools->workingdays(date("Y-m-d", strtotime($param['deliver_by_date'])), false, intval($max_production_time) + $param['frame_name_lead_time'])); $to_production_date1 = $workingdays_arr1[0]; $workingdays_shippers_arr = ($tools->busnessDaysWithShippersHoliday($to_production_date, true, intval($upto_days))); $to_date = (end($workingdays_shippers_arr)); $workingdays_shippers_arr1 = ($tools->busnessDaysWithShippersHoliday($to_production_date1, true, intval($upto_days))); $orderDate = $workingdays_shippers_arr1[0]; } // exit; // } // ===================== End ========================= if ($option["code"] == 2 && empty($param['get_estimated_date'])) { $time_for_ground = $time_in_transit; if ($time_for_ground == 1) { if (isset($cart["shipping_type"]) && $cart["shipping_type"] == 3) { $cart["shipping_type"] = 2; } elseif (isset($cart["shipping_type"]) && $cart["shipping_type"] == 5) { $cart["shipping_type"] = 2; } } else if ($time_for_ground == 2) { if (isset($cart["shipping_type"]) && $cart["shipping_type"] == 3) { $cart["shipping_type"] = 2; } } } if($param['pageSource'] == "cart"){ $estimated_date = ''; if ($rush_applied_to_cart) { $calculated_shipping_date = date('M d', strtotime($rush_to_date)); $calculated_shipping_date_next = date('d', strtotime('+1 day ' . $rush_to_date)); $estimated_date = $rush_to_date; }else{ $calculated_shipping_date = date('M d', strtotime($to_date)); $calculated_shipping_date_next = date('d', strtotime('+1 day ' . $to_date)); $estimated_date = $to_date; } if (!empty($param['get_estimated_date']) && $cart['shipping_type'] == $option["id"] && !in_array($param['website'],array(2,7,44))) { $estimated_date = date('Y-m-d', strtotime('+1 day ' . $estimated_date)); return $estimated_date; }elseif(!empty($param['get_estimated_date']) && $cart['shipping_type'] == $option["code"]){ $estimated_date = date('Y-m-d', strtotime('+1 day ' . $estimated_date)); return $estimated_date; } if (!empty($param['get_estimated_date'])) { return $estimated_date; } if (($option["code"] == 3 || $option["code"] == 5 || $option["code"] == 36) && (isset($option["api_price"]) && ($option["api_price"] == 0 || $option["api_price"] == '' || $param['getBoxCount'] > 1))) { continue; } if (($time_for_ground == 1) && ($option["code"] == 3 || $option["code"] == 5)) { continue; } elseif (($time_for_ground == 2) && ($option["code"] == 3)) { continue; } else { if (isset($cart['cart_extra']['Rush processing'])) { $shipp_date_color_cls = 'clsGreen'; $response['show_some_price_of_rush'] = ''; } else { $shipp_date_color_cls = 'clsGreen'; $response['show_some_price_of_rush'] = ''; } if (in_array($cart['ship_state'], $zip_3day_air_not) && $name == '3 Day Air') { // Here for Alaska & Hawaii } else { if ($param['WinnerCost_price'] != '' && $param['is_box_not_available_request_quote'] == 1) { if ($name == 'Standard ' && $_SESSION['hide_economy_shipping'] != '1') { $style_display = 'none'; } elseif (!isset($option["code"]) && $option["code"] == "" && $param['is_box_not_available_request_quote'] == 1) { $style_display = 'none'; } else if ($param['is_box_not_available_request_quote'] == 1 && ($param['qty_oversized_item'] > 2 || $param['order_items_count'] > 1) && in_array($option["code"], array('2', '3', '5', '36')) && $cart['static_shipping_price'] == "") { $style_display = 'none'; } else { $style_display = ''; } } else if (!isset($option["code"]) && $option["code"] == "" && $param['is_box_not_available_request_quote'] == 1) { $style_display = 'none'; } else if ($param['is_box_not_available_request_quote'] == 1 && ($param['qty_oversized_item'] > 2 || $param['order_items_count'] > 1) && in_array($option["code"], array('2', '3', '5', '36')) && $cart['static_shipping_price'] == "") { $style_display = 'none'; } else { $style_display = ''; } if ($_SESSION['hide_economy_shipping'] == '1') { if ($name == 'Economy ') { $style_display = 'none'; } } if (isset($cart["shipping_type"]) && empty($cart["shipping_type"]) && $style_display == '') { $cart["shipping_type"] = $option["code"]; $cart["shipping_cost"] = $option['price']; $cart = $cart_obj->save_cart($cart); $cart = $cart_obj->get_cart(); } $chk = ''; if (isset($cart["shipping_type"]) && $cart["shipping_type"] == $option["code"]) { $chk = 'checked="checked"'; $response['setShippingPrice'] = $option["price"]; $response['set_calculated_shipping_date'] = $calculated_shipping_date; } //Below codition is added on 20241122 #TW38398621: to set selected shipping type if it is changed // if(empty($style_display) && !empty($param['old_shipping_type']) && !empty($cart['shipping_type']) && ($param['old_shipping_type']!=$cart['shipping_type']) && ($param["old_shipping_type"] == $option["code"]) && !in_array($param["old_shipping_type"], $param['availShiptoGetQuoteOptArr'])){ // $chk = 'checked="checked"'; // $cart['shipping_type'] = $param['old_shipping_type']; // $cart['shipping_cost'] = $option['price'];; // $cart = $cart_obj->save_cart($cart); // $cart = $cart_obj->get_cart(); // } $param['availShiptoGetQuoteOptArr'] = is_array($param['availShiptoGetQuoteOptArr']) ? $param['availShiptoGetQuoteOptArr'] : array(); if (in_array($option["code"], $param['availShiptoGetQuoteOptArr']) && !isset($option["requestXMLpath"])) { $attr = 'class="getShippingQuoteById" data-option_code="'.$option["code"].'"'; }else{ $attr = 'class="setTheShippingTypeById" data-option_code="'.$option["code"].'"'; } $response['html'] .= '
'; $response['html'] .= '
'; $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= '
'; // Add the hidden input fields here $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= ''; $response['html'] .= '

'; $availShipOptArr = is_array($param['availShipOptArr']) ? $param['availShipOptArr'] : array(); if (in_array($option["code"], $param['availShiptoGetQuoteOptArr']) && empty($option["requestXMLpath"])){ // Quote-needed express methods can have price 0 before RateShop runs. // Show Get Quote first instead of treating the 0 placeholder as free shipping. $response['html'] .= ' Get Quote'; } elseif (in_array($option["code"], $availShipOptArr) && ($option["price"] == 0 || empty($option["price"]))) { $response['html'] .= "FREE"; } else { $response['html'] .= "$" . number_format($option["price"], 2); } $response['html'] .= '

'; $response['html'] .= '
'; $cart_v2_shipping = number_format($cart['shipping_cost'], 2); $cart_subtotal = number_format($cart['cart_v2_subtotal'], 2); $cart_total = number_format($cart['total'], 2); $response['cart_details'] = [ 'cart_subtotal' => $cart_subtotal, 'cart_v2_shipping' => $cart_v2_shipping, 'cart_total' => $cart_total, ]; } } }else{ $orderByCalDays = $max_production_time + $time_in_transit + 1; $rush_shipping_date = date('M d', strtotime($rush_to_date)); $rush_shipping_date_next = date('d', strtotime('+1 day ' . $rush_to_date)); $shipping_date = date('M d', strtotime($to_date)); $shipping_date_next = date('d', strtotime('+1 day ' . $to_date)); $orderDate = date('M d, Y', strtotime($orderDate)); $shippingMArr = explode("-", $shipping_types_info["name"]); $estimeted_date = date('Y-m-d', strtotime($to_date)); // exit; $response = array('rush_to_date_time' => $rush_to_date_time, 'rush_to_date' => $rush_shipping_date." - ".$rush_shipping_date_next, 'to_date_time' => $to_date_time, 'to_date' => $shipping_date.' - '.$shipping_date_next, 'shippingMethod' => $shippingMArr[0], "estimeted_date" => $estimeted_date, "orderDate" => $orderDate, "orderByCalDays" => $orderByCalDays, "shipping_date" => $shipping_date); } } } return $response; } function getShippingDetails($reqArr = array(), $arrRes = array()){ global $pdo_db1; include_once("lib/modules.products.php"); $p = new products; $pro_id = 0; $product_sku = ''; if (isset($reqArr['product_type_id']) && $reqArr['product_type_id'] > 0) { $pro_id = $reqArr['product_type_id']; } elseif ( is_array($arrRes) && isset($arrRes['order_item_details_new']) && is_array($arrRes['order_item_details_new']) && isset($arrRes['order_item_details_new'][0]) && is_array($arrRes['order_item_details_new'][0]) && isset($arrRes['order_item_details_new'][0]['product_type']) && $arrRes['order_item_details_new'][0]['product_type'] != '' ) { $pro_id = $arrRes['order_item_details_new'][0]['product_type']; } elseif (is_array($arrRes) && isset($arrRes['prod_type']) && $arrRes['prod_type'] != '') { $pro_id = $arrRes['prod_type']; } if ( is_array($arrRes) && isset($arrRes['order_item_details_new']) && is_array($arrRes['order_item_details_new']) && isset($arrRes['order_item_details_new'][0]) && is_array($arrRes['order_item_details_new'][0]) && isset($arrRes['order_item_details_new'][0]['sku']) ) { $product_sku = $arrRes['order_item_details_new'][0]['sku']; } elseif (is_array($arrRes) && isset($arrRes['sku'])) { $product_sku = $arrRes['sku']; } $product_lead_time = (isset($reqArr['product_lead_time']) && $reqArr['product_lead_time'] > 0) ? $reqArr['product_lead_time'] : 0; if ($pro_id == 0) { return; } if($product_lead_time > 0){ $this->max_ships_in_days_val[] = $product_lead_time; } else{ if ($pro_id == 87) { $get_leade_time = $p->get_lead_time_from_all_tbl($product_sku, 2); $item_ship_time = $get_leade_time['max_lead_time']; if ($item_ship_time == '') { $ship_time = 2; } else { $ship_time = $item_ship_time; } $max_production_time = $ship_time; $this->max_ships_in_days_val[] = $max_production_time; } else { $this_product_typesnew = $pdo_db1->pquery("SELECT * FROM product_types WHERE id = '" . $pro_id . "' "); if (!isset($this_product_typesnew[0]) || !is_array($this_product_typesnew[0])) { return; } $this_product_typenew = $this_product_typesnew[0]; $a = explode("-", $this_product_typenew['ships_in_days']); if (isset($a[1])) { $item_ship_time = $a[1]; } else { $item_ship_time = $this_product_typenew['ships_in_days']; } $max_production_time = $item_ship_time; $this->max_ships_in_days_val[] = $max_production_time; } } } function checkAndSetHideRush($product_code, $detail_v2_new, $pdo_db1, $p, $value) { // echo "
";

        // print_r($detail_v2_new);exit;
    // Initialize session variable
     $is_hide_rush = false;
    
    $ship_param = array(
        'prod_code' => $product_code,
        'framecode' => isset($detail_v2_new['frame_code']) ? $detail_v2_new['frame_code'] : '',
        'mat_one_id' => isset($detail_v2_new['mat_one_id']) ? $detail_v2_new['mat_one_id'] : '',
        'mat_two_id' => isset($detail_v2_new['mat_two_id']) ? $detail_v2_new['mat_two_id'] : '',
        'glass_id' => isset($detail_v2_new['glass_id']) ? $detail_v2_new['glass_id'] : '',
        'hardware_id' => isset($detail_v2_new['hardware_one_id']) ? $detail_v2_new['hardware_one_id'] : '',
        'backing_id' => isset($detail_v2_new['backing']) ? $detail_v2_new['backing'] : ''
    );

 

    $business_days = $p->showLeadTimeToShip($ship_param, 'get_array');

    if (!empty($business_days['max_additional_lead_time']) && $business_days['max_additional_lead_time'] > 1) {
         $is_hide_rush = true;
    }else{
     // $is_hide_rush = true;
    }

 if ($product_code != 33 && (!isset($value['sku_base_products']) || $value['sku_base_products'] == 0)){
        if ($detail_v2_new['frame_id'] != '') {
           // echo "SELECT override_lead_time FROM new_frames WHERE id = '" . $detail_v2_new['frame_id'] . "'";exit;
            $this_new_frmes = $pdo_db1->pquery("SELECT override_lead_time FROM new_frames WHERE id = '" . $detail_v2_new['frame_id'] . "'");
            $override_lead_time = $this_new_frmes[0]['override_lead_time'];
            $explode_lead = explode("-", $shipsInDays[$product_code]['ships_in_days']);
            $lead_time1 = (int)$explode_lead[0] + $override_lead_time;
            $lead_time2 = (int)$explode_lead[1] + $override_lead_time;
            $leadTimeToShip = $lead_time1 . "-" . $lead_time2;
            if (!empty($this_new_frmes[0]['additional_lead_time']) && $this_new_frmes[0]['additional_lead_time'] > 1) {
                 $is_hide_rush = true;
            }
        }
    }

    if (isset($value['sku_base_products']) && $value['sku_base_products'] == '1') {
        $new_sku_value = $value['order_item_details_new'][0]['sku'];
        $query_get_product_display_name = "SELECT * FROM sku_base_products WHERE sku='$new_sku_value'";
        $result_get_product_display_name = $pdo_db1->pquery($query_get_product_display_name);
        $row_get_product_display_name = $result_get_product_display_name[0];
        $lead_time_sku = $row_get_product_display_name['lead_time'];

        if (!empty($lead_time_sku)) {
            $leadTimeToShipArr = explode('-', $lead_time_sku);
            if (!empty($leadTimeToShipArr[0]) && $leadTimeToShipArr[0] > 1) {
                $is_hide_rush= true;
            }
        }

        $leadTimeToShipArr = array();
        if ($value['frame_id'] != '') {
            $this_new_frmes = $pdo_db1->pquery("SELECT override_lead_time FROM new_frames WHERE id = '" . $value['frame_id'] . "'");
            if (!empty($this_new_frmes[0]['override_lead_time'])) {
                $leadTimeToShipArr[] = $this_new_frmes[0]['override_lead_time'];
            }
        }

         if (!empty($leadTimeToShipArr)) {
             $leadTimeToShip = max($leadTimeToShipArr) . ' days';
         }
        //echo "
Lead Time: " . $leadTimeToShip; } return $is_hide_rush; } function get_shipping_date($value, $p, $shipsInDays, $tools_status) { // ini_set('display_errors', '1'); // ini_set('display_startup_errors', '1'); // error_reporting(E_ALL); global $pdo_db1; $a = array(); $is_hide_rush = false; // Ensure $is_hide_rush is always initialized if (isset($value['sku_base_products']) && $value['sku_base_products'] == '1') { if($value['product_type'] == 87 || $value['product_type'] == 88){ // Get lead time from all tables $get_lead_time = $p->get_lead_time_from_all_tbl($value['sku'], 2); if (isset($get_lead_time['max_lead_time']) && isset($get_lead_time['min_lead_time'])) { $max_time = $get_lead_time['max_lead_time']; $min_time = $get_lead_time['min_lead_time']; } else { // Handle case where lead time is not retrieved correctly $max_time = 0; $min_time = 0; } // Query to get product display name $query_get_product_display_name = "SELECT * FROM sku_base_products WHERE sku='" . $value['sku'] . "'"; // echo"
===>";print_r($query_get_product_display_name);exit;
        $result_get_product_display_name = $pdo_db1->pquery($query_get_product_display_name);
        $lead_time_sku = isset($result_get_product_display_name[0]['lead_time']) ? $result_get_product_display_name[0]['lead_time'] : 0;
        $row_get_product_display_name = isset($result_get_product_display_name[0]['id']) ? $result_get_product_display_name[0]['id'] : 0;

        $ship_day = ($max_time == $min_time) ? $min_time : $min_time . '-' . $max_time;

        $shippingdays = $shipsInDays[$value['product_type']]['ships_in_days'];
        $leadTimeToShip = !empty($lead_time_sku) ? $lead_time_sku : $shippingdays;
        if (!empty($lead_time_sku) && $lead_time_sku > 1) {
            $_SESSION['is_hide_rush'] = true;
            $is_hide_rush = true; // Also update local variable
        }

        $ship_param = array(
            'prod_code' => $value['product_type'],
            'framecode' => $value['frame_code'],
            'mat_one_id' => $value['mat_one_code'],
            'mat_two_id' => $value['mat_two_code'],
            'glass_id' => $value['glass_id'],
            'hardware_id' => $value['hardware_one_id'],
            'backing_id' => $value['backing'],
            'sku_base_products' => '1',
            'sku_base_products_id' => $row_get_product_display_name
        );


        $leadTimeToShipArr = $p->showLeadTimeToShip($ship_param, 'get_array');
        $leadTimeToShip = !empty($leadTimeToShipArr['label']) ? $leadTimeToShipArr['label'] : $leadTimeToShipArr;
        if (!empty($leadTimeToShipArr['max_additional_lead_time']) && $leadTimeToShipArr['max_additional_lead_time'] > 1) {
            $is_hide_rush = true;
        }

        $a['ship_days'] = $leadTimeToShip;
        $a['is_hide_rush'] = $is_hide_rush;
    }
    else{
        if ($value['frame_id'] != '') {
           // echo "SELECT override_lead_time FROM new_frames WHERE id = '" . $detail_v2_new['frame_id'] . "'";exit;
            $this_new_frmes = $pdo_db1->pquery("SELECT override_lead_time FROM new_frames WHERE id = '" . $value['frame_id'] . "'");
            $override_lead_time = $this_new_frmes[0]['override_lead_time'];

    
            
            $leadTimeToShip = $override_lead_time;
            
        }

         $a['ship_days'] = $leadTimeToShip;
    }

    }else if ($value['product_type'] != 33 && (!isset($value['sku_base_products']) || $value['sku_base_products'] == 0)){

         $ship_param = array(
        'prod_code' => $value['product_type'],
        'framecode' => isset($value['frame_code']) ? $value['frame_code'] : '',
        'mat_one_id' => isset($value['mat_one_id']) ? $value['mat_one_id'] : '',
        'mat_two_id' => isset($value['mat_two_id']) ? $value['mat_two_id'] : '',
        'glass_id' => isset($value['glass_id']) ? $value['glass_id'] : '',
        'hardware_id' => isset($value['hardware_one_id']) ? $detail_v2_new['hardware_one_id'] : '',
        'backing_id' => isset($value['backing']) ? $value['backing'] : ''
    );

        $business_days = $this->showLeadTimeToShip($ship_param, 'get_array');

       //  echo "
".$value['product_type'];

        // print_r($ship_param);
        // echo "
"; // echo $business_days['lead_days']; $leadTimeToShip= is_array($business_days)?$business_days['lead_days']:$business_days; $a['ship_days'] = $leadTimeToShip; } else if (!isset($value['sku_base_products']) || $value['sku_base_products'] == 0){ if ($value['frame_id'] != '') { // echo "SELECT override_lead_time FROM new_frames WHERE id = '" . $detail_v2_new['frame_id'] . "'";exit; $this_new_frmes = $pdo_db1->pquery("SELECT override_lead_time FROM new_frames WHERE id = '" . $value['frame_id'] . "'"); $override_lead_time = $this_new_frmes[0]['override_lead_time']; $explode_lead = explode("-", $shipsInDays[$product_code]['ships_in_days']); $lead_time1 = (int)$explode_lead[0] + $override_lead_time; $lead_time2 = (int)$explode_lead[1] + $override_lead_time; $leadTimeToShip = $lead_time1 . "-" . $lead_time2; if (!empty($this_new_frmes[0]['additional_lead_time']) && $this_new_frmes[0]['additional_lead_time'] > 1) { $is_hide_rush = true; } } $a['ship_days'] = $leadTimeToShip; } else { $param = array( 'prod_code' => $value['product_type'], 'framecode' => $value['frame_code'], 'mat_one_id' => $value['mat_one_id'], 'mat_two_id' => $value['mat_two_id'], 'glass_id' => $value['glass_id'], 'hardware_id' => $value['hardware_one_id'], 'backing_id' => $value['backing'] ); // echo "
";

// print_r( $param);exit;
        $leadTimeToShip =  $this->getLeadTimeToShip($param);
        $a['ship_days'] = $leadTimeToShip;
        $a['is_hide_rush'] = $is_hide_rush;
    }



    return $a;
}


function getLeadTimeToShip($param){
//     ini_set('display_errors', '1');
// ini_set('display_startup_errors', '1');
// error_reporting(E_ALL);

    global $pdo_db1;
    $days="";
//$param['prod_code'];
//$param['framecode']
//       if($param['prod_code']=="79")
// {
//     echo "
";
//     print_r($param);
// }
    // echo "select out_of_stock_min_lead_time from lead_time where  product_id= '".$param['prod_code']."' and out_of_stock_min_lead_time > 0  order by id desc limit 1";

    // echo "
"; $res_leadtime = $pdo_db1->pquery("select out_of_stock_min_lead_time from lead_time where product_id= '".$param['prod_code']."' and out_of_stock_min_lead_time > 0 order by id desc limit 1"); $outofstock_leadTimeToShip = $res_leadtime[0]['out_of_stock_min_lead_time']; if(isset($param['sku_base_products']) && $param['sku_base_products']=='1') { $sku_base_query = "SELECT sbp.lead_time, pst.product_type_id, sbp.in_stock FROM sku_base_products sbp LEFT JOIN product_sub_type pst ON pst.id = sbp.product_sub_type_id WHERE sbp.id = '".$param['sku_base_products_id']."'"; $sku_base_info = $pdo_db1->pquery($sku_base_query); $sku_base_info = $sku_base_info[0]; $getinstockstatus = $this->getinstockstatus($sku_base_info['in_stock']); if ($sku_base_info['in_stock'] == '1' && $getinstockstatus == 1) { if (isset($sku_base_info['lead_time']) && $sku_base_info['lead_time'] > 0) { $leadTimeToShip = $sku_base_info['lead_time']; } else { $result=$this->getShipsInDays($sku_base_info['product_type_id']); $leadTimeToShip = $result[$sku_base_info['product_type_id']]['ships_in_days']; } } else { $leadTimeToShip = 'Discontinued'; } if(!empty($param['mat_one_id'])){ $query ="SELECT name,in_stock FROM mats WHERE code = '".$param['mat_one_id']."' limit 1 "; $result1 = $pdo_db1->pquery($query); $row = $result1[0]; $in_stock = $row['in_stock']; if($in_stock == 2) { return $leadTimeToShip = $outofstock_leadTimeToShip; } if($in_stock == 0) { return $leadTimeToShip = ' Mat One '.$row['name'].' is Discontinued'; } } return $leadTimeToShip; } else if(isset($param['prod_code']) && $param['prod_code']!='') { if($param['framecode']=='') { if(!empty($param['mat_one_id_new'])) { $get_mat_name = $param['mat_one_id_new']; $query ="SELECT in_stock FROM mats WHERE code = '".$get_mat_name ."' ORDER BY `color_order_list` "; $result1 = $pdo_db1->pquery($query); $row = $result1[0]; $in_stock = $row['in_stock']; // $getinstockstatus = $this->getinstockstatus($instock['in_stock']); $getinstockstatus = $this->getinstockstatus($in_stock); if($in_stock == 2 && $getinstockstatus == 1) { return $leadTimeToShip = $outofstock_leadTimeToShip; } if($in_stock == 0 && $getinstockstatus == 0) { return $leadTimeToShip = 'Discontinued'; } if($in_stock == 1 && $getinstockstatus == 1) { $result=$this->getShipsInDays($param['prod_code']); return $leadTimeToShip = $result[$param['prod_code']]['ships_in_days']; } }else{ if(!empty($param['mat_one_id'])){ $query ="SELECT name,in_stock FROM mats WHERE id = '".$param['mat_one_id']."' limit 1 "; $result1 = $pdo_db1->pquery($query); $row = $result1[0]; // if($param['prod_code']=="79") // { // echo "
";
//     echo ("SELECT name,in_stock FROM mats WHERE code =  '".$param['mat_one_id']."'  limit 1");exit;
// }
                     $in_stock = $row['in_stock'];
                     if($in_stock == 2)
                     {
                       return $leadTimeToShip = $outofstock_leadTimeToShip;
                     }
                      if($in_stock == 0)
                     {
                       return $leadTimeToShip = ' Mat One '.$row['name'].' is Discontinued';
                     }
                }

                if(!empty($param['mat_two_id'])){

                     $query ="SELECT name,in_stock FROM mats WHERE id =  '".$param['mat_two_id']."'  limit 1 ";  
                     $result1 = $pdo_db1->pquery($query);
                     $row = $result1[0];
                     $in_stock = $row['in_stock'];
                     if($in_stock == 2)
                     {
                       return $leadTimeToShip = $outofstock_leadTimeToShip;
                     }
                      if($in_stock == 0)
                     {
                       return $leadTimeToShip = ' Mat Two '.$row['name'].' is Discontinued';
                     }
                    
                }

                 if(!empty($param['glass_id'])){
                    // $query ="SELECT in_stock,name FROM glaze WHERE id =  '".$param['glass_id']."'  limit 1 ";  

                    if($param['prod_code'] == 36)
                    {
                     $query ="SELECT count(id) as cnt FROM glaze_oval WHERE glaze_id =  '".$param['glass_id']."'  limit 1 "; 
                     $result1 = $pdo_db1->pquery($query);
                     $row_count = $result1[0]['cnt'];

                     if($row_count == 1)
                     {
                        $query ="SELECT in_stock,name FROM glaze_oval WHERE glaze_id =  '".$param['glass_id']."'  limit 1 "; 
                     }else{
                        $query ="SELECT in_stock,name FROM glaze WHERE id =  '".$param['glass_id']."'  limit 1 "; 
                     }

                    }else{
                        $query ="SELECT in_stock,name FROM glaze WHERE id =  '".$param['glass_id']."'  limit 1 "; 
                    }

                     $result1 = $pdo_db1->pquery($query);
                     $row = $result1[0];
                     $in_stock = $row['in_stock'];
                     if($in_stock == 2)
                     {
                       return $leadTimeToShip = $outofstock_leadTimeToShip;
                     }
                      if($in_stock == 0)
                     {
                       return $leadTimeToShip = ' Glass is '.$row['name'].' Discontinued';
                     }
                }
                $result=$this->getShipsInDays($param['prod_code']);
                return $leadTimeToShip = $result[$param['prod_code']]['ships_in_days'];
             }

        }else
        {
            // Commented below line and added condition because it shows discontinued message
            // $instock_res=$pdo_db1->query("Select in_stock from new_frames where code='".$param['framecode']."' LIMIT 1");
            if($param['prod_code'] == '36'){
                $instock_res=$pdo_db1->query("Select in_stock from pre_made_sku_products where id='".$param['framecode']."' LIMIT 1");
            }
            else{
// echo __LINE__;
// echo "Select in_stock from new_frames where code='".$param['framecode']."' LIMIT 1 ";exit;

                $instock_res=$pdo_db1->query("Select in_stock from new_frames where code='".$param['framecode']."' LIMIT 1");
            }
            if($pdo_db1->pdo_num_rows($instock_res) > 0)
            {
                $instock=$instock_res[0];
                 $getinstockstatus = $this->getinstockstatus($instock['in_stock']);
                if($instock['in_stock']==1 && $getinstockstatus == 1)
                {

                     if(!empty($param['mat_one_id'])){
                         $query ="SELECT name,in_stock FROM mats WHERE id =  '".$param['mat_one_id']."'  limit 1 "; 
                         $result1 = $pdo_db1->pquery($query);
                         $row = $result1[0];
                         $in_stock = $row['in_stock'];
                         if($in_stock == 2)
                         {
                           return $leadTimeToShip = $outofstock_leadTimeToShip;
                         }
                          if($in_stock == 0)
                         {
                           return $leadTimeToShip = ' Mat One '.$row['name'].' is Discontinued';
                         }
                    }

                    if(!empty($param['mat_two_id'])){

                         $query ="SELECT name,in_stock FROM mats WHERE id =  '".$param['mat_two_id']."'  limit 1 ";  
                         $result1 = $pdo_db1->pquery($query);
                         $row = $result1[0];
                         $in_stock = $row['in_stock'];
                         if($in_stock == 2)
                         {
                           return $leadTimeToShip = $outofstock_leadTimeToShip;
                         }
                          if($in_stock == 0)
                         {
                           return $leadTimeToShip = ' Mat Two '.$row['name'].' is Discontinued';
                         }
                        
                    }

                     if(!empty($param['glass_id'])){
                         $query ="SELECT in_stock,name FROM glaze WHERE id =  '".$param['glass_id']."'  limit 1 ";  
                         $result1 = $pdo_db1->pquery($query);
                         $row = $result1[0];
                         $in_stock = $row['in_stock'];
                         if($in_stock == 2)
                         {
                           return $leadTimeToShip = $outofstock_leadTimeToShip;
                         }
                          if($in_stock == 0 && $param['prod_code'] != '36')
                         {
                           return $leadTimeToShip = ' Glass is '.$row['name'].' Discontinued';
                         }
                    }

                    $result=$this->getShipsInDays($param['prod_code']);
                    $leadTimeToShip = $result[$param['prod_code']]['ships_in_days'];
                    if($_GET['debug_leadtime_data1'] == 1){
                        echo "
result:
";
                        print_r($result);
                        echo "
"; echo "
param:
";
                        print_r($param);
                        echo "
"; echo "
leadTimeToShip:00 ".$leadTimeToShip; } }elseif(($instock['in_stock']==2 || $instock['in_stock']==0) && $getinstockstatus == 1) { $result=$this->getShipsInDays($param['prod_code']); $manufacture_res = $pdo_db1->query("SELECT manufactur_order_due_date AS due_date, code as typecode from new_frames where code='".$param['framecode']."' and manufactur_order_due_date > CURDATE()"); if($pdo_db1->pdo_num_rows($manufacture_res) > 0){ $due_date = $manufacture_res[0]; $datetime1 = new DateTime(date("Y-m-d",strtotime($due_date['due_date']))); $datetime2 = new DateTime(date("Y-m-d")); $interval = $datetime1->diff($datetime2); $days= $interval->format('%a'); } else { if($instock['in_stock']==0){ $leadTimeToShip = "Discontinued"; return $leadTimeToShip; } else { return $leadTimeToShip = $outofstock_leadTimeToShip; } } //due_date; /************Remove '-' if present and get the max day from that string ********************/ $max_day=0; if(strpos($result[$param['prod_code']]['ships_in_days'] ,'-')!='') { $max_day_arr=explode('-',$result[$param['prod_code']]['ships_in_days']); if(trim($max_day_arr[0]) > trim($max_day_arr[1])) {$max_day = trim($max_day_arr[0]);} else{$max_day = trim($max_day_arr[1]);} } else{$max_day=trim($result[$param['prod_code']]['ships_in_days']);} /************Remove '-' End here********************/ if($days==""){$leadTimeToShip = "Discontinued";} else{$leadTimeToShip=$max_day+7+$days;} }else{ if($instock['in_stock']==2){ $leadTimeToShip = "Out of Stock"; }else{ $leadTimeToShip = "Discontinued"; } } }else { $leadTimeToShip = "Discontinued"; } if($_GET['debug_leadtime_data1'] == 1){ echo "
leadTimeToShip:01 ".$leadTimeToShip; } return $leadTimeToShip; //Ships in 2-4 Business Days } }else{ $leadTimeToShip = "Discontinued"; } } //end function function getShipsInDays($productCode = 0) { global $pdo_db1; $sql = "SELECT id, "; $sql .=" CASE WHEN ships_in_days IS NULL THEN '2-3' ELSE ships_in_days END 'ships_in_days' "; $sql .=' FROM product_types '; $sql .= ($productCode ? 'WHERE id= '.$productCode:'') ; $resultProductTypes = $pdo_db1->query($sql); foreach($resultProductTypes as $rowProductType) { $productTypesShipping[$rowProductType['id']] = $rowProductType; } return $productTypesShipping; } function getinstockstatus($param){ global $pdo_db1; $search_query1 = "select * from add_to_cart_btn_state where in_stock_value ='".$param."'"; $search_result1 = $pdo_db1->pquery($search_query1); $row_get_details = $search_result1[0]; return $row_get_details['allow_purchase']; } function showLeadTimeToShip($param){ $leadTimeToShip = $this->getLeadTimeToShip($param); if($leadTimeToShip == "Discontinued") { return "This frame ".$param['framecode']." is discontinued"; }else { return $leadTimeToShip; //Ships in 2-4 Business Days } } } 16x20 Picture Frames, 16x20 Poster Frames - ArtToFrame

Home Decor

PERSONALIZE

Custom Sizes-

Size based on your artwork.

Inches
Centimeters
Width
 cm
Height
 cm

Your size will be converted to inches on the search and product pages.

Width
Height

POPULAR SIZES-

POPULAR OPENINGS SIZES-

IMAGES OPENINGS-

MAT COLOR

-

Frame Width-

Style-

PERSONALIZE

SHOP BY SIZE

-

COLLECTIONS -

PATTERN COLORS -

FRAME FINISH & MATERIAL -

CATEGORIES-

CATEGORIES-

PRIVACY-

DECORATION -

LAMP TYPE

-

SHADE SIZE

-

PRINT

-

SHADE COLORS

-

STYLES

-

LAMP STAND

-

CHOOSE YOUR NUMBER OF OPENINGS SEE ALL

What color frame are you looking for

Loading Result...
X

Message information