Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getExchangeRate($baseCurrency = null, $targetCurrency = null)
 {
     $baseCurrency = null === $baseCurrency ? $this->requestHelper->getCurrentCurrency() : $baseCurrency;
     $targetCurrency = null === $targetCurrency ? $this->requestHelper->getCurrentCurrency() : $targetCurrency;
     $this->loadExchangeRates($targetCurrency);
     if (!isset($this->exchangeRates[$targetCurrency][$baseCurrency])) {
         throw new MissingCurrencyRateException($baseCurrency, $targetCurrency);
     }
     return $this->exchangeRates[$targetCurrency][$baseCurrency];
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function format($amount, $currency = null, $locale = null)
 {
     if (null === $currency) {
         $currency = $this->requestHelper->getCurrentCurrency();
     }
     if (null === $locale) {
         $locale = $this->requestHelper->getCurrentLocale();
     }
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     if (false === ($result = $formatter->formatCurrency($amount, $currency))) {
         throw new CurrencyFormatterException($amount, $currency, $locale);
     }
     return $result;
 }
 /**
  * Adds an additional left-join to currency_rate to calculate final prices in dataset
  *
  * @param QueryBuilder $queryBuilder
  */
 private function addCurrencyRateConditions(QueryBuilder $queryBuilder)
 {
     $queryBuilder->leftJoin('WellCommerce\\AppBundle\\Entity\\CurrencyRate', 'currency_rate', Expr\Join::WITH, 'currency_rate.currencyFrom = product.sellPrice.currency AND currency_rate.currencyTo = :targetCurrency');
     $queryBuilder->setParameter('targetCurrency', $this->requestHelper->getCurrentCurrency());
 }