本文整理汇总了PHP中eZCurrencyData类的典型用法代码示例。如果您正苦于以下问题:PHP eZCurrencyData类的具体用法?PHP eZCurrencyData怎么用?PHP eZCurrencyData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了eZCurrencyData类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMultipleCallsToCalculatedPrice
/**
* Test scenario for issue #13712: Multiprice datatype shows wrong price after multiple calls in template
*
* Test Outline
* ------------
* 1. Create a euro currency
* 2. Create a VAT type of 10 %
* 3. Create a content class with an attribute of the datatype ezmultiprice
* 4. Create a content object of this content class and set a custom price ex. VAT with the VAT type of 10% that we created
* 5. Subsequently retrieve the attribute 'inc_vat_price_list'
*
* @result: the returned eZMultiPriceData instances differ on each call, their values are increased each time with VAT
* @expected: the returned eZMultiPriceData instances are equal
* @link http://issues.ez.no/13712
* @group issue_13712
*/
public function testMultipleCallsToCalculatedPrice()
{
$currencyCode = 'EUR';
// create currency
$currencyParams = array('code' => $currencyCode, 'symbol' => false, 'locale' => 'eng-GB', 'custom_rate_value' => 0, 'rate_factor' => 1);
$currency = eZCurrencyData::create($currencyCode, '€', 'eng-GB', 0, 0, 1);
$currency->store();
$currencyID = $currency->attribute('id');
$this->assertInternalType('integer', $currencyID);
// create VAT type
$row = array('name' => 'Test', 'percentage' => 10.0);
$vatType = new eZVatType($row);
$vatType->store();
$vatTypeID = $vatType->attribute('id');
$this->assertInternalType('integer', $vatTypeID);
$class = eZContentClass::create(false, array('name' => 'eZMultiPrice::testMultipleCallsToCalculatedPrice', 'identifier' => 'ezmultiprice_test'));
$class->store();
$classID = $class->attribute('id');
$this->assertInternalType('integer', $classID);
$attributes = $class->fetchAttributes();
// add class attributes
$newAttribute = eZContentClassAttribute::create($classID, 'ezmultiprice', array('name' => 'Test', 'identifier' => 'test'));
$dataType = $newAttribute->dataType();
$dataType->initializeClassAttribute($newAttribute);
$newAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $currencyCode);
$newAttribute->setAttribute(eZMultiPriceType::VAT_ID_FIELD, $vatTypeID);
$newAttribute->store();
$attributes[] = $newAttribute;
$class->storeDefined($attributes);
$contentObject = $class->instantiate();
$version = $contentObject->currentVersion();
$dataMap = $version->dataMap();
$multiPrice = $dataMap['test']->content();
$multiPrice->setAttribute('selected_vat_type', $vatTypeID);
$multiPrice->setAttribute('is_vat_included', eZMultiPriceType::EXCLUDED_VAT);
$multiPrice->setCustomPrice($currencyCode, 100);
$multiPrice->updateAutoPriceList();
$dataMap['test']->setContent($multiPrice);
$dataMap['test']->setAttribute('data_text', $vatTypeID . ',' . eZMultiPriceType::EXCLUDED_VAT);
$dataMap['test']->store();
// test values
$firstIncVatPriceList = $multiPrice->attribute('inc_vat_price_list');
$this->assertArrayHasKey('EUR', $firstIncVatPriceList);
$firstCallValue = $firstIncVatPriceList['EUR']->attribute('value');
$secondIncVatPriceList = $multiPrice->attribute('inc_vat_price_list');
$this->assertArrayHasKey('EUR', $secondIncVatPriceList);
$secondCallValue = $secondIncVatPriceList['EUR']->attribute('value');
$this->assertEquals($firstCallValue, $secondCallValue);
$thirdIncVatPriceList = $multiPrice->attribute('inc_vat_price_list');
$this->assertArrayHasKey('EUR', $thirdIncVatPriceList);
$thirdCallValue = $thirdIncVatPriceList['EUR']->attribute('value');
$this->assertEquals($firstCallValue, $thirdCallValue);
}
示例2: updateAutoRates
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;
}
示例3: currencyList
function currencyList()
{
if ( !isset( $this->CurrencyList ) )
{
$this->CurrencyList = eZCurrencyData::fetchList();
}
return $this->CurrencyList;
}
示例4: fetchCurrency
function fetchCurrency( $code )
{
$currency = eZCurrencyData::fetch( $code );
if ( is_object( $currency ) )
$result = array( 'result' => $currency );
else
$result = array( 'result' => false );
return $result;
}
示例5: setStatus
function setStatus($status)
{
$statusNumeric = eZCurrencyData::statusStringToNumeric($status);
if ($statusNumeric !== false) {
$this->setAttribute('status', $statusNumeric);
} else {
eZDebug::writeError("Unknow currency's status '{$status}'", __METHOD__);
}
}
示例6: switch
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");
示例7: checkCurrency
function checkCurrency($orderID)
{
$returnStatus = array('status' => eZModuleOperationInfo::STATUS_CONTINUE);
$order = eZOrder::fetch($orderID);
$productCollection = $order->attribute('productcollection');
$currencyCode = $productCollection->attribute('currency_code');
$currencyCode = trim($currencyCode);
if ($currencyCode == '') {
$returnStatus = array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
}
$locale = eZLocale::instance();
$localeCurrencyCode = $locale->currencyShortName();
// Reverse logic to avoid calling eZCurrencyData::currencyExists() if the first expression is true.
if (!($currencyCode == $localeCurrencyCode or eZCurrencyData::currencyExists($currencyCode))) {
$returnStatus = array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
}
return $returnStatus;
}
示例8:
}
}
} else {
$error = eZCurrencyData::errorMessage($errCode);
}
}
}
}
$pathText = '';
if (strlen($originalCurrencyCode) > 0) {
// going to edit existing currency
$pathText = ezpI18n::tr('kernel/shop', 'Edit currency');
if ($currencyParams['code'] === false) {
// first time in 'edit' mode? => initialize template variables
// with existing data.
$currency = eZCurrencyData::fetch($originalCurrencyCode);
if (is_object($currency)) {
$currencyParams['code'] = $currency->attribute('code');
$currencyParams['symbol'] = $currency->attribute('symbol');
$currencyParams['locale'] = $currency->attribute('locale');
$currencyParams['custom_rate_value'] = $currency->attribute('custom_rate_value');
$currencyParams['rate_factor'] = $currency->attribute('rate_factor');
} else {
$error = "'{$originalCurrencyCode}' currency doesn't exist.";
$canEdit = false;
}
}
} else {
// going to create new currency
$pathText = ezpI18n::tr('kernel/shop', 'Create new currency');
}
示例9: currencyForLocale
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;
}