/** * 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); }
static function createCurrency($currencyParams) { $currency = eZCurrencyData::create($currencyParams['code'], $currencyParams['symbol'], $currencyParams['locale'], '0.0000', $currencyParams['custom_rate_value'], $currencyParams['rate_factor']); if (is_object($currency)) { $db = eZDB::instance(); $db->begin(); $currency->store(); eZMultiPriceData::createPriceListForCurrency($currencyParams['code']); $db->commit(); } }
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; }