/** * @param FactoryInterface $taxRateFactory * @param RepositoryInterface $zoneRepository * @param RepositoryInterface $taxCategoryRepository */ public function __construct(FactoryInterface $taxRateFactory, RepositoryInterface $zoneRepository, RepositoryInterface $taxCategoryRepository) { $this->taxRateFactory = $taxRateFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('amount', function (Options $options) { return $this->faker->randomFloat(2, 0, 1); })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) { return $this->faker->boolean(); })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefault('tax_category', LazyOption::randomOne($taxCategoryRepository))->setAllowedTypes('tax_category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('tax_category', LazyOption::findOneBy($taxCategoryRepository, 'code')); }
/** * @param FactoryInterface $routeFactory */ public function __construct(FactoryInterface $routeFactory, RepositoryInterface $staticContentRepository) { $this->routeFactory = $routeFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return StringInflector::nameToCode($this->faker->words(3, true)); })->setDefault('content', LazyOption::randomOne($staticContentRepository))->setAllowedTypes('content', ['string', StaticContent::class])->setNormalizer('content', LazyOption::findOneBy($staticContentRepository, 'name')); }
/** * @param FactoryInterface $shippingMethodFactory * @param RepositoryInterface $zoneRepository * @param RepositoryInterface $shippingCategoryRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $shippingMethodFactory, RepositoryInterface $zoneRepository, RepositoryInterface $shippingCategoryRepository, RepositoryInterface $localeRepository) { $this->shippingMethodFactory = $shippingMethodFactory; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefault('shipping_category', LazyOption::randomOne($shippingCategoryRepository))->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) { return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => ['amount' => 4200]]; }); }
/** * @param FactoryInterface $userFactory * @param FactoryInterface $customerFactory * @param RepositoryInterface $currencyRepository */ public function __construct(FactoryInterface $userFactory, FactoryInterface $customerFactory, RepositoryInterface $currencyRepository) { $this->userFactory = $userFactory; $this->customerFactory = $customerFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('email', function (Options $options) { return $this->faker->email; })->setDefault('first_name', function (Options $options) { return $this->faker->firstName; })->setDefault('last_name', function (Options $options) { return $this->faker->lastName; })->setDefault('currency_code', LazyOption::randomOne($currencyRepository))->setAllowedTypes('currency_code', ['null', 'string', CurrencyInterface::class])->setNormalizer('currency_code', LazyOption::findOneBy($currencyRepository, 'code'))->setNormalizer('currency_code', function (Options $options, CurrencyInterface $currency) { return $currency->getCode(); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('admin', false)->setAllowedTypes('admin', 'bool')->setDefault('password', function (Options $options) { return $this->faker->password; }); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('first_name', function (Options $options) { return $this->faker->firstName; })->setDefault('last_name', function (Options $options) { return $this->faker->lastName; })->setDefault('phone_number', function (Options $options) { return mt_rand(1, 100) > 50 ? $this->faker->phoneNumber : null; })->setDefault('company', function (Options $options) { return mt_rand(1, 100) > 50 ? $this->faker->company : null; })->setDefault('street', function (Options $options) { return $this->faker->streetAddress; })->setDefault('city', function (Options $options) { return $this->faker->city; })->setDefault('postcode', function (Options $options) { return $this->faker->postcode; })->setDefault('country_code', function (Options $options) { $countries = $this->countryRepository->findAll(); shuffle($countries); return array_pop($countries)->getCode(); })->setAllowedTypes('country_code', ['string'])->setDefault('province_name', null)->setAllowedTypes('province_name', ['null', 'string'])->setDefault('province_code', null)->setAllowedTypes('province_code', ['null', 'string'])->setDefault('customer', LazyOption::randomOne($this->customerRepository))->setAllowedTypes('customer', ['string', CustomerInterface::class])->setNormalizer('customer', LazyOption::findOneBy($this->customerRepository, 'email')); }
/** * @param FactoryInterface $productFactory * @param FactoryInterface $productVariantFactory * @param ProductVariantGeneratorInterface $variantGenerator * @param FactoryInterface $productAttributeValueFactory * @param FactoryInterface $productImageFactory * @param ImageUploaderInterface $imageUploader * @param SlugGeneratorInterface $slugGenerator * @param RepositoryInterface $taxonRepository * @param RepositoryInterface $productAttributeRepository * @param RepositoryInterface $productOptionRepository * @param RepositoryInterface $channelRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $productFactory, FactoryInterface $productVariantFactory, ProductVariantGeneratorInterface $variantGenerator, FactoryInterface $productAttributeValueFactory, FactoryInterface $productImageFactory, ImageUploaderInterface $imageUploader, SlugGeneratorInterface $slugGenerator, RepositoryInterface $taxonRepository, RepositoryInterface $productAttributeRepository, RepositoryInterface $productOptionRepository, RepositoryInterface $channelRepository, RepositoryInterface $localeRepository) { $this->productFactory = $productFactory; $this->productVariantFactory = $productVariantFactory; $this->variantGenerator = $variantGenerator; $this->productImageFactory = $productImageFactory; $this->imageUploader = $imageUploader; $this->slugGenerator = $slugGenerator; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('short_description', function (Options $options) { return $this->faker->paragraph; })->setDefault('description', function (Options $options) { return $this->faker->paragraphs(3, true); })->setDefault('main_taxon', LazyOption::randomOne($taxonRepository))->setAllowedTypes('main_taxon', ['null', 'string', TaxonInterface::class])->setNormalizer('main_taxon', LazyOption::findOneBy($taxonRepository, 'code'))->setDefault('taxons', LazyOption::randomOnes($taxonRepository, 3))->setAllowedTypes('taxons', 'array')->setNormalizer('taxons', LazyOption::findBy($taxonRepository, 'code'))->setDefault('channels', LazyOption::randomOnes($channelRepository, 3))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($channelRepository, 'code'))->setDefault('product_attributes', [])->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', function (Options $options, array $productAttributes) use($productAttributeRepository, $productAttributeValueFactory) { $productAttributesValues = []; foreach ($productAttributes as $code => $value) { /** @var ProductAttributeInterface $productAttribute */ $productAttribute = $productAttributeRepository->findOneBy(['code' => $code]); Assert::notNull($productAttribute); /** @var ProductAttributeValueInterface $productAttributeValue */ $productAttributeValue = $productAttributeValueFactory->createNew(); $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setValue($value ?: $this->getRandomValueForProductAttribute($productAttribute)); $productAttributesValues[] = $productAttributeValue; } return $productAttributesValues; })->setDefault('product_options', [])->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($productOptionRepository, 'code'))->setDefault('images', [])->setAllowedTypes('images', 'array'); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('description', function (Options $options) { return $this->faker->sentence(); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefined('shipping_category')->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($this->shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) { $configuration = []; /** @var ChannelInterface $channel */ foreach ($options['channels'] as $channel) { $configuration[$channel->getCode()] = ['amount' => $this->faker->randomNumber(4)]; } return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => $configuration]; })->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code')); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('amount', function (Options $options) { return $this->faker->randomFloat(2, 0, 0.4); })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) { return $this->faker->boolean(); })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefault('category', LazyOption::randomOne($this->taxCategoryRepository))->setAllowedTypes('category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('category', LazyOption::findOneBy($this->taxCategoryRepository, 'code')); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('title', function (Options $options) { return $this->faker->words(3, true); })->setDefault('rating', function (Options $options) { return $this->faker->numberBetween(1, 5); })->setDefault('comment', function (Options $options) { return $this->faker->sentences(3, true); })->setDefault('author', LazyOption::randomOne($this->customerRepository))->setNormalizer('author', LazyOption::findOneBy($this->customerRepository, 'email'))->setDefault('product', LazyOption::randomOne($this->productRepository))->setNormalizer('product', LazyOption::findOneBy($this->productRepository, 'code'))->setDefault('status', null); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('type', LazyOption::randomOne($this->productAssociationTypeRepository))->setAllowedTypes('type', ['string', ProductAssociationTypeInterface::class])->setNormalizer('type', LazyOption::findOneBy($this->productAssociationTypeRepository, 'code'))->setDefault('owner', LazyOption::randomOne($this->productRepository))->setAllowedTypes('owner', ['string', ProductInterface::class])->setNormalizer('owner', LazyOption::findOneBy($this->productRepository, 'code'))->setDefault('associated_products', LazyOption::randomOnes($this->productRepository, 3))->setAllowedTypes('associated_products', 'array')->setNormalizer('associated_products', LazyOption::findBy($this->productRepository, 'code')); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('short_description', function (Options $options) { return $this->faker->paragraph; })->setDefault('description', function (Options $options) { return $this->faker->paragraphs(3, true); })->setDefault('main_taxon', LazyOption::randomOne($this->taxonRepository))->setAllowedTypes('main_taxon', ['null', 'string', TaxonInterface::class])->setNormalizer('main_taxon', LazyOption::findOneBy($this->taxonRepository, 'code'))->setDefault('taxons', LazyOption::randomOnes($this->taxonRepository, 3))->setAllowedTypes('taxons', 'array')->setNormalizer('taxons', LazyOption::findBy($this->taxonRepository, 'code'))->setDefault('channels', LazyOption::randomOnes($this->channelRepository, 3))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setDefault('variant_selection_method', ProductInterface::VARIANT_SELECTION_MATCH)->setAllowedValues('variant_selection_method', [ProductInterface::VARIANT_SELECTION_MATCH, ProductInterface::VARIANT_SELECTION_CHOICE])->setDefault('product_attributes', [])->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', function (Options $options, array $productAttributes) { $productAttributesValues = []; foreach ($productAttributes as $code => $value) { /** @var ProductAttributeInterface $productAttribute */ $productAttribute = $this->productAttributeRepository->findOneBy(['code' => $code]); Assert::notNull($productAttribute); /** @var ProductAttributeValueInterface $productAttributeValue */ $productAttributeValue = $this->productAttributeValueFactory->createNew(); $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setValue($value ?: $this->getRandomValueForProductAttribute($productAttribute)); $productAttributesValues[] = $productAttributeValue; } return $productAttributesValues; })->setDefault('product_options', [])->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($this->productOptionRepository, 'code'))->setDefault('images', [])->setAllowedTypes('images', 'array'); }