function it_proccess_order_channel_successfully(GenericEvent $event, OrderInterface $order, ChannelContextInterface $channelContext, ChannelInterface $channel) { $event->getSubject()->shouldBeCalled()->willReturn($order); $channelContext->getChannel()->shouldBeCalled()->willReturn($channel); $order->setChannel($channel)->shouldBeCalled(); $this->processOrderChannel($event); }
function it_does_not_cache_results_while_there_are_no_master_requests(ChannelContextInterface $decoratedChannelContext, RequestStack $requestStack, ChannelInterface $firstChannel, ChannelInterface $secondChannel) { $requestStack->getMasterRequest()->willReturn(null, null); $decoratedChannelContext->getChannel()->willReturn($firstChannel, $secondChannel)->shouldBeCalledTimes(2); $this->getChannel()->shouldReturn($firstChannel); $this->getChannel()->shouldReturn($secondChannel); }
function it_does_not_cache_channel_not_found_exceptions_for_null_master_requests(ChannelContextInterface $decoratedChannelContext, RequestStack $requestStack, ChannelInterface $channel) { $requestStack->getMasterRequest()->willReturn(null, null); $decoratedChannelContext->getChannel()->will(CompositePromise::it()->willThrow(ChannelNotFoundException::class)->andThenReturn($channel))->shouldBeCalledTimes(2); $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel'); $this->getChannel()->shouldReturn($channel); }
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 getAvailableCurrencies() { $currentChannel = $this->channelContext->getChannel(); return $currentChannel->getCurrencies()->filter(function (CurrencyInterface $currency) { return $currency->isEnabled(); }); }
function it_throws_handle_exception_if_channel_was_not_found(LocaleStorageInterface $localeStorage, ChannelContextInterface $channelContext, EventDispatcherInterface $eventDispatcher) { $channelContext->getChannel()->willThrow(ChannelNotFoundException::class); $localeStorage->set(Argument::any(), Argument::any())->shouldNotBeCalled(); $eventDispatcher->dispatch(SyliusLocaleEvents::CODE_CHANGED, new GenericEvent('en_GB'))->shouldNotBeCalled(); $this->shouldThrow(HandleException::class)->during('handle', ['en_GB']); }
function it_throws_an_exception_if_locale_taken_from_storage_is_not_available(ChannelContextInterface $channelContext, LocaleStorageInterface $localeStorage, LocaleProviderInterface $localeProvider, ChannelInterface $channel) { $channelContext->getChannel()->willReturn($channel); $localeStorage->get($channel)->willReturn('pl_PL'); $localeProvider->getAvailableLocalesCodes()->willReturn(['en_US', 'en_UK']); $this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode'); }
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'); }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { try { $this->data['channel'] = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { } }
/** * @param GenericEvent $event */ public function processOrderChannel(GenericEvent $event) { $order = $event->getSubject(); if (!$order instanceof OrderInterface) { throw new UnexpectedTypeException($order, 'Sylius\\Component\\Core\\Model\\OrderInterface'); } $order->setChannel($this->channelContext->getChannel()); }
function it_clears_cart_session_after_logging_out_and_return_default_handler_response(ChannelContextInterface $channelContext, ChannelInterface $channel, HttpUtils $httpUtils, Request $request, Response $response, SessionInterface $session) { $channelContext->getChannel()->willReturn($channel); $channel->getCode()->willReturn('WEB_US'); $session->remove('_sylius.cart.WEB_US')->shouldBeCalled(); $httpUtils->createRedirectResponse($request, '/')->willReturn($response); $this->onLogoutSuccess($request)->shouldReturn($response); }
/** * @param GenericEvent $event */ public function processOrderChannel(GenericEvent $event) { $order = $event->getSubject(); if (!$order instanceof OrderInterface) { throw new UnexpectedTypeException($order, OrderInterface::class); } $order->setChannel($this->channelContext->getChannel()); }
/** * @param PriceableInterface $subject * @param array $configuration * @param array $context * * @return int */ public function calculate(PriceableInterface $subject, array $configuration, array $context = []) { $currentChannel = $this->channelContext->getChannel(); $calculatorConfiguration = $subject->getPricingConfiguration(); if (!isset($calculatorConfiguration[$currentChannel->getId()])) { return $subject->getPrice(); } return $calculatorConfiguration[$currentChannel->getId()]; }
/** * {@inheritdoc} */ public function handle($code) { try { $this->localeStorage->set($this->channelContext->getChannel(), $code); } catch (ChannelNotFoundException $exception) { throw new HandleException(self::class, 'Sylius cannot found the channel', $exception); } $this->eventDispatcher->dispatch(SyliusLocaleEvents::CODE_CHANGED, new GenericEvent($code)); }
/** * {@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; }
/** * @param ChannelRepositoryInterface $channelRepository * @param ChannelContextInterface $channelContext */ public function __construct(ChannelRepositoryInterface $channelRepository, ChannelContextInterface $channelContext) { $this->data['channels'] = $channelRepository->findAll(); try { $this->data['current_channel'] = $channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { $this->data['current_channel'] = null; } }
function its_nested_request_resolvers_can_have_priority(ChannelContextInterface $firstChannelContext, ChannelContextInterface $secondChannelContext, ChannelContextInterface $thirdChannelContext, ChannelInterface $channel) { $firstChannelContext->getChannel()->shouldNotBeCalled(); $secondChannelContext->getChannel()->willReturn($channel); $thirdChannelContext->getChannel()->willThrow(ChannelNotFoundException::class); $this->addContext($firstChannelContext, -5); $this->addContext($secondChannelContext, 0); $this->addContext($thirdChannelContext, 5); $this->getChannel()->shouldReturn($channel); }
/** * {@inheritdoc} */ public function setCurrencyCode($currencyCode) { if (null === ($customer = $this->customerContext->getCustomer())) { $channel = $this->channelContext->getChannel(); return $this->storage->setData($this->getStorageKey($channel->getCode()), $currencyCode); } $customer->setCurrencyCode($currencyCode); $this->customerManager->persist($customer); $this->customerManager->flush(); }
function it_sends_an_email_registration_successfully(SenderInterface $emailSender, ChannelContextInterface $channelContext, GenericEvent $event, CustomerInterface $customer, ShopUserInterface $user, ChannelInterface $channel) { $event->getSubject()->willReturn($customer); $customer->getUser()->willReturn($user); $customer->getEmail()->willReturn('*****@*****.**'); $user->getEmail()->willReturn('*****@*****.**'); $channelContext->getChannel()->willReturn($channel); $emailSender->send(Emails::USER_REGISTRATION, ['*****@*****.**'], ['user' => $user])->shouldBeCalled(); $this->sendUserRegistrationEmail($event); }
/** * {@inheritdoc} */ public function getDefaultLocaleCode() { try { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); return $channel->getDefaultLocale()->getCode(); } catch (ChannelNotFoundException $exception) { return $this->defaultLocaleCode; } }
/** * {@inheritdoc} */ public function getDefaultCurrencyCode() { try { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); return $channel->getBaseCurrency()->getCode(); } catch (ChannelNotFoundException $exception) { throw new CurrencyNotFoundException(null, $exception); } }
/** * {@inheritdoc} */ public function getChannel() { $objectIdentifier = $this->requestStack->getMasterRequest(); if (null === $objectIdentifier) { return $this->decoratedChannelContext->getChannel(); } if (!isset($this->requestToChannelMap[$objectIdentifier])) { $this->requestToChannelMap[$objectIdentifier] = $this->decoratedChannelContext->getChannel(); } return $this->requestToChannelMap[$objectIdentifier]; }
/** * {@inheritdoc} */ public function getTheme() { try { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); return $channel->getTheme(); } catch (ChannelNotFoundException $exception) { return null; } catch (\Exception $exception) { return null; } }
/** * {@inheritdoc} */ public function getTheme() { try { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); return $this->themeRepository->findOneByName($channel->getThemeName()); } catch (ChannelNotFoundException $exception) { return null; } catch (\Exception $exception) { return null; } }
/** * {@inheritdoc} */ public function getLocaleCode() { $availableLocalesCodes = $this->localeProvider->getAvailableLocalesCodes(); try { $localeCode = $this->localeStorage->get($this->channelContext->getChannel()); } catch (ChannelNotFoundException $exception) { throw new LocaleNotFoundException(null, $exception); } if (!in_array($localeCode, $availableLocalesCodes, true)) { throw LocaleNotFoundException::notAvailable($localeCode, $availableLocalesCodes); } return $localeCode; }
/** * @return string[] */ protected function getEnabledLocalesCodes() { $localesCodes = []; /** @var LocaleInterface[] $locales */ $locales = $this->channelContext->getChannel()->getLocales(); foreach ($locales as $locale) { if (!$locale->isEnabled()) { continue; } $localesCodes[] = $locale->getCode(); } return $localesCodes; }
/** * {@inheritdoc} */ public function getCart() { try { $channel = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException($exception); } if (!$this->session->has(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode()))) { throw new CartNotFoundException('Sylius was not able to find the cart in session'); } $cart = $this->orderRepository->findCartByIdAndChannel($this->session->get(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode())), $channel); if (null === $cart) { $this->session->remove(sprintf('%s.%s', $this->sessionKeyName, $channel->getCode())); throw new CartNotFoundException('Sylius was not able to find the cart in session'); } return $cart; }
/** * {@inheritdoc} */ public function getCart() { try { $channel = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to find the cart, as there is no current channel.'); } $customer = $this->customerContext->getCustomer(); if (null === $customer) { throw new CartNotFoundException('Sylius was not able to find the cart, as there is no logged in user.'); } $cart = $this->orderRepository->findLatestCartByChannelAndCustomer($channel, $customer); if (null === $cart) { throw new CartNotFoundException('Sylius was not able to find the cart for currently logged in user.'); } return $cart; }
/** * {@inheritdoc} */ public function getChannel() { $objectIdentifier = $this->requestStack->getMasterRequest(); if (null === $objectIdentifier) { return $this->decoratedChannelContext->getChannel(); } if (isset($this->requestToExceptionMap[$objectIdentifier])) { throw $this->requestToExceptionMap[$objectIdentifier]; } try { if (!isset($this->requestToChannelMap[$objectIdentifier])) { $this->requestToChannelMap[$objectIdentifier] = $this->decoratedChannelContext->getChannel(); } return $this->requestToChannelMap[$objectIdentifier]; } catch (ChannelNotFoundException $exception) { $this->requestToExceptionMap[$objectIdentifier] = $exception; throw $exception; } }
/** * @param Request $request * @return CartItemInterface */ public function resolve(Request $request) { if (!($id = $request->get('id'))) { throw new ItemResolvingException('Error while trying to add item to cart.'); } // Create cart item $item = $this->cartItemFactory->createNew(); $channel = $this->channelContext->getChannel(); if (!($product = $this->productRepository->findOneByIdAndChannel($id, $channel))) { throw new ItemResolvingException('Requested product was not found.'); } // We use forms to easily set the quantity and pick variant, // the same way Sylius does it while resolving products when adding to cart $form = $this->formFactory->create('sylius_cart_item', $item, array('product' => $product)); $form->submit($request); // Get appropriate variant $variant = $item->getVariant() ? $item->getVariant() : $product->getMasterVariant(); return $variant; }