Esempio n. 1
0
 function it_formats_money_using_default_currency_and_locale_if_only_amount_is_given(LocaleContextInterface $localeContext, CurrencyContextInterface $currencyContext, MoneyFormatterInterface $moneyFormatter)
 {
     $localeContext->getDefaultLocale()->willReturn('fr_FR');
     $currencyContext->getCurrencyCode()->willReturn('EUR');
     $moneyFormatter->format(500, 'EUR', 'fr_FR')->willReturn('€5.00');
     $this->formatAmount(500)->shouldReturn('€5.00');
 }
 /**
  * {@inheritdoc}
  */
 public function update(OrderInterface $order)
 {
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyRepository->findOneBy(['code' => $this->currencyContext->getCurrencyCode()]);
     $order->setCurrencyCode($currency->getCode());
     $order->setExchangeRate($currency->getExchangeRate());
 }
Esempio n. 3
0
 /**
  * @param GenericEvent $event
  *
  * @throws UnexpectedTypeException when event's subject is not an order
  */
 public function processOrderCurrency(GenericEvent $event)
 {
     $order = $event->getSubject();
     if (!$order instanceof OrderInterface) {
         throw new UnexpectedTypeException($order, OrderInterface::class);
     }
     $order->setCurrencyCode($this->currencyContext->getCurrencyCode());
 }
 function its_nested_request_resolvers_can_have_priority(CurrencyContextInterface $firstCurrencyContext, CurrencyContextInterface $secondCurrencyContext, CurrencyContextInterface $thirdCurrencyContext)
 {
     $firstCurrencyContext->getCurrencyCode()->shouldNotBeCalled();
     $secondCurrencyContext->getCurrencyCode()->willReturn('BTC');
     $thirdCurrencyContext->getCurrencyCode()->willThrow(CurrencyNotFoundException::class);
     $this->addContext($firstCurrencyContext, -5);
     $this->addContext($secondCurrencyContext, 0);
     $this->addContext($thirdCurrencyContext, 5);
     $this->getCurrencyCode()->shouldReturn('BTC');
 }
 function it_updates_order_exchange_rate(OrderInterface $order, CurrencyContextInterface $currencyContext, RepositoryInterface $currencyRepository, CurrencyInterface $currency, ChannelInterface $channel)
 {
     $order->getChannel()->willReturn($channel);
     $currencyContext->getCurrencyCode()->willReturn('GBP');
     $currencyRepository->findOneBy(['code' => 'GBP'])->willReturn($currency);
     $currency->getExchangeRate()->willReturn(3.5);
     $currency->getCode()->willReturn('GBP');
     $order->setCurrencyCode('GBP')->shouldBeCalled();
     $order->setExchangeRate(3.5)->shouldBeCalled();
     $this->update($order);
 }
Esempio n. 6
0
 function it_allows_to_convert_and_format_prices_in_different_currencies(CurrencyContextInterface $currencyContext, CurrencyConverterInterface $converter, MoneyFormatterInterface $moneyFormatter)
 {
     $currencyContext->getCurrencyCode()->willReturn('PLN');
     $converter->convertFromBase(15, 'USD')->willReturn(19);
     $converter->convertFromBase(2500, 'USD')->willReturn(1913);
     $converter->convertFromBase(312, 'PLN')->willReturn(407);
     $converter->convertFromBase(500, 'PLN')->willReturn(653);
     $moneyFormatter->format(19, 'USD')->willReturn('$0.19');
     $moneyFormatter->format(1913, 'USD')->willReturn('$19.13');
     $moneyFormatter->format(407, 'PLN')->willReturn('4.07 zł');
     $moneyFormatter->format(653, 'PLN')->willReturn('6.53 zł');
     $this->convertAndFormatAmount(15, 'USD')->shouldReturn('$0.19');
     $this->convertAndFormatAmount(2500, 'USD')->shouldReturn('$19.13');
     $this->convertAndFormatAmount(312, 'PLN')->shouldReturn('4.07 zł');
     $this->convertAndFormatAmount(500)->shouldReturn('6.53 zł');
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['currency' => $this->currencyContext->getCurrency()]);
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultCurrency()
 {
     return $this->currencyContext->getCurrency();
 }
Esempio n. 9
0
 function it_decorates_the_helper_with_current_currency_if_it_is_not_passed(PriceHelperInterface $decoratedHelper, CurrencyContextInterface $currencyContext)
 {
     $currencyContext->getCurrencyCode()->willReturn('EUR');
     $decoratedHelper->convertAndFormatAmount(42, 'EUR', null, null)->willReturn('€0.42');
     $this->convertAndFormatAmount(42)->shouldReturn('€0.42');
 }
Esempio n. 10
0
 /**
  * Convert amount and format it!
  *
  * @param int         $amount
  * @param string|null $currency
  * @param bool        $decimal
  *
  * @return string
  */
 public function convertAndFormatAmount($amount, $currency = null, $decimal = false)
 {
     $currency = $currency ?: $this->currencyContext->getCurrency();
     $amount = $this->converter->convertFromBase($amount, $currency);
     return $this->moneyHelper->formatAmount($amount, $currency, $decimal);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function getCurrencyCode()
 {
     return $this->currencyContext->getCurrencyCode();
 }
Esempio n. 12
0
 /**
  * @return Response
  */
 public function renderSelectorAction()
 {
     return $this->templatingEngine->renderResponse('SyliusShopBundle:Currency:selector.html.twig', ['activeCurrencyCode' => $this->currencyContext->getCurrencyCode(), 'availableCurrenciesCodes' => $this->currencyProvider->getAvailableCurrenciesCodes()]);
 }
Esempio n. 13
0
 /**
  * @return Response
  */
 public function renderAction()
 {
     return $this->templatingEngine->renderResponse('@SyliusShop/_currencySwitch.html.twig', ['active' => $this->currencyContext->getCurrencyCode(), 'currencies' => $this->currencyProvider->getAvailableCurrenciesCodes()]);
 }
Esempio n. 14
0
 /**
  * @return string
  */
 public function getCurrentCurrencySymbol()
 {
     return Intl::getCurrencyBundle()->getCurrencySymbol($this->currencyContext->getCurrency());
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 public function convertAndFormatAmount($amount, $currencyCode = null, $locale = null)
 {
     $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode();
     return $this->decoratedHelper->convertAndFormatAmount($amount, $currencyCode, $locale);
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function formatAmount($amount, $currencyCode = null, $locale = null)
 {
     $locale = $locale ?: $this->localeContext->getDefaultLocale();
     $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode();
     return $this->moneyFormatter->format($amount, $currencyCode, $locale);
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('currency' => $this->currencyContext->getCurrency()));
 }
Esempio n. 18
0
 function it_provides_current_currency(CurrencyContextInterface $currencyContext)
 {
     $currencyContext->getCurrency()->willReturn('PLN');
     $this->getCurrentCurrencySymbol()->shouldReturn('PLN');
 }
Esempio n. 19
0
 function it_gets_current_currency_code_from_context(CurrencyContextInterface $currencyContext)
 {
     $currencyContext->getCurrencyCode()->willReturn('USD');
     $this->getCurrencyCode()->shouldReturn('USD');
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function convertAndFormatAmount($amount, $currencyCode = null)
 {
     $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode();
     $amount = $this->currencyConverter->convertFromBase($amount, $currencyCode);
     return $this->moneyFormatter->format($amount, $currencyCode);
 }