PHP Code:
class IconSignit {
var $code, $title, $description, $icon, $enabled;
function __construct() {
$this->code = 'IconSignit';
$this->title = MODULE_SHIPPING_KISICONSIGNIT_TEXT_TITLE;
$this->description = MODULE_SHIPPING_KISICONSIGNIT_TEXT_DESCRIPTION;
$this->sort_order = defined('MODULE_SHIPPING_KISICONSIGNIT_SORT_ORDER') ? MODULE_SHIPPING_KISICONSIGNIT_SORT_ORDER : null;
if (null === $this->sort_order) return false;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_KISICONSIGNIT_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_KISICONSIGNIT_TAX_BASIS;
// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = (MODULE_SHIPPING_KISICONSIGNIT_STATUS == 'True');
}
$this->update_status();
}
/**
* Perform various checks to see whether this module should be visible
*/
function update_status() {
global $order, $db;
if (!$this->enabled) return;
if (IS_ADMIN_FLAG === true) return;
if ((int)MODULE_SHIPPING_KISICONSIGNIT_ZONE > 0) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_KISICONSIGNIT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
function quote($method = '') {
global $order,$db,$_SESSION; $varsicon = ""; $items =[]; $resapi = $db->Execute( "select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_KISICONSIGNIT_APIURL' limit 1" ); $APIURL = $resapi->fields['configuration_value']; $APIURLFULL = $APIURL; $resapi1 = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_KISICONSIGNIT_APITOKEN' limit 1"); $wf1 = $resapi1->fields['configuration_value']; $APITOKEN = $wf1;
$resapi2 = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_KISICONSIGNIT_POSTCODE' limit 1"); $wf2 = $resapi2->fields['configuration_value']; $LocationPostcode = $wf2;
$resapi3 = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_KISICONSIGNIT_SUBURB' limit 1" ); $wf3 = $resapi3->fields['configuration_value']; $LocationTown = $wf3;$addrid=$_SESSION['customer_default_address_id'];if($_SESSION['cart_address_id'])$addrid=$_SESSION['cart_address_id'];
$resapi4 = $db->Execute("select entry_postcode,entry_city from address_book WHERE customers_id= '".$_SESSION['customer_id']."'and address_book_id='".$addrid."' limit 1" ); $DeliveryTown = $resapi4->fields['entry_city']; $DeliveryPostcode = $resapi4->fields['entry_postcode']; $shipme = $_SESSION['cart']->get_products(); // Pack whats left Note: override must nullify weight for items already processed - including all! // no custom packing, use server code for ($index = 0; $index < count($shipme); $index++) { // loop through cart populating items array // $id = $shipme[$index]['id']; $type_query = "select * from " . TABLE_PRODUCTS . " where products_id='$id' limit 1 "; $type = $db->Execute($type_query); if ($type->fields['products_sweight'] > 0) { if(!$type->fields['products_slength']) $type->fields['products_slength']=160; if(!$type->fields['products_swidth']) $type->fields['products_swidth']=160; if(!$type->fields['products_sheight']) $type->fields['products_sheight']=160; if(!$type->fields['products_sweight']) $type->fields['products_sweight']=160; if($type->fields['products_dang']==1) $danggoods=1; $Items[] = array( 'item_code' => $type->fields['products_model'], 'item_desc' => 'carton', 'item_qty' => $shipme[$index]['quantity'], 'item_length' => $type->fields['products_slength'], 'item_width' => $type->fields['products_swidth'], 'item_height' => $type->fields['products_sheight'], 'item_weight' => $type->fields['products_weight'], 'item_palletised' => $type->fields['products_spallet'] ) ; $i=0; $itemlist.="'Items[".$index."][item_code]' => '".$type->fields['products_model']."','Items[".$index."][item_desc]' => 'Carton','Items[".$index."][item_qty]' => '".$shipme[$index]['quantity']."','Items[".$index."][item_length]' => '".$shipme[$index]['length']."','Items[".$index."][item_width]' => '".$shipme[$index]['width']."','Items[".$index."][item_height]' => '".$shipme[$index]['height']."','Items[".$index."][item_weight]' => '".$shipme[$index]['weight']."','Items[".$index."][item_palletised]' => '0'"; // Save these in case of error - We use them to calculate static rates // // $parcelWeight += $products_weight * $shipme[$index]['quantity']; $parcelQty += $shipme[$index]['quantity'] ; $orderValue += $shipme[$index]['price'] ; $parcelWeight += $type->fields['products_weight'] * $shipme[$index]['quantity']; $parcelQty += $shipme[$index]['quantity']; $orderValue += $shipme[$index]['price']; } } // next item /* array ( 0 => array ( 'item_code' => 'CE0', optional 'item_desc' => '', optional 'item_qty' => '1', Required with only numerical 'item_length' => '50', Required with only numerical 'item_width' => '30', Required with only numerical 'item_height' => '50', Required with only numerical 'item_weight' => '10', Required with only numerical 'item_palletised' => '0', Required with only (0/1) ) { "ApiUrl": Give APIURL, "ApiToken": Give "DeliveryTown": " "DeliveryPostcode": " "IsDangerousGoods": " "IsResidential": " "IsSenderResidential": " "IsTailgate": " */ /* echo $APIURL."<br />"; echo $APITOKEN."<br />"; echo $LocationPostcode ."<br />"; echo $LocationTown ."<br />"; echo $DeliveryPostcode ."<br />"; echo $DeliveryTown ."<br />"; print_r($shipme); */ //print_r($_SESSION); //exit; // package created, continue unless zero weight // // if ($parcelWeight == 0) { // $this->enabled = false; // return; // } // $restrain = (MODULE_SHIPPING_OZPOST_RESTRAIN_DIMS == "Yes") ? "yes" : ""; // save dimensions for display purposes on quote form (this way we don't need to hack another system file) //$parcelWeight = 930 ;;// $_SESSION['parcelweight'] = $parcelWeight / 1000; $_SESSION['parcelweight'] = $parcelWeight ; // Do some prep work to create the query string .. // convert cm to mm 'cos thats what the server uses // $parcelWidth = $parcelWidth * 10; $parcelHeight = $parcelHeight * 10; $parcelLength = $parcelLength * 10; // $fromcode = MODULE_SHIPPING_OZPOST_ORIGIN_ZIP; // Set destination code ( postcode if AU, else 2 char iso country code ) if ($dest_country == "AU") { $dcode = $topcode; } else { $dcode = $dest_country; if (isset($_POST['destSuburb'])) { unset($_POST['destSuburb']); $order->delivery['suburb'] = null; $order->delivery['city'] = null; } } /* $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 0); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1);curl_setopt($ch,CURLOPT_CUSTOMREQUEST , 'POST'); if (is_array($items)) { //curl_setopt($ch, CURLOPT_POST, true); // $varsicon="ApiUrl=".$APIURL."&ApiToken=".$APITOKEN."&DeliveryTown=".$DeliveryTown."&DeliveryPostcode=".$DeliveryPostcode."&LocationTown=".$LocationTown."&LocationPostcode=".$LocationPostcode."&IsDangerousGoods=0&IsResidential=0"; $varsicon1 = " 'Items' =>".json_encode($items); $varsicon="['ApiUrl' => '".$APIURL."','ApiToken' => '".$APITOKEN."','DeliveryTown' => '".$DeliveryTown."','DeliveryPostcode' => '".$DeliveryPostcode."','PickupTown' => '".$LocationTown."','PickupPostcode' => '".$LocationPostcode."','IsDangerousGoods' => '0','IsResidential' => '0','IsSenderResidential' => '0','IsTailgate' => '0',".$itemlist."]"; echo $varsicon; curl_setopt($ch, CURLOPT_POSTFIELDS, "$varsicon"); }//echo $varsicon; curl_setopt($ch, CURLOPT_URL, "https://kis9.iconsignit.com.au/api/getconsignrate"); $data = curl_exec($ch); $error1 = curl_error($ch); $commInfo = curl_getinfo($ch); curl_close($ch); echo $data.$error1; */$curl = curl_init();
//print_r($Items);//echo "DSfdsf".$Items[0]['item_code']; $testvar = ['ApiUrl' => $APIURL,'ApiToken' => $APITOKEN,'DeliveryTown' => $DeliveryTown,'DeliveryPostcode' => $DeliveryPostcode,'PickupTown' => $LocationTown,'PickupPostcode' => $LocationPostcode,'IsDangerousGoods' => $danggoods ,'IsResidential' => '0','IsSenderResidential' => '0','IsTailgate' => '0','Items[0][item_code]' => $Items[0]['item_code'],'Items[0][item_desc]' => $Items[0]['item_desc'],'Items[0][item_qty]' => $Items[0]['item_qty'],'Items[0][item_length]' => $Items[0]['item_length'],'Items[0][item_width]' => $Items[0]['item_width'],'Items[0][item_height]' => $Items[0]['item_height'],'Items[0][item_weight]' => $Items[0]['item_weight'],'Items[0][item_palletised]' => $Items[0]['item_palletised']];
curl_setopt_array($curl, array(CURLOPT_URL => 'https://kis9.iconsignit.com.au/api/getconsignrate',CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => '',CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => 'POST',CURLOPT_POSTFIELDS => $testvar,));
$responset = curl_exec($curl); curl_error($curl);curl_close($curl); // include "./testicon1.php"; //echo $responset;
$json_array=json_decode($responset,true); $carriers_result=$json_array['result'];// print_r($carriers_result); // while(list($key,$val)=each($carriers_result)){
foreach ($carriers_result as $key => $val) {
$methods[] = array(
'id' => $val['QuoteRateID'],
'title' => $val['carrier_nm'] ." - " .$val['service_nm']." ETA - ".$val['ETA_DAY'] .' days', // 'Display' => $val['carrier_nm'] ." - " .$val['service_nm']." ETA - ".$val['ETA_DAY'] .' days', 'cost' => $val['total_charge'] ); } // exit; //print_r($methods);
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_KISICONSIGNIT_TEXT_TITLE, 'methods' => $methods );
if ($this->tax_class > 0) {
// $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
return $this->quotes;
}
Bookmarks