function it_handles_shop_currency_code_change(CurrencyStorageInterface $currencyStorage, ChannelContextInterface $channelContext, EventDispatcherInterface $eventDispatcher, ChannelInterface $channel)
 {
     $channelContext->getChannel()->willReturn($channel);
     $currencyStorage->set($channel, 'USD')->shouldBeCalled();
     $eventDispatcher->dispatch(SyliusCurrencyEvents::CODE_CHANGED, Argument::type(GenericEvent::class))->shouldBeCalled();
     $this->handle('USD');
 }
 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 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 handle($code)
 {
     try {
         $this->currencyStorage->set($this->channelContext->getChannel(), $code);
     } catch (ChannelNotFoundException $exception) {
         throw new HandleException(self::class, 'Sylius could not find the channel.', $exception);
     }
     $this->eventDispatcher->dispatch(SyliusCurrencyEvents::CODE_CHANGED, new GenericEvent($code));
 }
Exemple #5
0
 /**
  * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
  * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
  * @Given the store operates on a channel identified by :code code
  */
 public function theStoreOperatesOnAChannelNamed($channelIdentifier, $currencyCode = null)
 {
     $defaultData = $this->defaultChannelFactory->create($channelIdentifier, $channelIdentifier, $currencyCode);
     $this->sharedStorage->setClipboard($defaultData);
     $this->sharedStorage->set('channel', $defaultData['channel']);
     $this->currencyStorage->set($defaultData['channel'], $defaultData['currency']->getCode());
 }
 /**
  * @Given the customer has chosen to order in the :currencyCode currency
  * @Given I have chosen to order in the :currencyCode currency
  */
 public function theCustomerChoseTheCurrency($currencyCode)
 {
     $this->currencyStorage->set($this->sharedStorage->get('channel'), $currencyCode);
     /** @var OrderInterface $order */
     $order = $this->sharedStorage->get('order');
     $order->setCurrencyCode($currencyCode);
     $this->objectManager->flush();
 }
Exemple #7
0
 /**
  * @Given /^(that channel) uses the "([^"]+)" currency by default$/
  * @Given /^(it) uses the "([^"]+)" currency by default$/
  */
 public function itUsesTheCurrencyByDefault(ChannelInterface $channel, $currencyCode)
 {
     $currency = $this->provideCurrency($currencyCode);
     $currency->setExchangeRate(1.0);
     $this->currencyManager->flush();
     $channel->addCurrency($currency);
     $channel->setDefaultCurrency($currency);
     $this->channelManager->flush();
     $this->sharedStorage->set('currency', $currency);
     $this->currencyStorage->set($channel, $currency->getCode());
 }
Exemple #8
0
 /**
  * @Given the customer chose :currencyCode currency
  * @Given I chose :currencyCode currency
  */
 public function theCustomerChoseTheCurrency($currencyCode)
 {
     $this->currencyStorage->set($this->sharedStorage->get('channel'), $currencyCode);
 }
 /**
  * @param Request $request
  * @param string $code
  *
  * @return Response
  */
 public function switchCurrencyAction(Request $request, $code)
 {
     $this->currencyStorage->set($this->channelContext->getChannel(), $code);
     return new RedirectResponse($request->headers->get('referer'));
 }