/**
  * 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 testGetCurrencySymbolByCurrency()
 {
     $existingCurrencyCode = 'USD';
     $existingCurrencySymbol = '$';
     $notExistingCurrencyCode = 'UAK';
     $currencyData = [$existingCurrencyCode => ['symbol' => $existingCurrencySymbol]];
     $this->localeSettings->addCurrencyData($currencyData);
     $this->assertEquals($existingCurrencySymbol, $this->localeSettings->getCurrencySymbolByCurrency($existingCurrencyCode));
     $this->assertEquals($notExistingCurrencyCode, $this->localeSettings->getCurrencySymbolByCurrency($notExistingCurrencyCode));
 }
Пример #3
0
 /**
  * {@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)));
 }
Пример #4
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))))));
 }
Пример #5
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]);
 }