Exemplo n.º 1
0
 public function process()
 {
     $source = CurrencyRateSource::getInstance($this->application);
     foreach ($source->getAllCurrencyCodes() as $currencyCode) {
         $rate = $source->getRate($currencyCode);
         if ($rate != null) {
             $currency = Currency::getInstanceById($currencyCode);
             $currency->rate->set($rate);
             $currency->lastUpdated->set(date('Y-m-d H:i:s', time()));
             $currency->save();
         }
     }
     $this->application->getCache()->set('currencyRateUpdateTs', time());
 }
Exemplo n.º 2
0
 /**
  * Sets default currency.
  * @role status
  * @return ActionRedirectResponse
  */
 public function setDefault()
 {
     try {
         $r = ActiveRecord::getInstanceByID('Currency', $this->request->get('id'), true);
     } catch (ARNotFoundException $e) {
         return new ActionRedirectResponse('backend.currency', 'index');
     }
     ActiveRecord::beginTransaction();
     $update = new ARUpdateFilter();
     $update->addModifier('isDefault', 0);
     ActiveRecord::updateRecordSet('Currency', $update);
     $r->setAsDefault(true);
     $r->save();
     $config = $this->getApplication()->getConfig();
     if ($config->get('CURRENCY_RATE_UPDATE')) {
         $source = CurrencyRateSource::getInstance($this->application, $r->getID());
         foreach ($source->getAllCurrencyCodes() as $currencyCode) {
             $rate = $source->getRate($currencyCode);
             if ($rate != null) {
                 $currency = Currency::getInstanceById($currencyCode);
                 $currency->rate->set($rate);
                 $currency->lastUpdated->set(date('Y-m-d H:i:s', time()));
                 $currency->save();
             }
         }
     }
     ActiveRecord::commit();
     return new ActionRedirectResponse('backend.currency', 'index');
 }