protected function processRequest($arrAddress) { //Origin Address// $arrOrigin['city'] = $this->Isotope->Config->city ? $this->Isotope->Config->city : NULL; if ($this->Isotope->Config->subdivision) { $arrState = explode('-', $this->Isotope->Config->subdivision); $arrOrigin['state'] = $arrState[1]; $arrOrigin['country'] = $arrState[0]; } else { $arrOrigin['country'] = $arrState[0]; } if ($this->Isotope->Config->postal) { $arrOrigin['zip'] = $this->Isotope->Config->postal; } //END Origin Address// //Destination Address// $arrFieldMap = array('name' => $arrAddress['firstname'] . ' ' . $arrAddress['lastname'], 'street' => $arrAddress['street_1'], 'city' => $arrAddress['city']); if ($arrAddress['subdivision']) { $arrState = explode("-", $arrAddress['subdivision']); $arrFieldMap['state'] = $arrState[1]; $arrFieldMap['country'] = $arrState[0]; } else { $arrFieldMap['country'] = strtoupper($arrAddress['country']); } if ($arrAddress['postal']) { $arrFieldMap['zip'] = $arrAddress['postal']; } //END Destination Address// //Package Info// $fltWeight = $this->Isotope->Cart->getShippingWeight('lb'); $arrData = array('pickup_date' => date('Ymd', time() + 86400), 'invoice' => array('currency_code' => $this->Isotope->Config->currency, 'monetary_value' => $this->Isotope->Cart->subTotal), 'weight' => array('unit_of_measure' => array('code' => 'LBS', 'desc' => 'Pounds'), 'weight' => $fltWeight > 0 ? ceil($fltWeight) : 3)); // end $data //END Package Info// $strIds = implode(",", deserialize($this->iso_shipping_modules, true)); if (!$strIds) { $this->Template->message = $GLOBALS['TL_LANG']['MSC']['noEnabledUpsServices']; return array(); } $objUPSService = $this->Database->prepare("SELECT ups_enabledservice FROM tl_iso_shipping_modules WHERE id IN({$strIds}) AND type='ups' OR type='multi_ups'")->limit(1)->execute(); if (!$objUPSService->numRows) { $this->Template->message = $GLOBALS['TL_LANG']['MSC']['noEnabledUpsServices']; return array(); } //Service Info// $arrShipment['pickup_type'] = (string) $objUPSService->ups_enabledservice; //default one-time but should be configurable. $arrShipment['service'] = (string) $objUPSService->ups_enabledservice; //ground $arrShipment['packages'][] = array('packaging' => array('code' => '02', 'description' => ''), 'description' => '', 'units' => 'LBS', 'weight' => $fltWeight > 0 ? ceil($fltWeight) : 3); $arrReturn = array(); //END Service Info/ $objUpsTimeRequest = new UpsAPITimeInTransit($arrOrigin, $arrFieldMap, $arrData); $xmlTime = $objUpsTimeRequest->buildRequest(); $arrReturn['transit'] = $objUpsTimeRequest->sendRequest($xmlTime); //collect rate codes for the rate values foreach ($arrReturn['transit']['TimeInTransitResponse']['TransitResponse']['ServiceSummary'] as $service) { $arrCodes[] = $service['Service']['Code']; } $objUpsRateRequest = new UpsAPIRatesAndService($arrShipment, $arrOrigin, $arrOrigin, $arrFieldMap); $xmlRate = $objUpsRateRequest->buildRequest(); // check the output type $arrReturn['rates'] = $objUpsRateRequest->sendRequest($xmlRate); return $arrReturn; }
/** * Return an object property * * @access public * @param string * @return mixed */ public function __get($strKey) { switch ($strKey) { case 'price': $arrShipment = $this->Shipment; if (!count($this->Shipment) || ($arrShipment['address']['postal'] == $this->Isotope->Config->postal && $arrShipment['address']['subdivision'] == $this->Isotope->Config->subdivision && $arrShipment['address']['country'] == $this->Isotope->Config->country && (!isset($arrShipment['address']['firstname']) || !isset($arrShipment['address']['lastname']) || !isset($arrShipment['address']['city']) || !isset($arrShipment['address']['subdivision']) || !isset($arrShipment['address']['postal']) || !isset($arrShipment['address']['country']) || !isset($arrShipment['address']['street_1'])) || ($arrShipment['address']['firstname'] == '' || $arrShipment['address']['lastname'] == '' || $arrShipment['address']['city'] == '' || $arrShipment['address']['subdivision'] == '' || $arrShipment['address']['postal'] == '' || $arrShipment['address']['country'] == '' || $arrShipment['address']['street_1'] == ''))) { return 0; } $blnShowError = false; $strPrice = $this->arrData['price']; $blnPercentage = substr($strPrice, -1) == '%' ? true : false; if ($blnPercentage) { $fltSurcharge = (double) substr($strPrice, 0, -1); $fltPrice = $this->Isotope->Cart->subTotal / 100 * $fltSurcharge; } else { $fltPrice = (double) $strPrice; } $arrPackage = $this->buildShipment(); list($arrOrigin, $arrDestination, $arrShipment) = $arrPackage; //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']) . $this->Shipment['quantity']); if ($_SESSION['CHECKOUT_DATA']['UPS'][$strRequestHash]) { $arrResponse = $_SESSION['CHECKOUT_DATA']['UPS'][$strRequestHash]; } else { // Construct UPS Object: For now, Origin is assumed to be the same for origin and shipping info $objUPSAPI = new UpsAPIRatesAndService($arrShipment, $arrOrigin, $arrOrigin, $arrDestination); $strRequestXML = $objUPSAPI->buildRequest('RatingServiceSelectionRequest'); $arrResponse = $objUPSAPI->sendRequest($strRequestXML); $_SESSION['CHECKOUT_DATA']['UPS'][$strRequestHash] = $arrResponse; if ($this->blnShowError) { $blnShowError = true; } } if ((int) $arrResponse['RatingServiceSelectionResponse']['Response']['ResponseStatusCode'] == 1) { $fltUPSPrice = floatval($arrResponse['RatingServiceSelectionResponse']['RatedShipment']['TotalCharges']['MonetaryValue']); } elseif ($blnShowError) { $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"]); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { // add something if this is an ajax with error? } else { //Log and display error if this is not an AJAX request to prevent a billion error msgs $_SESSION['ISO_ERROR']['ups'] = $strMessage; } $this->log($strLogMessage, __METHOD__, TL_ERROR); } return $this->Isotope->calculatePrice($fltPrice + $fltUPSPrice, $this, 'price', $this->arrData['tax_class']); break; case 'available': $blnAvailable = $this->price > 0 ? parent::__get('available') : false; // HOOK for determining availability if (isset($GLOBALS['ISO_HOOKS']['shippingAvailable']) && is_array($GLOBALS['ISO_HOOKS']['shippingAvailable'])) { foreach ($GLOBALS['ISO_HOOKS']['shippingAvailable'] as $callback) { $this->import($callback[0]); $blnAvailable = $this->{$callback}[0]->{$callback}[1]($blnAvailable, $this); } } return $blnAvailable; break; } return parent::__get($strKey); }