Exemple #1
0
 /**
  * @Given /^the store operates on (?:a|another) channel named "([^"]+)"$/
  */
 public function theStoreOperatesOnAChannelNamed($channelName)
 {
     $channel = $this->channelFactory->createNamed($channelName);
     $channel->setCode($channelName);
     $this->channelRepository->add($channel);
     $this->sharedStorage->set('channel', $channel);
 }
 function it_throws_a_channel_not_found_exception_if_channel_with_given_code_was_not_found(FakeChannelCodeProviderInterface $fakeChannelCodeProvider, ChannelRepositoryInterface $channelRepository, RequestStack $requestStack, Request $request)
 {
     $requestStack->getMasterRequest()->willReturn($request);
     $fakeChannelCodeProvider->getCode($request)->willReturn('CHANNEL_CODE');
     $channelRepository->findOneByCode('CHANNEL_CODE')->willReturn(null);
     $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
 }
 /**
  * {@inheritdoc}
  */
 public function resolve($hostname = null)
 {
     if (null === $hostname || null === ($channel = $this->channelRepository->findMatchingHostname($hostname))) {
         return $this->channelRepository->findDefault();
     }
     return $channel;
 }
 /**
  * {@inheritdoc}
  */
 public function getChannel()
 {
     $fakeChannelCode = $this->fakeChannelCodeProvider->getCode($this->getMasterRequest());
     $channel = $this->channelRepository->findOneByCode($fakeChannelCode);
     $this->assertChannelWasFound($channel);
     return $channel;
 }
Exemple #5
0
 /**
  * @Transform /^channel "([^"]+)"$/
  * @Transform /^"([^"]+)" channel/
  * @Transform :channel
  */
 public function getChannelByName($channelName)
 {
     $channel = $this->channelRepository->findOneByName($channelName);
     if (null === $channel) {
         throw new \InvalidArgumentException('Channel with name "' . $channelName . '" does not exist');
     }
     return $channel;
 }
 /**
  * {@inheritdoc}
  */
 public function getChannel()
 {
     $channels = $this->channelRepository->findAll();
     if (1 !== count($channels)) {
         throw new ChannelNotFoundException();
     }
     return current($channels);
 }
 /**
  * @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;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     /**
      * @var ChannelInterface $channel
      */
     foreach ($this->channelRepository->findAll() as $channel) {
         $builder->add($channel->getCode(), FlatRateConfigurationType::class, ['label' => $channel->getName()]);
     }
 }
Exemple #9
0
 /**
  * @When I create a new channel :channelName
  */
 public function iCreateNewChannel($channelName)
 {
     $this->channelCreatePage->open();
     $this->channelCreatePage->nameIt($channelName);
     $this->channelCreatePage->specifyCode($channelName);
     $this->channelCreatePage->create();
     $channel = $this->channelRepository->findOneBy(['name' => $channelName]);
     $this->sharedStorage->set('channel', $channel);
 }
 function it_adds_missing_channel_pricings_on_pre_set_data(ChannelInterface $firstChannel, ChannelInterface $secondChannel, ChannelPricingInterface $channelPricing, ChannelRepositoryInterface $channelRepository, FactoryInterface $channelPricingFactory, FormEvent $formEvent, ProductVariantInterface $productVariant)
 {
     $formEvent->getData()->willReturn($productVariant);
     $channelRepository->findAll()->willReturn([$firstChannel, $secondChannel]);
     $productVariant->hasChannelPricingForChannel($firstChannel)->willReturn(true);
     $productVariant->hasChannelPricingForChannel($secondChannel)->willReturn(false);
     $channelPricingFactory->createNew()->willReturn($channelPricing);
     $channelPricing->setChannel($secondChannel)->shouldBeCalled();
     $productVariant->addChannelPricing($channelPricing)->shouldBeCalled();
     $this->preSetData($formEvent);
 }
Exemple #11
0
 /**
  * @param string $channelCode
  *
  * @return ChannelInterface|null
  */
 private function findChannelByCodeOrFindFirst($channelCode)
 {
     $channel = null;
     if (null !== $channelCode) {
         $channel = $this->channelRepository->findOneByCode($channelCode);
     }
     if (null === $channel) {
         $channels = $this->channelRepository->findAll();
         $channel = current($channels) === false ? null : current($channels);
     }
     return $channel;
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     /** @var ProductVariantInterface $productVariant */
     $productVariant = $event->getData();
     if (null === $productVariant) {
         return;
     }
     /** @var ChannelInterface $channel */
     foreach ($this->channelRepository->findAll() as $channel) {
         if ($productVariant->hasChannelPricingForChannel($channel)) {
             continue;
         }
         /** @var ChannelPricingInterface $channelPricing */
         $channelPricing = $this->channelPricingFactory->createNew();
         $channelPricing->setChannel($channel);
         $productVariant->addChannelPricing($channelPricing);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function addConfigurationFields(FormInterface $form, $registryIdentifier, array $data = [])
 {
     $model = $this->registry->get($registryIdentifier);
     $configuration = $model->getConfigurationFormType();
     if (null === $configuration) {
         return;
     }
     if (!$model instanceof ChannelBasedPromotionActionCommandInterface) {
         $form->add($this->createConfigurationField($configuration, $data));
         return;
     }
     $configurationCollection = $this->factory->createNamed('configuration', PromotionConfigurationType::class, [], ['compound' => true, 'auto_initialize' => false]);
     /** @var ChannelInterface $channel */
     foreach ($this->channelRepository->findAll() as $channel) {
         $configurationCollection->add($this->createConfigurationFieldForChannel($channel, $configuration, $data));
     }
     $form->add($configurationCollection);
 }
Exemple #14
0
 /**
  * @Transform all channels
  */
 public function getAllChannels()
 {
     return $this->channelRepository->findAll();
 }
 function it_returns_null_if_channel_was_not_found(ChannelRepositoryInterface $channelRepository, Request $request)
 {
     $request->getHost()->willReturn('example.org');
     $channelRepository->findOneByHostname('example.org')->willReturn(null);
     $this->findChannel($request)->shouldReturn(null);
 }
Exemple #16
0
 /**
  * @Transform /^channel "([^"]+)"$/
  * @Transform /^"([^"]+)" channel/
  * @Transform /^channel to "([^"]+)"$/
  * @Transform :channel
  */
 public function getChannelByName($channelName)
 {
     $channels = $this->channelRepository->findByName($channelName);
     Assert::eq(1, count($channels), sprintf('%d channels has been found with name "%s".', count($channels), $channelName));
     return $channels[0];
 }
 /**
  * @param ChannelRepositoryInterface $channelRepository
  * @param ChannelContextInterface $channelContext
  * @param bool $channelChangeSupport
  */
 public function __construct(ChannelRepositoryInterface $channelRepository, ChannelContextInterface $channelContext, $channelChangeSupport = false)
 {
     $this->channelContext = $channelContext;
     $this->data = ['channel' => null, 'channels' => $channelRepository->findAll(), 'channel_change_support' => $channelChangeSupport];
 }
 /**
  * @Transform /^channel "([^"]+)"$/
  * @Transform /^"([^"]+)" channel/
  * @Transform /^channel to "([^"]+)"$/
  * @Transform :channel
  */
 public function getChannelByName($channelName)
 {
     $channel = $this->channelRepository->findOneByName($channelName);
     Assert::notNull($channel, sprintf('Channel with name "%s" does not exist', $channelName));
     return $channel;
 }
Exemple #19
0
 /**
  * @Given channel :channel has been deleted
  */
 public function iChannelHasBeenDeleted(ChannelInterface $channel)
 {
     $this->channelRepository->remove($channel);
 }
 /**
  * @param ChannelRepositoryInterface $channelRepository
  * @param ChannelContextInterface $channelContext
  */
 public function __construct(ChannelRepositoryInterface $channelRepository, ChannelContextInterface $channelContext)
 {
     $this->data['channels'] = $channelRepository->findAll();
     $this->data['current_channel'] = $channelContext->getChannel();
 }
 /**
  * {@inheritdoc}
  */
 public function findChannel(Request $request)
 {
     return $this->channelRepository->findOneByHostname($request->getHost());
 }
 function it_throws_a_channel_not_found_exception_if_there_are_many_channels_defined(ChannelRepositoryInterface $channelRepository, ChannelInterface $firstChannel, ChannelInterface $secondChannel)
 {
     $channelRepository->findAll()->willReturn([$firstChannel, $secondChannel]);
     $this->shouldThrow(ChannelNotFoundException::class)->during('getChannel');
 }
 function it_throws_an_exception_if_channel_is_not_found(ChannelRepositoryInterface $channelRepository)
 {
     $channelRepository->findOneBy(['name' => 'Store'])->willReturn(null);
     $this->shouldThrow(new \InvalidArgumentException('Channel with name "Store" does not exist'))->during('getChannelByName', ['Store']);
 }