/** * {@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()); }
/** * @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 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'); }
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); }
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ł'); }
function it_gets_current_currency_code_from_context(CurrencyContextInterface $currencyContext) { $currencyContext->getCurrencyCode()->willReturn('USD'); $this->getCurrencyCode()->shouldReturn('USD'); }
/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null, $locale = null) { $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode(); return $this->decoratedHelper->convertAndFormatAmount($amount, $currencyCode, $locale); }
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'); }
/** * {@inheritdoc} */ public function getCurrencyCode() { return $this->currencyContext->getCurrencyCode(); }
/** * @return Response */ public function renderAction() { return $this->templatingEngine->renderResponse('@SyliusShop/_currencySwitch.html.twig', ['active' => $this->currencyContext->getCurrencyCode(), 'currencies' => $this->currencyProvider->getAvailableCurrenciesCodes()]); }
/** * @return Response */ public function renderSelectorAction() { return $this->templatingEngine->renderResponse('SyliusShopBundle:Currency:selector.html.twig', ['activeCurrencyCode' => $this->currencyContext->getCurrencyCode(), 'availableCurrenciesCodes' => $this->currencyProvider->getAvailableCurrenciesCodes()]); }
/** * {@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); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['currency' => $this->currencyContext->getCurrencyCode()]); }
/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null) { $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode(); $amount = $this->currencyConverter->convertFromBase($amount, $currencyCode); return $this->moneyFormatter->format($amount, $currencyCode); }