static function fetch($currencyCode, $asObject = true)
 {
     if ($currencyCode) {
         $currency = eZCurrencyData::fetchList(array('code' => $currencyCode), $asObject);
         if (is_array($currency) && count($currency) > 0) {
             return $currency[$currencyCode];
         }
     }
     return null;
 }
Esempio n. 2
0
 static function updateAutoRates()
 {
     $error = array('code' => eZExchangeRatesUpdateHandler::OK, 'description' => '');
     $handler = eZExchangeRatesUpdateHandler::create();
     if ($handler) {
         $error = $handler->requestRates();
         if ($error['code'] === eZExchangeRatesUpdateHandler::OK) {
             $rateList = $handler->rateList();
             if (is_array($rateList) && count($rateList) > 0) {
                 $handlerBaseCurrency = $handler->baseCurrency();
                 if ($handlerBaseCurrency) {
                     $shopBaseCurrency = false;
                     $shopINI = eZINI::instance('shop.ini');
                     if ($shopINI->hasVariable('ExchangeRatesSettings', 'BaseCurrency')) {
                         $shopBaseCurrency = $shopINI->variable('ExchangeRatesSettings', 'BaseCurrency');
                     }
                     if (!$shopBaseCurrency) {
                         $shopBaseCurrency = $handlerBaseCurrency;
                     }
                     // update rates for existing currencies
                     //$baseCurrencyCode = $handler->baseCurrency();
                     if (isset($rateList[$shopBaseCurrency]) || $shopBaseCurrency === $handlerBaseCurrency) {
                         // to avoid unnecessary multiplication set $crossBaseRate to 'false';
                         $crossBaseRate = false;
                         if ($shopBaseCurrency !== $handlerBaseCurrency) {
                             $crossBaseRate = 1.0 / (double) $rateList[$shopBaseCurrency];
                             $rateList[$handlerBaseCurrency] = '1.0000';
                         }
                         $currencyList = eZCurrencyData::fetchList();
                         if (is_array($currencyList) && count($currencyList) > 0) {
                             foreach ($currencyList as $currency) {
                                 $rateValue = false;
                                 $currencyCode = $currency->attribute('code');
                                 if (isset($rateList[$currencyCode])) {
                                     $rateValue = $rateList[$currencyCode];
                                     if ($crossBaseRate !== false) {
                                         $rateValue *= $crossBaseRate;
                                     }
                                 } else {
                                     if ($currencyCode === $shopBaseCurrency) {
                                         $rateValue = '1.0000';
                                     }
                                 }
                                 $currency->setAttribute('auto_rate_value', $rateValue);
                                 $currency->sync();
                             }
                         }
                         $error['code'] = eZExchangeRatesUpdateHandler::OK;
                         $error['description'] = ezpI18n::tr('kernel/shop', "'Auto' rates were updated successfully.");
                     } else {
                         $error['code'] = eZExchangeRatesUpdateHandler::INVALID_BASE_CROSS_RATE;
                         $error['description'] = ezpI18n::tr('kernel/shop', "Unable to calculate cross-rate for currency-pair '%1'/'%2'", null, array($handlerBaseCurrency, $shopBaseCurrency));
                     }
                 } else {
                     $error['code'] = eZExchangeRatesUpdateHandler::UNKNOWN_BASE_CURRENCY;
                     $error['description'] = ezpI18n::tr('kernel/shop', 'Unable to determine currency for retrieved rates.');
                 }
             } else {
                 $error['code'] = eZExchangeRatesUpdateHandler::EMPTY_RATE_LIST;
                 $error['description'] = ezpI18n::tr('kernel/shop', 'Retrieved empty list of rates.');
             }
         }
     } else {
         $error['code'] = eZExchangeRatesUpdateHandler::CANT_CREATE_HANDLER;
         $error['description'] = ezpI18n::tr('kernel/shop', 'Unable to create handler to update auto rates.');
     }
     if ($error['code'] !== eZExchangeRatesUpdateHandler::OK) {
         eZDebug::writeError($error['description'], __METHOD__);
     }
     return $error;
 }
Esempio n. 3
0
    function currencyList()
    {
        if ( !isset( $this->CurrencyList ) )
        {
            $this->CurrencyList = eZCurrencyData::fetchList();
        }

        return $this->CurrencyList;
    }
    function fetchCurrencyList( $status = false )
    {
        $conditions = null;
        $status = eZCurrencyData::statusStringToNumeric( $status );
        if ( $status !== false )
        {
            $conditions = array( 'status' => $status );
        }

        $currencyList = eZCurrencyData::fetchList( $conditions );

        $result = array( 'result' => $currencyList );

        return $result;
    }
Esempio n. 5
0
    if ($error['code'] != 0) {
        $error['style'] = 'message-error';
    } else {
        $error['style'] = 'message-feedback';
    }
}
switch (eZPreferences::value('currencies_list_limit')) {
    case '2':
        $limit = 25;
        break;
    case '3':
        $limit = 50;
        break;
    default:
        $limit = 10;
        break;
}
// fetch currencies
$currencyList = eZCurrencyData::fetchList(null, true, $offset, $limit);
$currencyCount = eZCurrencyData::fetchListCount();
$viewParameters = array('offset' => $offset);
$tpl = eZTemplate::factory();
$tpl->setVariable('currency_list', $currencyList);
$tpl->setVariable('currency_list_count', $currencyCount);
$tpl->setVariable('limit', $limit);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('show_error_message', $error !== false);
$tpl->setVariable('error', $error);
$Result = array();
$Result['path'] = array(array('text' => ezpI18n::tr('kernel/shop', 'Available currency list'), 'url' => false));
$Result['content'] = $tpl->fetch("design:shop/currencylist.tpl");
function currencyForLocale($localeString = false)
{
    global $cli;
    global $currencyList;
    $currency = false;
    if ($currencyList === false) {
        $currencyList = eZCurrencyData::fetchList();
    }
    $locale = eZLocale::instance($localeString);
    if (is_object($locale)) {
        // get currency
        if ($currencyCode = $locale->currencyShortName()) {
            if (!isset($currencyList[$currencyCode])) {
                $cli->warning("Currency '{$currencyCode}' doesn't exist");
                $cli->notice("Creating currency '{$currencyCode}'... ", false);
                $currencySymbol = $locale->currencySymbol();
                $localeCode = $locale->localeFullCode();
                if ($currency = eZCurrencyData::create($currencyCode, $currencySymbol, $localeCode, '0.00000', '1.00000', '0.00000')) {
                    $cli->output('Ok');
                    $currency->store();
                    $currencyList[$currencyCode] = $currency;
                } else {
                    $cli->error('Failed');
                }
            } else {
                $currency = $currencyList[$currencyCode];
            }
        } else {
            $cli->error("Unable to find currency code for the '{$localeString}' locale");
        }
    } else {
        $cli->error("Unable to find '{$localeString}' locale");
    }
    return $currency;
}