static function convertAdditionalPrice($toCurrency, $value) { if ($toCurrency == false) { return $value; } $converter = eZCurrencyConverter::instance(); $converter->setRoundingType(eZCurrencyConverter::ROUNDING_TYPE_ROUND); $converter->setRoundingPrecision(2); $converter->setRoundingTarget(false); return $converter->convertFromLocaleCurrency($toCurrency, $value, true); }
static function updateAutoprices() { // use direct sql-queries to speed up the process. $converter = eZCurrencyConverter::instance(); $currencyList = $converter->currencyList(); $currencyListCount = count( $currencyList ); if ( $currencyListCount > 0 ) { $fetchCount = self::FETCH_DATA_LIST_LIMIT; $fetchOffset = 0; $sql = "SELECT DISTINCT ezmultipricedata.* FROM ezmultipricedata, ezcontentobject, ezcontentobject_attribute WHERE ezmultipricedata.contentobject_attr_id = ezcontentobject_attribute.id AND ezcontentobject_attribute.contentobject_id = ezcontentobject.id AND ezmultipricedata.contentobject_attr_version = ezcontentobject.current_version ORDER BY ezmultipricedata.contentobject_attr_id, ezmultipricedata.type"; $objectAttributeID = false; $fromCurrency = false; $fromValue = 0; $db = eZDB::instance(); $db->begin(); while( $fetchCount === self::FETCH_DATA_LIST_LIMIT ) { $multipriceDataList = $db->arrayQuery( $sql, array( 'offset' => $fetchOffset, 'limit' => $fetchCount ) ); $fetchCount = count( $multipriceDataList ); $fetchOffset += $fetchCount; foreach ( $multipriceDataList as $multipriceData ) { if ( $multipriceData['contentobject_attr_id'] != $objectAttributeID ) { // process next attribute. $objectAttributeID = $multipriceData['contentobject_attr_id']; // use value of the first custom price as base price. $fromCurrency = $multipriceData['currency_code']; $fromValue = $multipriceData['value']; } if ( $multipriceData['type'] == self::VALUE_TYPE_AUTO ) { $value = $converter->convert( $fromCurrency, $multipriceData['currency_code'], $fromValue ); $updateSql = "UPDATE ezmultipricedata SET value = '$value' WHERE id = {$multipriceData['id']}"; $db->query( $updateSql ); } } } $db->commit(); } $error = array( 'code' => self::ERROR_OK, 'description' => ezpI18n::tr( 'kernel/shop', "'Auto' prices were updated successfully." ) ); return $error; }
function updateAutoPriceList() { $converter = eZCurrencyConverter::instance(); $basePrice = $this->basePrice(); $basePriceValue = $basePrice ? $basePrice->attribute('value') : 0; $baseCurrencyCode = $basePrice ? $basePrice->attribute('currency_code') : false; $autoCurrencyList = $this->autoCurrencyList(); foreach ($autoCurrencyList as $currencyCode => $currency) { $autoValue = $converter->convert($baseCurrencyCode, $currencyCode, $basePriceValue); $this->setAutoPrice($currencyCode, $autoValue); } }