Example #1
0
 function get_product_shipping($id, $order_quantity)
 {
     if (isAjax()) {
         $rows = get_quantities();
         $dim = $this->products_model->get_product_dimensions($id);
         $temp1 = array('"', 'Fermé', 'Ouvert', 'Open', 'Closed', ',');
         $temp2 = array('', '', '', '', '', '.');
         $dimensions = explode('x', str_replace($temp1, $temp2, $dim[0]->dimension));
         define('CP_SERVER', 'sellonline.canadapost.ca');
         define('CP_PORT', 30000);
         define('MERCHANT_CPCID', 'CPC_GROUPE_VSRG');
         //define('MERCHANT_CPCID', 'CPC_ERLIK');
         $cp = new CanadaPost($this->session->userdata['lang']);
         $cp->addItem($quantity = 1, $weight = intval($rows[$order_quantity]) / 100, $length = 1, $width = floatval($dimensions[0]), $height = floatval($dimensions[1]), $description = 'Test');
         $cp->getQuote('Montréal', 'Québec', 'Canada', 'H1P 2X8');
         if ($cp->error_message) {
             echo json_encode(array('error', $cp->error_message));
         } else {
             $shipping_methods = $cp->shipping_methods;
             if ($this->session->userdata['lang'] == 'fr') {
                 $shipping_methods[1]['name'] = "Colis accélérés ";
             }
             echo json_encode($shipping_methods);
         }
     }
 }
Example #2
0
 function sendRequest($address, $orderItems)
 {
     $rates = array();
     require_once dirname(__FILE__) . '/shipping_canada/canadapost.php';
     $key = $this->params->get('key');
     $canadaPost = new CanadaPost($key);
     foreach ($orderItems as $item) {
         $product = JTable::getInstance('Products', 'TiendaTable');
         $product->load($item->product_id);
         $description = strip_tags($product->product_description);
         if ($product->product_ships) {
             $canadaPost->addItem($item->orderitem_quantity, $product->product_weight, $product->product_length, $product->product_width, $product->product_height, $description);
         }
     }
     //  $city, $provstate, $country, $postal_code
     // $address->city $address->zone_id $address->country_name $address->postal_code
     //
     // $address->city="Delhi";
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $zone = JTable::getInstance('Zones', 'TiendaTable');
     $zone->load($address->zone_id);
     $canadaPost->getQuote($address->city, $zone->zone_name, $address->country_name, $address->postal_code);
     $rates = $canadaPost->shipping_methods;
     $i = 0;
     foreach ($rates as $rate) {
         $vars[$i]['element'] = $this->_element;
         $vars[$i]['name'] = $rate['name'];
         $vars[$i]['price'] = $rate['rate'];
         // TODO
         $vars[$i]['code'] = $rate['packingID'];
         $vars[$i]['tax'] = 0;
         $vars[$i]['extra'] = 0;
         $vars[$i]['total'] = $rate['rate'];
         $i++;
     }
     return $vars;
 }
         $APchargeArray = split('=', $myfile[0]);
         $charge = $APchargeArray[1];
         $APerrorArray = split('=', $myfile[2]);
         //print_r($APchargeArray) ;
         $strAPerrorMessage_epi = trim($APerrorArray[1]);
         $errormessage[] = $strAPerrorMessage_epi;
         if ($strAPerrorMessage_epi == "OK") {
             if ($eachServiceVal != "" && $charge != "") {
                 $resultShippingArray[$product_option_id][] = array("service_name" => $eachServiceVal, "rate" => $charge);
             }
         }
     }
     break;
 case 'CP':
     //echo "entered CP";
     $cPost = new CanadaPost();
     $cPost->setPrice($product_price);
     $cPost->setCustomer(array('city' => '', 'provOrState' => $destination_state, 'country' => $destination_country, 'postalCode' => $destination_zip));
     $shipping_weight . $product_length . $product_width . $product_height;
     $cPost->addProduct(array('quantity' => $quantity, 'weight' => $shipping_weight, 'length' => $product_length, 'width' => $product_width, 'height' => $product_height, 'description' => 'Product Description'));
     // echo "CPPPPP";
     $assoc_Array = array();
     $assoc_Array[$product_option_id] = $cPost->getRates('array');
     //echo $cPost->getErrorMessage();
     if ($cPost->getErrorMessage() == "success") {
         foreach ($assoc_Array[$product_option_id]['product'] as $canShipping) {
             if ($canShipping['name'] != "" && $canShipping['rate'] != "") {
                 $resultShippingArray[$product_option_id][] = array("service_name" => $canShipping['name'], "rate" => $canShipping['rate']);
             }
         }
     }
Example #4
0
 public function getCanadaPostRates($id_zone, $is_cart, $cart, $product_weight, $dest_zip, $dest_state, $dest_country, $currency, $product, $id_product_attribute, $qty, $dest_city)
 {
     $rates = array();
     if (file_exists(dirname(__FILE__) . '/../../canadapost/classes/RateAvailableServices.php')) {
         include_once dirname(__FILE__) . '/../../canadapost/canadapost.php';
         include_once dirname(__FILE__) . '/../../canadapost/classes/RateAvailableServices.php';
         $ap = new CanadaPost();
         if ($ap->active) {
             $handling = Configuration::get('PS_SHIPPING_HANDLING');
             $carriers = $ap->getCarriers($id_zone, $cart, $is_cart, $product);
             foreach ($carriers as $carrier) {
                 if (get_parent_class($ap) == 'PrestoChangeoCarrierModule') {
                     $ap_rate = new CanadaPostRate();
                     $amount = $ap_rate->getRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_state, $dest_country, "", $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id, $is_cart != '' ? 0 : $id_product_attribute, $qty);
                 } else {
                     $amount = getCanadaPostRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_country, $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id);
                 }
                 // Add product spercific cost + handling fee
                 if ($amount > 0) {
                     $amount += $this->getExtraShippingCost($carrier, $handling, $is_cart != '' ? $cart->getProducts() : array(), $product, $qty);
                 }
                 // Apply shipping tax if needed
                 if (!Tax::excludeTaxeOption()) {
                     $carrierTax = Tax::getCarrierTaxRate($carrier['id_carrier']);
                 }
                 if (isset($carrierTax) && $amount !== false) {
                     $amount *= 1 + $carrierTax / 100;
                 }
                 $amount = $amount === false ? -1 : Tools::convertPrice($amount, $currency);
                 if ($amount > 0) {
                     $rates[$carrier['name']] = array(Tools::displayPrice($amount, $currency, false), $carrier['id_carrier']);
                 } elseif ($amount !== false && $amount == 0) {
                     $rates[$carrier['name']] = array($ap->l('Free!'), $carrier['id_carrier']);
                 }
             }
         }
     }
     return $rates;
 }
Example #5
0
echo $product_check['products_height'];
?>
" />				
		<input type="hidden" name="ttime" value="<?php 
echo time();
?>
" />
		<input type="submit" name="submit" value="Estimate" /> &nbsp; <input type="button" name="close" onclick="javascript:window.close();" value="Close Window" />
	</form>
</div>

<?php 
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isset($_POST['ttime'])) {
        require_once "class.canadapost.php";
        $cPost = new CanadaPost();
        $cPost->setPrice($_POST['price']);
        $cPost->setCustomer(array('city' => $_POST['city'], 'provOrState' => $_POST['prov'], 'country' => $_POST['country'], 'postalCode' => $_POST['postal']));
        $cPost->addProduct(array('quantity' => $_POST['quantity'], 'weight' => $_POST['weight'], 'length' => $_POST['length'], 'width' => $_POST['width'], 'height' => $_POST['height'], 'description' => ' '));
        $assoc_Array = $cPost->getRates('array');
        if ($assoc_Array === false) {
            echo 'Error: ' . $cPost->getErrorMessage();
        } else {
            //		echo "<pre>";
            //		var_dump( $assoc_Array );
            //		echo "</pre>";
            ?>
	<div style="border-bottom: solid 1px #ccc; height: 5px; margin-bottom: 5px;"></div>
	<div class="shippingRatesDivHeader">
		<div><strong> Shipping Type </strong></div>
		<div><strong> Rate ($) </strong></div>