/** * @param array $options * * @return array */ private function getZones(array $options) { if (isset($options['scope'])) { return $this->zoneRepository->findBy(['scope' => $options['scope']]); } return $this->zoneRepository->findAll(); }
/** * {@inheritdoc} */ public function getDefinedLocalesCodes() { $locales = $this->localeRepository->findAll(); return array_map(function (LocaleInterface $locale) { return $locale->getCode(); }, $locales); }
/** * @return array */ private function getLocales() { /** @var LocaleInterface[] $locales */ $locales = $this->localeRepository->findAll(); foreach ($locales as $locale) { (yield $locale->getCode()); } }
/** * @return array */ private function getLocalesCodes() { $localesCodes = []; /** @var LocaleInterface $locale */ foreach ($this->localeRepository->findAll() as $locale) { $localesCodes[$locale->getName()] = $locale->getCode(); } return $localesCodes; }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['choices' => function (Options $options) { if (null === $options['enabled']) { return $this->countryRepository->findAll(); } return $this->countryRepository->findBy(['enabled' => $options['enabled']]); }, 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, 'enabled' => true, 'label' => 'sylius.form.address.country', 'placeholder' => 'sylius.form.country.select']); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['choices' => function (Options $options) { if (isset($options['subject'])) { return $this->paymentMethodsResolver->getSupportedMethods($options['subject']); } return $this->paymentMethodRepository->findAll(); }, 'choice_value' => 'id', 'choice_label' => 'name', 'choice_translation_domain' => false])->setDefined(['subject'])->setAllowedTypes('subject', PaymentInterface::class); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $productAssociationTypes = $this->productAssociationTypeRepository->findAll(); /** @var ProductAssociationTypeInterface $productAssociationType */ foreach ($productAssociationTypes as $productAssociationType) { $builder->add($productAssociationType->getCode(), TextType::class, ['label' => $productAssociationType->getName()]); } $builder->addModelTransformer($this->productsToProductAssociationsTransformer); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $taxonomies = $this->taxonomyRepository->findAll(); $builder->addModelTransformer(new $options['model_transformer']['class']($taxonomies, $options['model_transformer']['save_objects'])); foreach ($taxonomies as $taxonomy) { /* @var $taxonomy TaxonomyInterface */ $builder->add($taxonomy->getId(), 'choice', array('choice_list' => new ObjectChoiceList($this->taxonRepository->getTaxonsAsList($taxonomy), null, array(), null, 'id'), 'multiple' => $options['multiple'], 'label' => $taxonomy->getName())); } }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choiceList = function (Options $options) { if (null === $options['country']) { return new ObjectChoiceList($this->repository->findAll(), null, array(), null, 'id'); } return new ObjectChoiceList($options['country']->getProvinces(), null, array(), null, 'id'); }; $resolver->setDefaults(array('choice_list' => $choiceList, 'country' => null, 'label' => 'sylius.form.address.province', 'empty_value' => 'sylius.form.province.select')); }
/** * @return TokenInterface * * @throws \RuntimeException */ private function findCaptureToken() { $tokens = $this->securityTokenRepository->findAll(); foreach ($tokens as $token) { if (strpos($token->getTargetUrl(), 'capture')) { return $token; } } throw new \RuntimeException('Cannot find capture token, check if you are after proper checkout steps'); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver->setDefaults(['choices' => function (Options $options) { if (null === $options['enabled']) { return $this->localeRepository->findAll(); } return $this->localeRepository->findBy(['enabled' => $options['enabled']]); }, 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, 'enabled' => null, 'label' => 'sylius.form.locale.locale', 'placeholder' => 'sylius.form.locale.select']); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choices = function (Options $options) { if (null === $options['customer']) { return $this->addressRepository->findAll(); } return $this->addressRepository->findBy(['customer' => $options['customer']]); }; $resolver->setDefaults(['class' => AddressInterface::class, 'choices' => $choices, 'customer' => null, 'label' => false, 'placeholder' => false]); }
/** * Should be private, used public to support PHP 5.3 * * @internal * * @return array */ public function getAvailableCountries() { $availableCountries = Intl::getRegionBundle()->getCountryNames(); /** @var CountryInterface[] $definedCountries */ $definedCountries = $this->countryRepository->findAll(); foreach ($definedCountries as $country) { unset($availableCountries[$country->getIsoName()]); } return $availableCountries; }
/** * Should be private, used public to support PHP 5.3 * * @internal * * @return array */ public function getAvailableLocales() { $availableLocales = Intl::getLocaleBundle()->getLocaleNames(); /** @var LocaleInterface[] $definedLocales */ $definedLocales = $this->localeRepository->findAll(); foreach ($definedLocales as $locale) { unset($availableLocales[$locale->getCode()]); } return $availableLocales; }
/** * @return array */ private function getZoneCodes() { $zoneObjects = $this->zoneRepository->findAll(); $zones = []; /* @var ZoneInterface $zone */ foreach ($zoneObjects as $zone) { $zones[$zone->getCode()] = $zone->getName(); } return $zones; }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['choices' => function (Options $options) { if (null === $options['country']) { return $this->provinceRepository->findAll(); } return $options['country']->getProvinces(); }, 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false, 'country' => null, 'label' => 'sylius.form.address.province', 'placeholder' => 'sylius.form.province.select']); $resolver->addAllowedTypes('country', ['null', CountryInterface::class]); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choices = function (Options $options) { if (null === $options['enabled']) { $countries = $this->countryRepository->findAll(); } else { $countries = $this->countryRepository->findBy(['enabled' => $options['enabled']]); } return $this->getCountryCodes($countries); }; $resolver->setDefaults(['choices' => $choices, 'choices_as_values' => true, 'enabled' => true, 'label' => 'sylius.form.address.country', 'empty_value' => 'sylius.form.country.select']); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choices = function (Options $options) { if (null === $options['enabled']) { $choices = $this->countryRepository->findAll(); } else { $choices = $this->countryRepository->findBy(['enabled' => $options['enabled']]); } return new ArrayChoiceList($choices); }; $resolver->setDefaults(['choice_translation_domain' => false, 'choice_list' => $choices, 'enabled' => true, 'label' => 'sylius.form.address.country', 'empty_value' => 'sylius.form.country.select']); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choiceList = function (Options $options) { if (isset($options['subject']) && $this->shippingMethodsResolver->supports($options['subject'])) { $methods = $this->shippingMethodsResolver->getSupportedMethods($options['subject']); } else { $methods = $this->repository->findAll(); } return new ObjectChoiceList($methods, null, [], null, 'code'); }; $resolver->setDefaults(['choice_list' => $choiceList])->setDefined(['subject'])->setAllowedTypes('subject', ShippingSubjectInterface::class); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choiceList = function (Options $options) { if (null === $options['enabled']) { $choices = $this->localeRepository->findAll(); } else { $choices = $this->localeRepository->findBy(array('enabled' => $options['enabled'])); } return new ObjectChoiceList($choices, null, array(), null, 'id'); }; $resolver->setDefaults(array('choice_list' => $choiceList, 'enabled' => null, 'label' => 'sylius.form.locale.locale', 'empty_value' => 'sylius.form.locale.select')); }
/** * {@inheritdoc} */ public function generate() { $products = $this->productRepository->findAll(); foreach ($products as $product) { $productUrl = $this->sitemapUrlFactory->createNew(); $localization = $this->router->generate('sylius_shop_product_show', ['slug' => $product->getSlug()], true); $productUrl->setLastModification($product->getUpdatedAt()); $productUrl->setLocalization($localization); $productUrl->setChangeFrequency(ChangeFrequency::always()); $productUrl->setPriority(0.5); $this->urls[] = $productUrl; } return $this->urls; }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choices = function (Options $options) { if (null === $options['country']) { $choices = $this->provinceRepository->findAll(); } else { $choices = $options['country']->getProvinces(); } return new ArrayChoiceList($choices); }; $resolver->setDefaults(array('choice_list' => $choices, 'country' => null, 'label' => 'sylius.form.address.province', 'empty_value' => 'sylius.form.province.select')); $resolver->addAllowedTypes('country', 'NULL'); $resolver->addAllowedTypes('country', CountryInterface::class); }
/** * @Given /^the store ships everywhere for free for (all channels)$/ */ public function theStoreShipsEverywhereForFreeForAllChannels(array $channels) { foreach ($this->zoneRepository->findAll() as $zone) { $configuration = $this->getConfigurationByChannels($channels); $this->createShippingMethod('Free', null, null, $zone, 'en', $configuration, DefaultCalculators::FLAT_RATE, true, false, $channels); } }
function it_calls_proper_method_with_arguments_based_on_configuration(RepositoryInterface $repository, $configuration) { $configuration->getRepositoryMethod('findBy')->willReturn('findAll'); $configuration->getRepositoryArguments(array())->willReturn(array(5)); $repository->findAll(5)->shouldBeCalled()->willReturn(array('foo', 'bar')); $this->getResource($repository, 'findBy')->shouldReturn(array('foo', 'bar')); }
/** * @Given the store does not have any zones defined */ public function theStoreDoesNotHaveAnyZonesDefined() { $zones = $this->zoneRepository->findAll(); foreach ($zones as $zone) { $this->zoneRepository->remove($zone); } }
function it_uses_a_custom_method_if_configured(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, ResourceInterface $resource) { $requestConfiguration->getRepositoryMethod()->willReturn('findAll'); $requestConfiguration->getRepositoryArguments()->willReturn(array('foo')); $repository->findAll('foo')->willReturn($resource); $this->get($requestConfiguration, $repository)->shouldReturn($resource); }
/** * @param string|null $scope * * @return array */ protected function getZones($scope = null) { if (null === $scope) { return $this->zoneRepository->findAll(); } return $this->zoneRepository->findBy(array('scope' => $scope)); }
function it_configures_options(OptionsResolver $resolver, ZoneInterface $zone, RepositoryInterface $repository) { $zone->getCode()->willReturn('EU'); $zone->getName()->willReturn('European Union'); $repository->findAll()->willReturn(array($zone)); $resolver->setDefaults(array('choices' => array('EU' => 'European Union'), 'label' => 'sylius.form.zone.types.zone', 'empty_value' => 'sylius.form.zone.select'))->willReturn($resolver); $this->configureOptions($resolver); }
function it_configures_options(OptionsResolver $resolver, ZoneInterface $zone, RepositoryInterface $repository) { $zone->getCode()->willReturn('EU'); $zone->getName()->willReturn('European Union'); $repository->findAll()->willReturn([$zone]); $resolver->setDefaults(['choice_translation_domain' => false, 'choices' => ['EU' => 'European Union'], 'label' => 'sylius.form.zone.types.zone', 'empty_value' => 'sylius.form.zone.select'])->willReturn($resolver); $this->configureOptions($resolver); }
/** * @Given /^the store ships everywhere for free for (all channels)$/ */ public function theStoreShipsEverywhereForFreeForAllChannels(array $channels) { foreach ($this->zoneRepository->findAll() as $zone) { $configuration = $this->getConfigurationByChannels($channels); $shippingMethod = $this->shippingMethodExampleFactory->create(['name' => 'Free', 'enabled' => true, 'zone' => $zone, 'calculator' => ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => $configuration], 'channels' => $channels]); $this->saveShippingMethod($shippingMethod); } }