Beispiel #1
0
 /**
  * Get all currency values and cache in memory
  */
 public function init()
 {
     // optimize
     if (!empty(self::$curList)) {
         return self::$curList;
     }
     $this->app->jbdebug->mark('jbmoney::init::start');
     $curParams = $this->_config->getGroup('cart.currency')->get('list');
     $ttl = (int) $this->_config->get('currency_ttl', 1440, 'cart.config');
     $cacheKey = $this->_jbcache->hash(array('params' => (array) $curParams, 'date' => date('d-m-Y'), 'ttl' => $ttl));
     self::$curList = $this->_jbcache->get($cacheKey, 'currency', true, array('ttl' => $ttl));
     if (empty(self::$curList)) {
         $elements = $this->app->jbcartposition->loadElements('currency');
         self::$curList = array(JBCartValue::DEFAULT_CODE => array('code' => JBCartValue::DEFAULT_CODE, 'value' => 1, 'name' => JText::_('JBZOO_CURRENCY_DEFAULT_CODE'), 'format' => $this->_defaultFormat), self::PERCENT => array('code' => self::PERCENT, 'value' => 1, 'name' => JText::_('JBZOO_CART_CURRENCY_PERCENT'), 'format' => array_merge($this->_defaultFormat, array('symbol' => self::PERCENT))));
         $noCache = null;
         // fallback flag
         /** @type JBCartElementCurrency $element */
         foreach ($elements as $element) {
             $code = $element->getCode();
             if (empty($code)) {
                 continue;
             }
             try {
                 if ($noCache) {
                     // speedup if fatal errors have appeared
                     $value = $element->getFallbackValue();
                 } else {
                     $value = $element->getValue($code);
                 }
             } catch (JBCartElementCurrencyException $e) {
                 $noCache = time();
                 $value = $element->getFallbackValue();
                 if (JDEBUG || !$this->app->jbenv->isSite()) {
                     $this->app->jbnotify->warning($e->getMessage());
                 }
             }
             if ($code && $value > 0) {
                 self::$curList[$code] = array('code' => $code, 'value' => $value, 'name' => $element->getName(), 'format' => $element->getFormat());
             }
         }
         if (count(self::$curList) == 2 || !isset(self::$curList['eur'])) {
             self::$curList['eur'] = self::$curList[JBCartValue::DEFAULT_CODE];
         }
         if (!$noCache) {
             $this->_jbcache->set($cacheKey, self::$curList, 'currency', true, array('ttl' => $ttl));
         }
     }
     $this->app->jbdebug->mark('jbmoney::init::finish');
     return self::$curList;
 }
Beispiel #2
0
 /**
  * @param mixed    $data
  * @param JSONData $rates
  * @param string   $baseCur
  */
 public function __construct($data = 0, $rates = null, $baseCur = null)
 {
     $this->app = App::getInstance('zoo');
     $this->_jbmoney = $this->app->jbmoney;
     $this->_jbvars = $this->app->jbvars;
     $this->_currencyMode = $this->app->jbmoney->getCurrencyMode();
     $this->_isDebug = JDEBUG;
     $this->_rates = (array) ($rates ? $rates : $this->_jbmoney->getData());
     $this->_baseCur = $baseCur ? $baseCur : $this->_jbmoney->getDefaultCur();
     list($this->_value, $this->_currency) = $this->_parse($data);
     self::$_counter++;
     $this->_id = self::$_counter;
     $this->_log('ValueId=' . $this->_id . ' has just created; Value = "' . $this->dump() . '"');
 }
Beispiel #3
0
 /**
  * @return string
  */
 public function getCurrency()
 {
     return $this->_jbmoney->getDefaultCur();
 }