/**
* Return calculated price for this shipping method
* @param IsotopeProductCollection
* @return float
*/
protected function getLiveRateQuote(IsotopeProductCollection $objCollection)
{
$fltPrice = 0.0;
//get a hash for the cache
$strService = $this->fedex_enabledService ?: 'FEDEX_GROUND';
$strPackagingType = $this->fedex_PackingService ?: 'YOUR_PACKAGING';
$strHash = static::makeHash($objCollection, array($strService, $strPackagingType));
if (!Cache::has($strHash)) {
$arrReturn = $this->buildShipment($objCollection);
if (empty($arrReturn) || count($arrReturn) != 3) {
Cache::set($strHash, $fltPrice);
return Cache::get($strHash);
}
list($arrOrigin, $arrDestination, $arrShipment) = $arrReturn;
//Cache the request so we don't have to run it again as the API is slow
$strRequestHash = md5(implode('.', $arrDestination) . $arrShipment['service'] . $arrShipment['weight'] . implode('.', $this->Shipment['productids']));
// Construct FEDEX Object: For now, Origin is assumed to be the same for origin and shipping info
$objFEDEXAPI = new FedExAPIRatesAndService($arrShipment, $arrOrigin, $arrOrigin, $arrDestination);
$strRequestXML = $objFEDEXAPI->buildRequest('RatingServiceSelectionRequest');
// What the...?
unset($_SESSION['CHECKOUT_DATA']['FEDEX'][$strRequestHash]);
if ($_SESSION['CHECKOUT_DATA']['FEDEX'][$strRequestHash]) {
$arrResponse = $_SESSION['CHECKOUT_DATA']['FEDEX'][$strRequestHash];
} else {
$arrResponse = $objFEDEXAPI->sendRequest($strRequestXML);
$_SESSION['CHECKOUT_DATA']['FEDEX'][$strRequestHash] = $arrResponse;
}
if ($arrResponse['RateReply']['Notifications']['Severity'] == 'SUCCESS') {
$fltPrice = floatval($arrResponse['RateReply']['RateReplyDetails']['RatedShipmentDetails'][0]['ShipmentRateDetail']['TotalNetCharge']['Amount']);
} else {
$strLogMessage = sprintf('Error in shipping digest: %s - %s', $arrResponse['RatingServiceSelectionResponse']["Response"]["ResponseStatusDescription"], $arrResponse['RatingServiceSelectionResponse']["Response"]["Error"]["ErrorDescription"]);
$strMessage = sprintf('%s - %s', $arrResponse['RatingServiceSelectionResponse']["Response"]["ResponseStatusDescription"], $arrResponse['RatingServiceSelectionResponse']["Response"]["Error"]["ErrorDescription"]);
log_message($strLogMessage, 'error.log');
//$_SESSION['ISO_ERROR'][] = $strMessage;
//\System::log($strLogMessage, __METHOD__, TL_ERROR);
}
Cache::set($strHash, $fltPrice);
}
return Cache::get($strHash);
}