/**
  * @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();
 }
Ejemplo n.º 2
0
 /**
  * {@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());
     }
 }
Ejemplo n.º 4
0
 /**
  * @return array
  */
 private function getLocalesCodes()
 {
     $localesCodes = [];
     /** @var LocaleInterface $locale */
     foreach ($this->localeRepository->findAll() as $locale) {
         $localesCodes[$locale->getName()] = $locale->getCode();
     }
     return $localesCodes;
 }
Ejemplo n.º 5
0
 /**
  * {@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);
 }
Ejemplo n.º 7
0
 /**
  * {@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);
 }
Ejemplo n.º 8
0
 /**
  * {@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()));
     }
 }
Ejemplo n.º 9
0
 /**
  * {@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'));
 }
Ejemplo n.º 10
0
 /**
  * @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');
 }
Ejemplo n.º 11
0
 /**
  * {@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']);
 }
Ejemplo n.º 12
0
 /**
  * {@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]);
 }
Ejemplo n.º 13
0
 /**
  * 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;
 }
Ejemplo n.º 14
0
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * @return array
  */
 private function getZoneCodes()
 {
     $zoneObjects = $this->zoneRepository->findAll();
     $zones = [];
     /* @var ZoneInterface $zone */
     foreach ($zoneObjects as $zone) {
         $zones[$zone->getCode()] = $zone->getName();
     }
     return $zones;
 }
Ejemplo n.º 16
0
 /**
  * {@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]);
 }
Ejemplo n.º 17
0
 /**
  * {@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']);
 }
Ejemplo n.º 18
0
 /**
  * {@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);
 }
Ejemplo n.º 20
0
 /**
  * {@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'));
 }
Ejemplo n.º 21
0
 /**
  * {@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;
 }
Ejemplo n.º 22
0
 /**
  * {@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);
 }
Ejemplo n.º 23
0
 /**
  * @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);
     }
 }
Ejemplo n.º 24
0
 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'));
 }
Ejemplo n.º 25
0
 /**
  * @Given the store does not have any zones defined
  */
 public function theStoreDoesNotHaveAnyZonesDefined()
 {
     $zones = $this->zoneRepository->findAll();
     foreach ($zones as $zone) {
         $this->zoneRepository->remove($zone);
     }
 }
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
0
 /**
  * @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));
 }
Ejemplo n.º 28
0
 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);
 }
Ejemplo n.º 29
0
 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);
 }
Ejemplo n.º 30
0
 /**
  * @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);
     }
 }