if ($ouncelength == 0) {
     $shipping_ounces = 0;
 }
 if ($ouncelength == 1) {
     $shipping_ounces = $usps_shipping_weightSplit[1] / 10 * 16;
 }
 if ($ouncelength == 2) {
     $shipping_ounces = $usps_shipping_weightSplit[1] / 100 * 16;
 }
 if ($ouncelength == 3) {
     $shipping_ounces = $usps_shipping_weightSplit[1] / 1000 * 16;
 }
 if ($ouncelength == 4) {
     $shipping_ounces = $usps_shipping_weightSplit[1] / 10000 * 16;
 }
 $usps = new USPS();
 //echo $server."PPPPP";
 if ($server == "test") {
     //echo "!!!";
     $usps->setWeight(10, 5);
     $usps->setDestZip("20008");
     $usps->setOrigZip("10022");
 } else {
     //echo "###";
     $usps->setDestZip($destination_zip);
     $usps->setOrigZip($origin_zip);
     $usps->setWeight($shipping_pounds, $shipping_ounces);
 }
 $usps->setServer($uspsserver);
 $usps->setUserName($uspsid);
 $uspspaswd = "";
Beispiel #2
0
<?php

require_once 'common/config/config.inc.php';
require_once SOURCE_ROOT . 'classes/class.customer_login.php';
//here object is created
$objCustomerLogin = new CustomerLogin();
//customer session is checked whether it is valid or not
if (!$objCustomerLogin->checkCustomerSession()) {
    header('location:login.php');
    die;
}
if (isset($_SESSION['sessCartDetails'])) {
    $arrCartDetails = $_SESSION['sessCartDetails'];
    //$_SESSION['sessCartDetails']= array();
    require "components/ups/usps.php";
    $usps = new USPS();
    $usps->setServer("http://Production.ShippingAPIs.com/ShippingAPI.dll");
    $usps->setUserName("760BODYZ6562");
    $usps->setService("All");
    $usps->setOrigZip("30076");
    $usps->setContainer("Flat Rate Box");
    $usps->setMachinable("true");
    $usps->setSize("LARGE");
}
//Code for getting Billing Details
$arrCols = array('CustomerFirstName', 'CustomerLastName', 'CustomerEmailID', 'CustomerPhone', 'CustomerAddressOne', 'CustomerAddressTwo', 'CustomerCountry', 'CustomerState', 'CustomerCity', 'CustomerZipcode', 'CustomerShippingPhone', 'CustomerShippingAddressOne', 'CustomerShippingAddressTwo', 'CustomerShippingCountry', 'CustomerShippingState', 'CustomerShippingCity', 'CustomerShippingZipcode', 'CustomerIsAddressSame');
//$varTable = TABLE_CUSTOMERS.' INNER JOIN '.TABLE_CARD_INFO.' ON '.TABLE_CUSTOMERS.'.pkCustomerID ='.TABLE_CARD_INFO.'.fkCustomerID';
$varWhere = 'pkCustomerID = \'' . $_SESSION['sessCustomerID'] . '\'';
$arrCustomerRecord = $objGeneral->getRecord(TABLE_CUSTOMERS, $arrCols, $varWhere);
@extract($arrCustomerRecord[0]);
//Listing countries
Beispiel #3
0
 public function getUSPSRates($id_zone, $is_cart, $cart, $product_weight, $dest_zip, $dest_state, $dest_country, $currency, $product, $id_product_attribute, $qty)
 {
     $rates = array();
     if (file_exists(dirname(__FILE__) . '/../../usps/classes/RateAvailableServices.php')) {
         include_once dirname(__FILE__) . '/../../usps/usps.php';
         include_once dirname(__FILE__) . '/../../usps/classes/RateAvailableServices.php';
         $usps = new USPS();
         if ($usps->active) {
             // Get handling cost (once)
             $handling = Configuration::get('PS_SHIPPING_HANDLING');
             $carriers = $usps->getCarriers($id_zone, $cart, $is_cart, $product);
             foreach ($carriers as $carrier) {
                 //check if USPS module is new or old
                 if (get_parent_class($usps) == 'PrestoChangeoCarrierModule') {
                     $USPSRate = new USPSRate();
                     $amount = $USPSRate->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 = getUSPSRate($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);
                 }
                 // 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($usps->l('Free!'), $carrier['id_carrier']);
                 }
             }
         }
     }
     return $rates;
 }
Beispiel #4
0
function ecom_shipping_USPS($shipping_option, $index, $packages, $org_zip, $dest_zip, $dest_country, $error)
{
    global $_TABLES;
    $shipper_res = DB_query("SELECT user_name, live_server FROM {$_TABLES['ecom_shipper']} WHERE id = 1");
    $shipper_row = DB_fetchArray($shipper_res);
    $pc = new USPS($shipper_row['user_name'], $org_zip, $dest_zip, $dest_country, $index);
    //user, z_org, z_dest
    $data_error = $pc->check_data();
    if ($data_error != "") {
        $error .= $data_error;
        return 1;
    }
    foreach ($packages as $p) {
        $pc->add_package($p['w'], $p['h'], $p['l'], $p['p'], $p['o']);
        //w, h, l, p, o
    }
    $pc->merge_packages();
    //Not yet functioning
    # Set the shipping options for national shipping US and US territories
    if ($dest_country == "US" || $dest_country == "PR" || $dest_country == "US" || $dest_country == "FM" || $dest_country == "PW") {
        $res = DB_query("SELECT * FROM {$_TABLES['ecom_shipper_service']} WHERE ecom_shipper_service_enabled = true AND ecom_shipper_id = 1 AND ecom_shipper_service_international = false");
        while ($row = DB_fetchArray($res)) {
            //Check if it is media, library, or bound printed matter
            $can_ship = true;
            if ($row['ecom_shipper_service_service'] == "BPM") {
                //check to see if any items in cart can not be shipped this way
                foreach ($packages as $p) {
                    if (!$p['bmp']) {
                        $can_ship = false;
                    }
                }
            } else {
                if ($row['ecom_shipper_service_service'] == "MEDIA") {
                    //check to see if any items in cart can not be shipped this way
                    foreach ($packages as $p) {
                        if (!$p['media']) {
                            $can_ship = false;
                        }
                    }
                } else {
                    if ($row['ecom_shipper_service_service'] == "LIBRARY") {
                        foreach ($packages as $p) {
                            if (!$p['library']) {
                                $can_ship = false;
                            }
                        }
                    }
                }
            }
            if ($can_ship) {
                $total = $pc->get_price($row['ecom_shipper_service_service'], $row['ecom_shiper_service_code'], $shipper_row['live_server']);
                if ($total > 0) {
                    //if total is 0 then error occurred (counldn't ship package).
                    $shipping_option[$index]['description'] = $row['ecom_shipper_service_description'];
                    $shipping_option[$index]['price'] = $total;
                    $index++;
                }
            }
        }
    } else {
        # INTERNATION Shipping
        $res = DB_query("SELECT ecom_shiper_service_code FROM {$_TABLES['ecom_shipper_service']} WHERE ecom_shipper_service_enabled = true AND ecom_shipper_id = 1 AND ecom_shipper_service_international = true");
        while ($row = DB_fetchArray($res)) {
            $service[$i++] = $row['ecom_shiper_service_code'];
        }
        $shipping_result = $pc->get_price($service, 0, $shipper_row['live_server']);
        if (is_array($shipping_result)) {
            foreach ($shipping_result as $shipping) {
                $shipping_option[$index]['description'] = $shipping['description'];
                //
                $shipping_option[$index]['price'] = $shipping['price'];
                $index++;
            }
        }
    }
}
 public static function getShippingPriceProduct($productid = 0, $productOptionId = 0, $userId = "", $destination_country = "", $destination_state = "", $destination_zip = "")
 {
     global $tableprefix;
     $adminCurrency = GetAdminCurrency();
     if (isCartEmpty($userId)) {
         clsGenerateShippingControl::getNoShippingControl($product_option_id);
         return 0;
     }
     if (get_magic_quotes_gpc()) {
         $_POST = array_map('stripslashes_deep', $_POST);
         $_GET = array_map('stripslashes_deep', $_GET);
         $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
     }
     if ($destination_country == "" && $destination_state == "" && $destination_zip == "") {
         $userAddress = clsGenerateShippingControl::getuserAddress($userId);
         if (count($userAddress) > 0) {
             $destination_state = $userAddress['state'];
             $destination_country = $userAddress['country'];
             $destination_zip = $userAddress['zip'];
         }
     }
     $uspsRequired_Service = array("Express Mail", "Express Mail Hold For Pickup", "Express Mail Sunday/Holiday Delivery", "Priority Mail", "Parcel Post", "Priority Mail Large Flat Rate Box", "\nPriority Mail Medium Flat Rate Box", "Priority Mail Small Flat Rate Box", "Priority Mail Flat Rate Envelope", "Media Mail", "Library Mail");
     //===================Getting Currency Type=========================
     $currency_attributes = displayCurrencyType();
     $flatrateEnabled = getSettingsValue('enable_flatrate');
     /*display the active template*/
     //set shipping gateway and doing basic settings
     include_once 'fedex/fedex.php';
     $sql = "select * from " . $tableprefix . "fedexsettings ";
     $rs = mysql_query($sql) or die(mysql_error());
     if (mysql_num_rows($rs) > 0) {
         $serviceName = array();
         $row = mysql_fetch_array($rs);
         $fedexaccno = stripslashes($row['FedexAccno']);
         $fedexmeterno = stripslashes($row['FedexMeterno']);
         $weightunits = $row['FedexWeight'];
         $server = $row['FedexServer'];
         $dropoff = stripslashes($row['FedexDropOff']);
         $packageTypes = stripslashes($row['FedexPackage']);
         $sName = $row['FedexService'];
         $currency = $row['FedexCurrency'];
         if ($_SESSION["sessShippingMethod"] == "FDXE") {
             $sarry = $fedexService;
             $shippingTitle = "Fedex Express Shipping";
         } else {
             $sarry = $fedexGroundService;
             $shippingTitle = "Fedex Express Ground Shipping";
         }
     }
     // end num rows check
     switch ($server) {
         case "test":
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
         case "production":
             // change this to actual server when go on live
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
         default:
             $fedexserver = "https://gatewaybeta.fedex.com/GatewayDC";
             break;
     }
     //// check enabled shipping is usps or not
     include_once "usps/xmlparser.php";
     include_once 'usps/usps.php';
     $shippingTitle = "USPS";
     $sql = "select * from " . $tableprefix . "usps_settings ";
     $rs = mysql_query($sql) or die(mysql_error());
     if (mysql_num_rows($rs) > 0) {
         $row = mysql_fetch_array($rs);
         $uspsid = $row['username'];
         $server = $row['server'];
     }
     // end num rows check
     switch ($server) {
         case "test":
             $uspsserver = "http://testing.shippingapis.com/ShippingAPITest.dll";
             break;
         case "production":
             //change this line when usps is on live
             $uspsserver = "http://Production.ShippingAPIs.com/ShippingAPI.dll";
             break;
         default:
             $uspsserver = "http://testing.shippingapis.com/ShippingAPITest.dll";
             break;
     }
     // end switch
     require_once "ups.php";
     include_once "shipping.php";
     include_once 'http_client.php';
     $shippingTitle = "UPS";
     // Shipping setting for UPS Shipping
     $select_shipping_settings = "SELECT * FROM " . $tableprefix . "shipping_settings";
     $result_shipping_settings = mysql_query($select_shipping_settings);
     if (mysql_num_rows($result_shipping_settings) > 0) {
         $rs_ship = mysql_fetch_array($result_shipping_settings);
         $ups_weight = $rs_ship['nShippingweight'];
         $ups_rate = $rs_ship['ups_rate'];
         $ups_container = $rs_ship['container_type'];
         $ups_type = $rs_ship['address_quote_method'];
     }
     $upsrate = new Ups();
     // select product details
     $select_cart_details = "SELECT prd.product_id,prd.product_name,po.product_option_id,po.product_length,po.product_width,po.product_height,crt.quantity,\n                       po.product_shipping_weight,art.country AS origin_country,art.state AS origin_state,art.zip AS origin_zip,art.artist_id,\n                       art.defaultflatrate,art.additionalflatrate, prd.eUps, prd.eUsps , prd.eFedex , prd.fFlatRateShippingAmount, prd.fAdditionalItemCost\n                       FROM " . $tableprefix . "cart crt\n                       INNER JOIN " . $tableprefix . "product_options po ON crt.product_option_id = po.product_option_id\n                       INNER JOIN " . $tableprefix . "products prd ON prd.product_id = po.product_id\n                       INNER JOIN " . $tableprefix . "artists art ON art.artist_id = prd.product_artist_id\n                       WHERE crt.user_id = '" . mysql_real_escape_string($userId) . "' AND po.product_option_id = '" . mysql_real_escape_string($productOptionId) . "' ORDER BY crt.cart_id";
     $result_cart_details = mysql_query($select_cart_details) or die(mysql_error());
     $_SESSION["SHIPPING_DETAILS"] = array();
     $_SESSION["SHIPPING_TOTAL"] = 0;
     $productArray = array();
     $resultShippingArray = array();
     if (mysql_num_rows($result_cart_details) == 0) {
         //as no products there is no point in staying in shipping options
         clsGenerateShippingControl::getNoShippingControl($product_option_id);
         return 0;
     } else {
         //Now we need to take shipping rates a products
         $cart_details_row = mysql_fetch_array($result_cart_details);
         $shipping_weight = trim($cart_details_row['product_shipping_weight']);
         $origin_country = $cart_details_row['origin_country'];
         $origin_state = $cart_details_row['origin_state'];
         $origin_zip = $cart_details_row['origin_zip'];
         $product_name = $cart_details_row['product_name'];
         $artist_id = $cart_details_row['artist_id'];
         $product_id = $cart_details_row['product_id'];
         $product_option_id = $cart_details_row['product_option_id'];
         $optionsStr = "";
         $optionVal = getProductOptionsName($product_option_id);
         if ($optionVal != "") {
             $optionsStr = "<br>" . $optionVal;
         }
         $productArray[$product_option_id] = $product_name . $optionsStr;
         $quantity = trim($cart_details_row['quantity']);
         $product_length = $cart_details_row['product_length'];
         $product_height = $cart_details_row['product_height'];
         $product_width = $cart_details_row['product_width'];
         // Take product shippings
         $productShippingArray = array();
         if ($cart_details_row['eUps'] == 'Y') {
             $productShippingArray[] = 'UPS';
         }
         if ($cart_details_row['eFedex'] == 'Y') {
             $productShippingArray[] = 'FDXG';
         }
         if ($cart_details_row['eUsps'] == 'Y') {
             $productShippingArray[] = 'USPS';
         }
         if ($cart_details_row['fFlatRateShippingAmount'] > 0) {
             $productShippingArray[] = 'Flat Rate';
             $FlatRateShippingAmount = $cart_details_row['fFlatRateShippingAmount'];
             $AdditionalItemCost = $cart_details_row['fAdditionalItemCost'];
         }
         /*  echo '<br>' . $origin_state;
             echo '<br>' . $origin_country;
             echo '<br>' . $origin_zip;
             echo '<br>' . $destination_state;
             echo '<br>' . $destination_country;
             echo '<br>' . $destination_zip;*/
         //print_r($productShippingArray);
         foreach ($productShippingArray as $key => $shippingMethod) {
             //  $shippingMethod = $value; // set product shipping
             //set for ups only
             $shippingMethod = trim($shippingMethod);
             //======================Getting rates for each product from shipping gateways-Santhosh=================================
             switch ($shippingMethod) {
                 case "FDXE":
                 case "FDXG":
                     $shippingMode = $shippingMethod;
                     if (is_array($sarry)) {
                         // check service is an array or not
                         foreach ($sarry as $serviceNames) {
                             $fedex_shipping_weight = $shipping_weight * $quantity;
                             list($service, $serviceName) = split('-', $serviceNames);
                             $fedex = new Fedex();
                             $fedex->setServer($fedexserver);
                             $fedex->setAccountNumber($fedexaccno);
                             //Get your own - this will not work...
                             $fedex->setMeterNumber($fedexmeterno);
                             //Get your own - this will not work...
                             $fedex->setCarrierCode($shippingMode);
                             $fedex->setDropoffType($dropoff);
                             $fedex->setService($service, $serviceName);
                             $fedex->setPackaging($packageTypes);
                             $fedex->setWeightUnits($weightunits);
                             $fedex->setWeight($fedex_shipping_weight);
                             $fedex->setOriginStateOrProvinceCode($origin_state);
                             $fedex->setOriginPostalCode($origin_zip);
                             $fedex->setOriginCountryCode($origin_country);
                             $fedex->setDestStateOrProvinceCode($destination_state);
                             $fedex->setDestPostalCode($destination_zip);
                             $fedex->setDestCountryCode($destination_country);
                             $fedex->setPayorType("SENDER");
                             $fedexprice = $fedex->getPrice();
                             $fedexrate[] = $fedexprice->price->rate;
                             $fedexerror[] = $fedexprice->error->description;
                             if ($fedexprice->error->description == "" && $fedexprice->serviceName != "" && $fedexprice->price->rate != "") {
                                 $resultShippingArray[$product_option_id][] = array("service_name" => $fedexprice->serviceName, "rate" => $fedexprice->price->rate);
                             }
                         }
                         // end foreach
                     }
                     // end array check
                     break;
                 case "USPS":
                     $usps_shipping_weight = $shipping_weight * $quantity;
                     if ($usps_shipping_weight < 1) {
                         $usps_shipping_weight = 1;
                     }
                     $usps_shipping_weightSplit = explode(".", $usps_shipping_weight);
                     $shipping_pounds = $usps_shipping_weightSplit[0];
                     $ouncelength = count_digit($usps_shipping_weightSplit[1]);
                     if ($ouncelength == 0) {
                         $shipping_ounces = 0;
                     }
                     if ($ouncelength == 1) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 10 * 16;
                     }
                     if ($ouncelength == 2) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 100 * 16;
                     }
                     if ($ouncelength == 3) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 1000 * 16;
                     }
                     if ($ouncelength == 4) {
                         $shipping_ounces = $usps_shipping_weightSplit[1] / 10000 * 16;
                     }
                     $usps = new USPS();
                     if ($server == "test") {
                         $usps->setWeight(10, 5);
                         $usps->setDestZip("20008");
                         $usps->setOrigZip("10022");
                     } else {
                         $usps->setDestZip($destination_zip);
                         $usps->setOrigZip($origin_zip);
                         $usps->setWeight($shipping_pounds, $shipping_ounces);
                     }
                     $usps->setServer($uspsserver);
                     $usps->setUserName($uspsid);
                     $uspspaswd = "";
                     $usps->setPass($uspspaswd);
                     $usps->setService("All");
                     //$usps->setContainer("Flat Rate Box");
                     $usps->setCountry("USA");
                     $usps->setMachinable("true");
                     $usps->setSize("REGULAR");
                     $uspsprice = array();
                     $uspsprice = $usps->getPrice();
                     $special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";
                     if ($uspsprice->error->description == "") {
                         foreach ($uspsprice->list as $eachItem) {
                             if ($eachItem->mailservice != "" && $eachItem->rate != "") {
                                 $eachItemServicename = str_replace($special_chars, "", $eachItem->mailservice);
                                 if (in_array($eachItemServicename, $uspsRequired_Service)) {
                                     $resultShippingArray[$product_option_id][] = array("service_name" => $eachItemServicename, "rate" => $eachItem->rate);
                                 }
                             }
                         }
                     }
                     break;
                 case "UPS":
                     $ups_types = clsGenerateShippingControl::getupsShippingTypes();
                     $ups_shipping_weight = $shipping_weight * $quantity;
                     $ups_shipping_weight = $ups_shipping_weight < 0.1 ? 0.1 : $ups_shipping_weight;
                     foreach ($ups_types as $types => $ups) {
                         $upsrate->upsProduct($types);
                         // See upsProduct() function for codes
                         $upsrate->origin($origin_zip, $origin_country);
                         // Use ISO country codes!
                         $upsrate->dest($destination_zip, $destination_country);
                         // Use ISO country codes!
                         $upsrate->rate($ups_rate);
                         // See the rate() function for codes
                         $upsrate->container($ups_container);
                         // See the container() function for codes
                         $upsrate->weight(number_format($ups_shipping_weight, 2, ".", ""));
                         $upsrate->rescom($ups_type);
                         // See the rescom() function for codes
                         $quote = $upsrate->getQuote();
                         if ($quote != "error" && $ups != "" && $quote != "") {
                             $resultShippingArray[$product_option_id][] = array("service_name" => $ups, "rate" => $quote);
                         }
                         // end price empty check
                     }
                     //end foreach
                     break;
                 case "Flat Rate":
                     $flat_rate_name = "Flat Rate";
                     $first_Item_charge = $FlatRateShippingAmount;
                     $additional_Item_charge = $AdditionalItemCost;
                     $rate = $first_Item_charge + $additional_Item_charge * ($quantity - 1);
                     $resultShippingArray[$product_option_id][] = array("service_name" => stripslashes($flat_rate_name), "rate" => $rate);
                 default:
             }
             // if the rate array is empty for other shipping Options check whether
             // admin has enabled the flat rate shipping so that customer can still
             // buy with the flat option.
             $Selected_Shipping_options = $shippingTitle;
             if (empty($selectedShippingOption)) {
                 $selectedShippingOption = $shippingTitle;
             }
             $shipping_options_availabe = count($resultShippingArray[$product_option_id]);
         }
         // end while loop
     }
     return $resultShippingArray;
 }
Beispiel #6
0
USPS Rates
<pre>
<?php 
require "usps.php";
$usps = new USPS();
$usps->setServer("http://testing.shippingapis.com/ShippingAPITest.dll");
$usps->setUserName("GETYOUROWN");
$usps->setService("All");
$usps->setDestZip("20008");
$usps->setOrigZip("10022");
$usps->setWeight(10, 5);
$usps->setContainer("Flat Rate Box");
$usps->setCountry("USA");
$usps->setMachinable("true");
$usps->setSize("LARGE");
$price = $usps->getPrice();
print_r($price);
?>
</pre>