/** * * 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; }