Code:
<?php
/**
* @package shippingMethod
* @copyright Copyright 2016 BILSI Inc
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: Author: Bryan Kowalchuk
*/
/**
* bilsi
*
*/
class bilsi extends base {
/**
* $code determines the internal 'code' name used to designate "this" payment module
*
* @var string
*/
var $code;
/**
* $title is the displayed name for this payment method
*
* @var string
*/
var $title;
/**
* $description is a soft name for this payment method
*
* @var string
*/
var $description;
/**
* module's icon
*
* @var string
*/
var $icon;
/**
* $enabled determines whether this module shows or not... during checkout.
*
* @var boolean
*/
var $enabled;
/**
* Constructor
*
* @return BILSI
*/
function __construct() {
global $order, $db;
$this->code = 'bilsi';
$this->title = MODULE_SHIPPING_BILSI_TEXT_TITLE;
$this->description = MODULE_SHIPPING_BILSI_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_BILSI_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_BILSI_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_BILSI_TAX_BASIS;
$shippingmarkup = 1.4;
/*
// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_BILSI_STATUS == 'True') ? true : false);
}
if ($this->enabled) {
// check MODULE_SHIPPING_BILSI_HANDLING_METHOD is in
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_BILSI_HANDLING_METHOD'");
if ($check_query->EOF) {
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_BILSI_HANDLING_METHOD', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
}
}
*/
$this->enabled = true;
/*
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_BILSI_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
where geo_zone_id = '" . MODULE_SHIPPING_BILSI_ZONE . "'
and zone_country_id = '" . (int)$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;
}
}
*/
}
/**
* Obtain quote from shipping system/calculations
*
* @param string $method
* @return array
*/
function quote($method = '') {
global $order, $shipping_weight, $shipping_num_boxes;
$total_weight_units = $shipping_weight;
// customer details
$street_address = $order->delivery['street_address'];
$street_address2 = $order->delivery['suburb'];
$city = $order->delivery['city'];
$state = zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], '');
// if ($state == "QC") $state = "PQ";
$postcode = str_replace(array(' ', '-'), '', $order->delivery['postcode']);
if(isset($order->delivery['country']['iso_code_2'])) {
$country_id = $order->delivery['country']['iso_code_2'];
}
else {
$country_id = $this->country_iso($order->delivery['country']);
}
if ($method != '')
{
$this->quotes = array('id' => $this->code , 'module' => 'BILSI Shipping');
$methods = array('id' => $_SESSION['shipping']->id , 'title' => 'Method: '.$method , 'cost' => 100000);
return $quotes;
}
/*
$webxmlrequest = '<?xml version="1.0" encoding="utf-8"?>
<ShipmentRateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<User_Name>test</User_Name>
<Password>test</Password>
<Client_Id>test</Client_Id>
<Receiver>
<City>'.$city.'</City>
<State_Province>'.$state.'</State_Province>
<Postal_Zip_Code>'.$postcode.'</Postal_Zip_Code>
<Country>'.$country_id.'</Country>
</Receiver>
<Sender>
<SenderId>0</SenderId>
<City>MISSISSAUGA</City>
<State_Province>ON</State_Province>
<Postal_Zip_Code>L5L5Y5</Postal_Zip_Code>
<Country>CA</Country>
</Sender>
<Shipment_Info>
<Wo_Type>SMP</Wo_Type>
<No_Packages>1</No_Packages>
<No_OverWeight_Packages>0</No_OverWeight_Packages>
<No_Ltl_Skids>0</No_Ltl_Skids>
<Total_Weight>'.$shipping_weight.'</Total_Weight>
<Total_Dim_Weight>0</Total_Dim_Weight>
</Shipment_Info>
<SignatureRequired>false</SignatureRequired>
<IsResidential>false</IsResidential>
<DeclaredValue>0</DeclaredValue>
</ShipmentRateRequest>';
*/
//Object for use later in postback to Bilsi
$orderRequest['request'] = array( 'User_Name'=>'test',
'Password'=>'test',
'Client_Id'=>'test',
'Po_Number'=> '0',
'Appointment_Required'=> 'No',
'Appointment_Notes'=>'',
'Consignee_Info' => array( 'Consignee_Id'=> 0,
'Name'=>$_SESSION['customer_first_name'].' '.$_SESSION['customer_last_name'],
'Address_1'=>$street_address,
'Address_2'=>$street_address2,
'City'=>$city,
'State_Province'=>$state,
'Postal_Zip_Code'=>$postcode,
'Country'=>$country_id,
'Phone'=>'',
'Email'=>$_SESSION['customer_email_address'],
'ValidateAddressFlag'=>0),
'Shipment_Info' => array( 'Wo_Type'=>'SMP',
'No_Packages'=> $shipping_num_boxes,
'No_OverWeight_Packages'=>0,
'No_Ltl_Skids'=> 0,
'Total_Weight'=> $shipping_weight,
'Total_Dim_Weight'=> 0),
'GenerateShippingLabel'=>0,
'ShipFromAddressId'=>0,
'ServiceType'=>101,
'SignatureRequired'=>0,
'IsResidential'=>'true',
'DeclaredValue'=>0,
'ReferenceNumber'=>0);
//Add all the product info
/*
-<s:sequence>
<s:element name="ProductNumber" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="AlternateReference" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="Description" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="GeneralDescription" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="UnitPrice" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Weight" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Length" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Height" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Width" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="HSCode" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="CountryOfOrigin" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="CurrencyId" type="s:int" maxOccurs="1" minOccurs="1"/>
<s:element name="SystemOfUnitsId" type="s:int" maxOccurs="1" minOccurs="1"/>
<s:element name="ClientEnterHSCode" type="s:boolean" maxOccurs="1" minOccurs="1"/>
<s:element name="NAFTAApplied" type="s:boolean" maxOccurs="1" minOccurs="1"/>
<s:element name="Quantity" type="s:int" maxOccurs="1" minOccurs="1"/>
</s:sequence>
Product
[0] => Array
(
[id] => 15
[category] => 14
[name] => Frantic Linked
[model] => DVD-FRAN
[image] => dvd/frantic.gif
[price] => 35.0000
[quantity] => 1
[weight] => 7
[final_price] => 35
[onetime_charges] => 0
[tax_class_id] => 1
[attributes] =>
[attributes_values] =>
[products_priced_by_attribute] => 0
[product_is_free] => 0
[products_discount_type] => 0
[products_discount_type_from] => 0
[products_virtual] => 0
[product_is_always_free_shipping] => 0
)
*/
$products = $_SESSION['cart']->get_products();
foreach($products as $product)
{
// echo 'Product: '.$product['id'];
$nextproduct['ProductNumber'] = $product['id'];
$nextproduct['Description'] = $product['name'];
$nextproduct['UnitPrice'] = $product['price'];
$nextproduct['Weight'] = $product['weight'];
$nextproduct['Length'] = 0;
$nextproduct['Height'] = 0;
$nextproduct['Width'] = 0;
$nextproduct['CurrencyId'] = 0;
$nextproduct['SystemOfUnitsId'] = 0;
$nextproduct['ClientEnterHSCode'] = 0;
$nextproduct['NAFTAApplied']=0;
$nextproduct['Quantity']=$product['quantity'];
$nextproduct['CountryOfOrigin']='CN';
$nextproduct['HSCode'] = '9999999999';
$orderRequest['request']['Shipment_Info']['Products'][] = $nextproduct;
}
$webrequest['request'] = array( 'User_Name'=>'test',
'Password'=>'test',
'Client_Id'=>'test',
'Receiver' => array('City'=>$city,
'State_Province'=>$state,
'Postal_Zip_Code'=>$postcode,
'Country'=>$country_id),
'Sender' => array('SenderId'=>'0',
'City'=>'MISSISSAUGA',
'State_Province'=>'ON',
'Postal_Zip_Code'=>'L5L5Y5',
'Country'=>'CA'),
'Shipment_Info' => array('Wo_Type'=>'SMP',
'No_Packages'=> $shipping_num_boxes,
'No_OverWeight_Packages'=>0,
'No_Ltl_Skids'=> 0,
'Total_Weight'=> $shipping_weight,
'Total_Dim_Weight'=> 0),
'SignatureRequired'=>'false',
'IsResidential'=>'true',
'DeclaredValue'=>0);
$url = 'http://www.bilsi.com/Freight/Services/ShipmentRateService.asmx?WSDL';
$params = array('trace' => 1, 'soap_version' => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new SoapClient($url, $params);
try{
$result = $client->GetRate($webrequest);
}
catch (Exception $e)
{
$message = 'Error in processing transaction.<br /><br />';
$message .= $response->Notifications->Severity;
$message .= ': '.$e->getMessage();
$message .= $response->Notifications->Message . '<br />';
$quotes = array('module' => $this->title,
'error' => $message);
echo 'Caught exception: ', $e->getMessage();
return $quotes;
}
//echo '<!-- Request: ';
//print_r($webrequest['request']);
echo '<!-- Shipping: ';
print_r($_SESSION['shipping']);
echo '-- Method';
echo $method;
echo '<!-- Result: ';
print_r($result);
/*
$ratecount = count($result->GetRateResult->ShipmentRates->ShipmentRate);
//Add the markup
//$shiprate = $shiprate * $shippingmarkup;
$this->quotes = array('id' => $this->code,
'module' => 'BILSI Shipping',
'methods' => array(array('id' => 'Air101',
'title' => $result->GetRateResult->ShipmentRates->ShipmentRate[0]->ServiceDescription,
'cost' => $result->GetRateResult->ShipmentRates->ShipmentRate[0]->Total_Charge),
array('id' => 'Ground102',
'title' => $result->GetRateResult->ShipmentRates->ShipmentRate[1]->ServiceDescription,
'cost' => $result->GetRateResult->ShipmentRates->ShipmentRate[1]->Total_Charge)));
echo '-- Quotes: ';
print_r( $this->quotes);
*/
$shiprates = $result->GetRateResult->ShipmentRates->ShipmentRate;
if (is_array($shiprates) && sizeof($shiprates) > 0)
{
$this->quotes = array('id' => $this->code , 'module' => 'BILSI Shipping');
$methods = array();
for ($i = 0; $i < sizeof($shiprates); $i ++)
{
// list ($type, $cost) = each($shiprates[$i]);
// $type = html_entity_decode($type);
// if ($this->cp_online_handling == true)
// {
// if ($method == '' || $method == $type)
// {
// $methods[] = array('id' => $type , 'title' => $type , 'cost' => $cost + $this->handling_cp);
// }
// } else
// {
// if ($method == '' || $method == $type)
$methods[$i] = array('id' => $shiprates[$i]->ServiceType , 'title' =>$shiprates[$i]->ServiceDescription , 'cost' => $shiprates[$i]->Total_Charge + $i);
}
}
// if ($this->tax_class > 0)
// {
// $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
// }
$this->quotes['methods'] = $methods;
echo '-- Quotes: ';
print_r( $this->quotes);
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);
// echo '<!-- Quotes: ';
// echo 'Products: ';
// print_r($products);
// echo 'Order: ';
// print_r($order);
// echo 'Request: ';
// print_r($_SESSION);S
// print_r($orderRequest);
//print_r($this->quotes);
//print_r($_SESSION['shipping']);
// print_r($rateobj);
echo '-- Bilsi Shipping Object -- ';
//print_r($result->GetRateResult->ShipmentRates->ShipmentRate[0]->Total_Charge);
//print_r($orderRequest);
echo ' -- Shipping Rate: '.$shiprate;
// print_r($result);
echo ' -->';
//Create a session variable that can be retrived on the final order page
$_SESSION['Bilsi_shipping'] = $orderRequest;
return $this->quotes;
}
/**
* Check to see whether module is installed
*
* @return boolean
*/
function check() {
/*
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_BILSI_STATUS'");
$this->_check = $check_query->RecordCount();
}*/
return true;
}
/**
* Install the shipping module and its configuration settings
*
*/
function install() {
global $db;
}
/**
* Remove the module and all its settings
*
*/
function remove() {
global $db;
}
/**
* Internal list of configuration keys used for configuration of the module
*
* @return array
*/
function keys() {
return array('MODULE_SHIPPING_BILSI_STATUS', 'MODULE_SHIPPING_BILSI_COST', 'MODULE_SHIPPING_BILSI_HANDLING', 'MODULE_SHIPPING_BILSI_HANDLING_METHOD', 'MODULE_SHIPPING_BILSI_TAX_CLASS', 'MODULE_SHIPPING_BILSI_TAX_BASIS', 'MODULE_SHIPPING_BILSI_ZONE', 'MODULE_SHIPPING_BILSI_SORT_ORDER');
}
}
?>
Bookmarks