has() public static method

Check whether a key is set
public static has ( string $strKey ) : boolean
$strKey string The cache key
return boolean True if the key is set
 /**
  * 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);
 }
Example #2
0
 /**
  * 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
     $strHash = static::makeHash($objCollection, array($this->ups_enabledService));
     if (!Cache::has($strHash)) {
         //Build shipment
         $Shipment = $this->buildShipmentFromCollection($objCollection);
         //Get Iso Config
         $Config = Isotope::getConfig();
         //UPS Rate Object
         $UPS = new Ups_Rate($Config->UpsAccessKey, $Config->UpsUsername, $Config->UpsPassword, $Config->UpsMode == 'test' ? true : false);
         try {
             $objResponse = $UPS->getRate($Shipment);
             $fltPrice = (double) $objResponse->RatedShipment[0]->TotalCharges->MonetaryValue;
         } catch (\Exception $e) {
             //@!TODO post error message
         }
         Cache::set($strHash, $fltPrice);
     }
     return Cache::get($strHash);
 }
Example #3
0
 /**
  * Get the details of a page including inherited parameters
  *
  * @param mixed $intId A page ID or a Model object
  *
  * @return \PageModel The page model or null
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use PageModel::findWithDetails() or PageModel->loadDetails() instead.
  */
 public static function getPageDetails($intId)
 {
     trigger_error('Using Controller::getPageDetails() has been deprecated and will no longer work in Contao 5.0. Use PageModel::findWithDetails() or PageModel->loadDetails() instead.', E_USER_DEPRECATED);
     if ($intId instanceof \PageModel) {
         return $intId->loadDetails();
     } elseif ($intId instanceof \Model\Collection) {
         /** @var \PageModel $objPage */
         $objPage = $intId->current();
         return $objPage->loadDetails();
     } elseif (is_object($intId)) {
         $strKey = __METHOD__ . '-' . $intId->id;
         // Try to load from cache
         if (\Cache::has($strKey)) {
             return \Cache::get($strKey);
         }
         // Create a model from the database result
         $objPage = new \PageModel();
         $objPage->setRow($intId->row());
         $objPage->loadDetails();
         \Cache::set($strKey, $objPage);
         return $objPage;
     } else {
         // Invalid ID
         if (!strlen($intId) || $intId < 1) {
             return null;
         }
         $strKey = __METHOD__ . '-' . $intId;
         // Try to load from cache
         if (\Cache::has($strKey)) {
             return \Cache::get($strKey);
         }
         $objPage = \PageModel::findWithDetails($intId);
         \Cache::set($strKey, $objPage);
         return $objPage;
     }
 }