/**
  * Format currency, replace INTL currency symbol with configuration currency symbol
  *
  * @param float $value
  * @param string $currency Currency code
  * @param array $attributes Set of attributes of \NumberFormatter
  * @param array $textAttributes Set of text attributes of \NumberFormatter
  * @param array $symbols Set of symbols of \NumberFormatter
  * @param string|null $locale Locale of formatting
  * @return string
  */
 public function formatCurrency($value, $currency = null, array $attributes = array(), array $textAttributes = array(), array $symbols = array(), $locale = null)
 {
     if (!$currency) {
         $currency = $this->localeSettings->getCurrency();
     }
     $formatter = $this->getFormatter($locale, \NumberFormatter::CURRENCY, $attributes, $textAttributes, $symbols);
     $currencySymbol = $this->getSymbol(\NumberFormatter::CURRENCY_SYMBOL, \NumberFormatter::CURRENCY);
     $currencyIntlSymbol = $this->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL, \NumberFormatter::CURRENCY);
     $localizedCurrencySymbol = $this->localeSettings->getCurrencySymbolByCurrency($currency);
     $formattedString = $formatter->formatCurrency($value, $currency);
     return str_replace(array($currency, $currencySymbol, $currencyIntlSymbol), $localizedCurrencySymbol, $formattedString);
 }
 public function testGetCurrencyDefault()
 {
     $expectedCurrency = LocaleConfiguration::DEFAULT_CURRENCY;
     $this->configManager->expects($this->once())->method('get')->with('oro_locale.currency')->will($this->returnValue(null));
     $this->assertEquals($expectedCurrency, $this->localeSettings->getCurrency());
     $this->assertEquals($expectedCurrency, $this->localeSettings->getCurrency());
 }
 /**
  * {@inheritDoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(['choices' => function (Options $options) {
         $this->checkOptions($options);
         if ($options['full_currency_list']) {
             return Intl::getCurrencyBundle()->getCurrencyNames('en');
         }
         $currencies = $options['currencies_list'];
         if (!count($currencies)) {
             $currencies = $this->configManager->get('oro_currency.allowed_currencies');
         }
         $currencies = array_merge($currencies, (array) $options['additional_currencies']);
         if (empty($currencies)) {
             //TODO: Change the getting currency list from system configuration option
             //TODO: "functional currency of organization" when it will be added.
             $currencies = [$this->localeSettings->getCurrency()];
         }
         $this->checkCurrencies($currencies);
         return $this->getChoices($currencies, $options['compact']);
     }, 'compact' => false, 'currencies_list' => null, 'additional_currencies' => null, 'full_currency_list' => false]);
 }
示例#4
0
 /**
  * @param string $currency
  * @param string|null $locale
  * @return bool|null Null means that there are no currency symbol in string
  */
 public function isCurrencySymbolPrepend($currency = null, $locale = null)
 {
     if (!$locale) {
         $locale = $this->localeSettings->getLocale();
     }
     if (!$currency) {
         $currency = $this->localeSettings->getCurrency();
     }
     if (empty($this->currencySymbolPrepend[$locale]) || !array_key_exists($currency, $this->currencySymbolPrepend)) {
         $formatter = $this->getFormatter($locale, \NumberFormatter::CURRENCY);
         $pattern = $formatter->formatCurrency('123', $currency);
         preg_match('/^([^\\s\\xc2\\xa0]*)[\\s\\xc2\\xa0]*123(?:[,.]0+)?[\\s\\xc2\\xa0]*([^\\s\\xc2\\xa0]*)$/u', $pattern, $matches);
         if (!empty($matches[1])) {
             $this->currencySymbolPrepend[$locale][$currency] = true;
         } elseif (!empty($matches[2])) {
             $this->currencySymbolPrepend[$locale][$currency] = false;
         } else {
             $this->currencySymbolPrepend[$locale][$currency] = null;
         }
     }
     return $this->currencySymbolPrepend[$locale][$currency];
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $currencyCode = $this->localeSettings->getCurrency();
     $currencySymbol = $this->localeSettings->getCurrencySymbolByCurrency($currencyCode);
     $resolver->setDefaults(array('currency' => $currencyCode, 'currency_symbol' => $currencySymbol, 'grouping' => (bool) $this->numberFormatter->getAttribute(\NumberFormatter::GROUPING_USED), 'constraints' => array(new LessThan(array('value' => pow(10, 15))))));
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $currencyCode = $this->localeSettings->getCurrency();
     $currencySymbol = $this->localeSettings->getCurrencySymbolByCurrency($currencyCode);
     $resolver->setDefaults(array('currency' => $currencyCode, 'currency_symbol' => $currencySymbol, 'grouping' => (bool) $this->numberFormatter->getAttribute(\NumberFormatter::GROUPING_USED)));
 }
 /**
  * @param Order $order
  */
 public function setOrderCurrency(Order $order)
 {
     if (!$order->getCurrency()) {
         $order->setCurrency($this->localeSettings->getCurrency());
     }
 }
示例#8
0
 /**
  * Get default currency for application
  * @return string
  */
 public function getDefaultCurrency()
 {
     return $this->localeSettings->getCurrency();
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $currencyCode = $this->localeSettings->getCurrency();
     $currencySymbol = $this->localeSettings->getCurrencySymbolByCurrency($currencyCode);
     $resolver->setDefaults(['data_class' => 'Marello\\Bundle\\PricingBundle\\Entity\\ProductPrice', 'intention' => 'productprice', 'single_form' => true, 'currency' => $currencyCode, 'currency_symbol' => $currencySymbol]);
 }