/** * {@inheritdoc} */ public function getChannel() { $channels = $this->channelRepository->findAll(); if (1 !== count($channels)) { throw new ChannelNotFoundException(); } return current($channels); }
/** * {@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()]); } }
/** * @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); }
/** * @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 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); }
/** * @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]; }
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'); }
/** * @param ChannelRepositoryInterface $channelRepository * @param ChannelContextInterface $channelContext */ public function __construct(ChannelRepositoryInterface $channelRepository, ChannelContextInterface $channelContext) { $this->data['channels'] = $channelRepository->findAll(); $this->data['current_channel'] = $channelContext->getChannel(); }
/** * @Transform all channels */ public function getAllChannels() { return $this->channelRepository->findAll(); }