function it_throws_an_exception_if_currency_taken_from_storage_is_not_available(ChannelContextInterface $channelContext, CurrencyStorageInterface $currencyStorage, CurrencyProviderInterface $currencyProvider, ChannelInterface $channel)
 {
     $channelContext->getChannel()->willReturn($channel);
     $currencyStorage->get($channel)->willReturn('BTC');
     $currencyProvider->getAvailableCurrenciesCodes()->willReturn(['LTC', 'PLN']);
     $this->shouldThrow(CurrencyNotFoundException::class)->during('getCurrencyCode');
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $choices = null;
     foreach ($this->currencyProvider->getAvailableCurrencies() as $currency) {
         $choices[$currency->getCode()] = sprintf('%s - %s', $currency->getCode(), $currency->getName());
     }
     $resolver->setDefaults(['choices' => $choices]);
 }
Esempio n. 3
0
 /**
  * @param Request $request
  * @param string $code
  *
  * @return Response
  */
 public function switchAction(Request $request, $code)
 {
     if (!in_array($code, $this->currencyProvider->getAvailableCurrenciesCodes())) {
         throw new HttpException(Response::HTTP_NOT_ACCEPTABLE, sprintf('The currency code "%s" is invalid.', $code));
     }
     $this->currencyChangeHandler->handle($code);
     return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choices = null;
     foreach ($this->currencyProvider->getAvailableCurrencies() as $currency) {
         $choices[$currency->getCode()] = sprintf('%s - %s', $currency->getCode(), $currency->getName());
     }
     $resolver->setDefaults(array('choices' => $choices));
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $currencies = array();
     foreach ($this->currencyProvider->getAvailableCurrencies() as $currency) {
         $currencies[$currency->getCode()] = $currency->getName();
     }
     $builder->add('currency', 'choice', array('choices' => $currencies))->add('product', 'hidden', array('mapped' => false))->add('state', 'choice', array('choices' => array(OrderInterface::STATE_CART => 'sylius.order.state.checkout', OrderInterface::STATE_CART_LOCKED => 'sylius.order.state.cart_locked', OrderInterface::STATE_PENDING => 'sylius.order.state.ordered', OrderInterface::STATE_CONFIRMED => 'sylius.order.state.order_confimed', OrderInterface::STATE_SHIPPED => 'sylius.order.state.shipped', OrderInterface::STATE_ABANDONED => 'sylius.order.state.abandoned', OrderInterface::STATE_CANCELLED => 'sylius.order.state.cancelled', OrderInterface::STATE_RETURNED => 'sylius.order.state.returned')));
 }
 /**
  * {@inheritdoc}
  */
 public function getCurrencyCode()
 {
     $availableCurrenciesCodes = $this->currencyProvider->getAvailableCurrenciesCodes();
     $currencyCode = $this->currencyStorage->get($this->channelContext->getChannel());
     if (!in_array($currencyCode, $availableCurrenciesCodes, true)) {
         throw CurrencyNotFoundException::notAvailable($currencyCode, $availableCurrenciesCodes);
     }
     return $currencyCode;
 }
 /**
  * {@inheritdoc}
  */
 public function getCurrencyCode()
 {
     $availableCurrenciesCodes = $this->currencyProvider->getAvailableCurrenciesCodes();
     $currencyCode = $this->currencyProvider->getDefaultCurrencyCode();
     if (!in_array($currencyCode, $availableCurrenciesCodes, true)) {
         throw CurrencyNotFoundException::notAvailable($currencyCode, $availableCurrenciesCodes);
     }
     return $currencyCode;
 }
Esempio n. 8
0
 /**
  * Builds frontend currency menu.
  *
  * @return ItemInterface
  */
 public function createCurrencyMenu()
 {
     $menu = $this->factory->createItem('root', array('childrenAttributes' => array('class' => 'nav nav-pills')));
     $currencies = $this->currencyProvider->getAvailableCurrencies();
     if (1 === count($currencies)) {
         $menu->setDisplay(false);
         return $menu;
     }
     foreach ($currencies as $currency) {
         $code = $currency->getCode();
         $menu->addChild($code, array('route' => 'sylius_currency_change', 'routeParameters' => array('currency' => $code), 'linkAttributes' => array('title' => $this->translate('sylius.frontend.menu.currency', array('%currency%' => $code)))))->setLabel(Intl::getCurrencyBundle()->getCurrencySymbol($code));
     }
     return $menu;
 }
Esempio n. 9
0
 /**
  * Builds frontend currency menu.
  *
  * @return ItemInterface
  */
 public function createCurrencyMenu()
 {
     $menu = $this->factory->createItem('root', ['childrenAttributes' => ['class' => 'nav nav-pills']]);
     $currencies = $this->currencyProvider->getAvailableCurrenciesCodes();
     if (1 === count($currencies)) {
         $menu->setDisplay(false);
         return $menu;
     }
     foreach ($currencies as $currency) {
         $code = $currency->getCode();
         $menu->addChild($code, ['route' => 'sylius_currency_change', 'routeParameters' => ['currencyCode' => $code], 'linkAttributes' => ['title' => $this->translate('sylius.frontend.menu.currency', ['%currency%' => $code])]])->setLabel(Intl::getCurrencyBundle()->getCurrencySymbol($code));
     }
     $this->eventDispatcher->dispatch(MenuBuilderEvent::FRONTEND_CURRENCY, new MenuBuilderEvent($this->factory, $menu));
     return $menu;
 }
Esempio n. 10
0
 function it_provides_current_currency(CurrencyProviderInterface $currencyProvider, CurrencyInterface $currency)
 {
     $currencyProvider->getBaseCurrency()->willReturn($currency);
     $currency->getCode()->willReturn('PLN');
     $this->getBaseCurrencySymbol()->shouldReturn('PLN');
 }
 function it_throws_a_currency_not_found_exception_if_default_currency_is_not_available(CurrencyProviderInterface $currencyProvider)
 {
     $currencyProvider->getAvailableCurrenciesCodes()->willReturn(['GBP', 'PLN']);
     $currencyProvider->getDefaultCurrencyCode()->willReturn('EUR');
     $this->shouldThrow(CurrencyNotFoundException::class)->during('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 string
  */
 public function getBaseCurrencySymbol()
 {
     return Intl::getCurrencyBundle()->getCurrencySymbol($this->currencyProvider->getBaseCurrency()->getCode());
 }
Esempio n. 14
0
 /**
  * @return string
  */
 public function getBaseCurrencyCode()
 {
     return $this->currencyProvider->getBaseCurrency()->getCode();
 }