private function getRatesByType(Fedex $fedex, $type) { $fedex->setCarrierCode($type); $enabledServices = $this->getConfigValue('enabledServices', null); $price = $fedex->getPrice(); if (isset($price['FDXRATEAVAILABLESERVICESREPLY'][0]['ENTRY'])) { $rates = $price['FDXRATEAVAILABLESERVICESREPLY'][0]['ENTRY']; $result = new ShippingRateSet(); foreach ($rates as $price) { $r = new ShippingRateResult(); $code = $price['SERVICE'][0]['VALUE']; if (!is_array($enabledServices) || isset($enabledServices[$code])) { $name = self::$names[$code]; if (isset($price['DELIVERYDATE'][0]['VALUE'])) { $date = $price['DELIVERYDATE'][0]['VALUE']; $name = $name . ' (' . $date . ')'; } $r->setServiceName($name); $cost = $price['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'][0]['VALUE']; $currency = isset($price['ESTIMATEDCHARGES'][0]['CURRENCYCODE'][0]['VALUE']) ? $price['ESTIMATEDCHARGES'][0]['CURRENCYCODE'][0]['VALUE'] : 'USD'; $r->setCost($cost, $currency); $r->setClassName(get_class($this)); $r->setProviderName($this->getProviderName()); $result->add($r); } } } else { $price = $price['FDXRATEAVAILABLESERVICESREPLY'][0]; $msg = isset($price['ERROR']) ? $price['ERROR'] : (isset($price['SOFTERROR']) ? $price['SOFTERROR'][0]['MESSAGE'] : ''); $result = new ShippingRateError($msg); } $result->setRawResponse($price); return $result; }
} // end price empty check } //end foreach // print_r($resultShippingArray);echo "$$$$$$$$"; break; case 'FDX': //echo "entered fdx 2";print_r($sarry);echo "AAAAAAAA".$sarry; if (is_array($sarry)) { // check service is an array or not foreach ($sarry as $serviceNames) { // print_r($serviceNames); $fedex_shipping_weight = $shipping_weight * $quantity; list($service, $serviceName) = split('-', $serviceNames); $fedex = new Fedex(); $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);
public function getFedexRates($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__) . '/../../fedex/classes/RateAvailableServices.php')) { include_once dirname(__FILE__) . '/../../fedex/fedex.php'; include_once dirname(__FILE__) . '/../../fedex/classes/RateAvailableServices.php'; $fedex = new Fedex(); if ($fedex->active) { // Get handling cost (once) $handling = Configuration::get('PS_SHIPPING_HANDLING'); $carriers = $fedex->getCarriers($id_zone, $cart, $is_cart, $product); foreach ($carriers as $carrier) { //check if Fedex module is new or old if (get_parent_class($fedex) == 'PrestoChangeoCarrierModule') { $fedexRate = new FedexRate(); $amount = $fedexRate->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 = getFedexRate($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($fedex->l('Free!'), $carrier['id_carrier']); } } } } return $rates; }
require "fedex.php"; $fedexService['PRIORITYOVERNIGHT'] = 'FedEx Priority Overnight'; $fedexService['STANDARDOVERNIGHT'] = 'FedEx Standard Overnight'; $fedexService['FIRSTOVERNIGHT'] = 'FedEx First Overnight'; $fedexService['FEDEX2DAY'] = 'FedEx 2 Day'; $fedexService['FEDEXEXPRESSSAVER'] = 'FedEx Express Saver'; $fedexService['INTERNATIONALPRIORITY'] = 'FedEx International Priority'; $fedexService['INTERNATIONALECONOMY'] = 'FedEx International Economy'; $fedexService['INTERNATIONALFIRST'] = 'FedEx International First'; $fedexService['FEDEX1DAYFREIGHT'] = 'FedEx Overnight Freight'; $fedexService['FEDEX2DAYFREIGHT'] = 'FedEx 2 day Freight'; $fedexService['FEDEX3DAYFREIGHT'] = 'FedEx 3 day Freight'; $fedexService['FEDEXGROUND'] = 'FedEx Ground'; $fedexService['GROUNDHOMEDELIVERY'] = 'FedEx Home Delivery'; foreach ($fedexService as $service => $serviceName) { $fedex = new Fedex(); $fedex->setServer("https://gatewaybeta.fedex.com/GatewayDC"); $fedex->setAccountNumber(123123123); //Get your own - this will not work... $fedex->setMeterNumber(12312312); //Get your own - this will not work... $fedex->setCarrierCode("FDXE"); $fedex->setDropoffType("REGULARPICKUP"); $fedex->setService($service, $serviceName); $fedex->setPackaging("YOURPACKAGING"); $fedex->setWeightUnits("LBS"); $fedex->setWeight(17); $fedex->setOriginStateOrProvinceCode("OH"); $fedex->setOriginPostalCode(44333); $fedex->setOriginCountryCode("US"); $fedex->setDestStateOrProvinceCode("CA");
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 = "<sup>&reg;</sup>"; 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; }
/** * * Request FEDEX shippings * @author Oleg D. */ function fedexReuest($ship_country, $ship_state, $ship_zip, $ship_company, $sender_state, $sender_zip, $sender_country, $package_weight) { App::import('Vendor', 'Fedex', array('file' => 'class.Fedex.php')); $Fedex = new Fedex(); //$pounds = sprintf("%d", round($package_weight/16)); $pounds = ceil($package_weight / 16); if (FEDEX_TEST_MODE) { $Fedex->testing = 1; $Fedex->meter = FEDEX_TEST_METER; $Fedex->account = FEDEX_TEST_ACCOUNT; } else { $Fedex->testing = 0; $Fedex->meter = FEDEX_METER; $Fedex->account = FEDEX_ACCOUNT; } $Fedex->dest_state = $ship_state; $Fedex->dest_zip = $ship_zip; $Fedex->dest_country = $ship_country; $Fedex->dest_company = $ship_company; $Fedex->sender_state = $sender_state; $Fedex->sender_zip = $sender_zip; $Fedex->sender_country = $sender_country; $Fedex->total_weight = $pounds; $myFedexQuote = array(); $fedex_error = 0; $fedexGet = 0; $fedexIteration = 0; $iterationsNum = 2; // Numbe of trying to ger request while ($fedexGet == 0) { $fedexQuote = $Fedex->quote(); //echo "<pre/>"; print_r($fedexQuote); if (!empty($fedexQuote)) { foreach ($fedexQuote as $this_code => $this_price) { $myFedexQuote[substr($this_code, 0, 2)] = $this_price; } } $fedexIteration++; if (isset($myFedexQuote['90']) || isset($myFedexQuote['01']) || $fedexIteration > $iterationsNum) { $fedexGet = 1; } } if (isset($myFedexQuote['error'])) { $fedex_error = 1; } if (!$fedex_error) { $result = $myFedexQuote; } else { $result = 0; } // show FEDEX quote info !!!!!! //echo 'pounds:' . $pounds; echo "<pre>"; print_r($myFedexQuote); //debug($result); return $result; }