public function load(ObjectManager $manager) { $user = $manager->getRepository('TaichiUserBundle:User')->findOneBy(['username' => 'heaven']); foreach (range(1, self::POST_NUMS) as $i) { $post = new Post(); $categories = $manager->getRepository('TaichiBlogBundle:Category')->findAll(); $categoryIds = []; foreach ($categories as $category) { $categoryIds[] = $category->getId(); } $cIdKey = array_rand($categoryIds, 1); $category = $manager->getRepository('TaichiBlogBundle:Category')->find($categoryIds[$cIdKey]); $post->setSubject(implode(' ', array_map('ucfirst', $this->faker->words(mt_rand(3, 5))))); $post->setAbstract($this->faker->paragraph(mt_rand(2, 4))); $post->setContent($this->faker->paragraph(mt_rand(6, 10))); $post->setUser($user); $post->setCategory($category); //Add tags $tags = $manager->getRepository('TaichiBlogBundle:Tag')->findAll(); $tagIds = []; foreach ($tags as $tag) { $tagIds[] = $tag->getId(); } $tIdKeys = array_rand($tagIds, mt_rand(2, 5)); foreach ($tIdKeys as $tIdKey) { $tag = $manager->getRepository('TaichiBlogBundle:Tag')->find($tagIds[$tIdKey]); $post->addTag($tag); } $post->setPictureUrl($this->faker->imageUrl(400, 240)); $post->setCreatedAt($this->faker->dateTimeBetween('-1 year', '-10 days')); $post->setUpdatedAt($post->getCreatedAt()); foreach (range(1, mt_rand(1, self::COMMENT_NUMS)) as $j) { $comment = new Comment(); $comment->setUser($user); $comment->setCreatedAt($this->faker->dateTimeBetween($post->getCreatedAt(), 'now')); $comment->setUpdatedAt($comment->getCreatedAt()); $comment->setContent($this->faker->paragraph(mt_rand(1, 3))); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } $manager->persist($post); } $manager->flush(); }
/** * @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')); }
/** * Generate an array of tags * * @param int $prefixChance Percent chance the result will have a prefix assigned * @param int $min Minimum number of tags * @param int $max Maximum number of tags * @return array */ public function tags($prefixChance = 25, $min = 1, $max = 7) { $tags = $this->faker->words(mt_rand($min, $max)); $prefix = mt_rand(0, 100) < $prefixChance ? array_rand($tags) : NULL; // 25% chance to add a tag prefix return array('tags' => $tags, 'prefix' => $prefix); }
/** * @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')); }
/** * {@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']); }); }
/** * {@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('type', function (Options $options) { return $this->faker->randomElement(array_keys($this->attributeTypes)); })->setAllowedValues('type', array_keys($this->attributeTypes)); }
/** * @param FactoryInterface $productArchetypeFactory * @param RepositoryInterface $productOptionRepository * @param RepositoryInterface $productAttributeRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $productArchetypeFactory, RepositoryInterface $productOptionRepository, RepositoryInterface $productAttributeRepository, RepositoryInterface $localeRepository) { $this->productArchetypeFactory = $productArchetypeFactory; $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('product_options', LazyOption::randomOnes($productOptionRepository, 2))->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($productOptionRepository, 'code'))->setDefault('product_attributes', LazyOption::randomOnes($productAttributeRepository, 2))->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', LazyOption::findBy($productAttributeRepository, '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')); }
/** * @param FactoryInterface $shippingCategoryFactory */ public function __construct(FactoryInterface $shippingCategoryFactory) { $this->shippingCategoryFactory = $shippingCategoryFactory; $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('description', function (Options $options) { return $this->faker->paragraph; }); }
/** * @param AttributeFactoryInterface $productAttributeFactory * @param RepositoryInterface $localeRepository * @param array $attributeTypes */ public function __construct(AttributeFactoryInterface $productAttributeFactory, RepositoryInterface $localeRepository, array $attributeTypes) { $this->productAttributeFactory = $productAttributeFactory; $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('type', function (Options $options) use($attributeTypes) { return $this->faker->randomElement(array_keys($attributeTypes)); })->setAllowedValues('type', array_keys($attributeTypes)); }
/** * @param FactoryInterface $paymentMethodFactory * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $paymentMethodFactory, RepositoryInterface $localeRepository) { $this->paymentMethodFactory = $paymentMethodFactory; $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('gateway', 'offline')->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool'); }
/** * @param FactoryInterface $staticContentFactory */ public function __construct(FactoryInterface $staticContentFactory) { $this->staticContentFactory = $staticContentFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('title', function (Options $options) { return $this->faker->words(3, true); })->setDefault('name', function (Options $options) { return StringInflector::nameToCode($options['title']); })->setDefault('body', function (Options $options) { return $this->faker->paragraphs(4, true); })->setDefault('publishable', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('publishable', 'bool'); }
/** * @param FactoryInterface $taxonFactory * @param TaxonRepositoryInterface $taxonRepository * @param ObjectManager $taxonManager * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $taxonFactory, TaxonRepositoryInterface $taxonRepository, ObjectManager $taxonManager, RepositoryInterface $localeRepository) { $this->taxonFactory = $taxonFactory; $this->taxonRepository = $taxonRepository; $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('description', function (Options $options) { return $this->faker->paragraph; })->setDefault('children', [])->setAllowedTypes('children', ['array']); }
/** * @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 $taxonFactory * @param ObjectManager $taxonManager * @param RepositoryInterface $taxonRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $taxonFactory, ObjectManager $taxonManager, RepositoryInterface $taxonRepository, RepositoryInterface $localeRepository) { $this->taxonFactory = $taxonFactory; $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('description', function (Options $options) { return $this->faker->paragraph; })->setDefault('parent', LazyOption::randomOneOrNull($taxonRepository, 70))->setAllowedTypes('parent', ['null', 'string', TaxonInterface::class])->setNormalizer('parent', function (Options $options, $previousValue) use($taxonManager) { $taxonManager->flush(); return $previousValue; })->setNormalizer('parent', LazyOption::findOneBy($taxonRepository, 'code')); }
public static function generateProducts(\Faker\Generator $generator) { $title_words = $generator->words(mt_rand(2, 5)); $title = implode(' ', $title_words); $price = mt_rand(1, 10000); return array('title' => $title, 'price' => $price); }
/** * @param ChannelFactoryInterface $channelFactory * @param RepositoryInterface $localeRepository * @param RepositoryInterface $currencyRepository * @param RepositoryInterface $paymentMethodRepository * @param RepositoryInterface $shippingMethodRepository */ public function __construct(ChannelFactoryInterface $channelFactory, RepositoryInterface $localeRepository, RepositoryInterface $currencyRepository, RepositoryInterface $paymentMethodRepository, RepositoryInterface $shippingMethodRepository) { $this->channelFactory = $channelFactory; $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('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('locales', LazyOption::all($localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($localeRepository, 'code'))->setDefault('currencies', LazyOption::all($currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($currencyRepository, 'code'))->setDefault('payment_methods', LazyOption::all($paymentMethodRepository))->setAllowedTypes('payment_methods', 'array')->setNormalizer('payment_methods', LazyOption::findBy($paymentMethodRepository, 'code'))->setDefault('shipping_methods', LazyOption::all($shippingMethodRepository))->setAllowedTypes('shipping_methods', 'array')->setNormalizer('shipping_methods', LazyOption::findBy($shippingMethodRepository, 'code')); }
private function generateOption() { $optionName = "vp_random_" . Random::generate(10, 'a-z'); $optionValue = $this->faker->words(rand(1, 20)); add_option($optionName, $optionValue); return []; }
/** * @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('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); }
/** * @param ChannelFactoryInterface $channelFactory * @param RepositoryInterface $localeRepository * @param RepositoryInterface $currencyRepository * @param RepositoryInterface $paymentMethodRepository * @param RepositoryInterface $shippingMethodRepository */ public function __construct(ChannelFactoryInterface $channelFactory, RepositoryInterface $localeRepository, RepositoryInterface $currencyRepository, RepositoryInterface $paymentMethodRepository, RepositoryInterface $shippingMethodRepository) { $this->channelFactory = $channelFactory; $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('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('tax_calculation_strategy', 'order_items_based')->setAllowedTypes('tax_calculation_strategy', 'string')->setDefault('default_locale', function (Options $options) { return $this->faker->randomElement($options['locales']); })->setAllowedTypes('default_locale', LocaleInterface::class)->setNormalizer('default_locale', LazyOption::findOneBy($localeRepository, 'code'))->setDefault('locales', LazyOption::all($localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($localeRepository, 'code'))->setDefault('default_currency', function (Options $options) { return $this->faker->randomElement($options['currencies']); })->setAllowedTypes('default_currency', CurrencyInterface::class)->setNormalizer('default_currency', LazyOption::findOneBy($currencyRepository, 'code'))->setDefault('currencies', LazyOption::all($currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($currencyRepository, 'code'))->setDefault('payment_methods', LazyOption::all($paymentMethodRepository))->setAllowedTypes('payment_methods', 'array')->setNormalizer('payment_methods', LazyOption::findBy($paymentMethodRepository, 'code'))->setDefault('shipping_methods', LazyOption::all($shippingMethodRepository))->setAllowedTypes('shipping_methods', 'array')->setNormalizer('shipping_methods', LazyOption::findBy($shippingMethodRepository, 'code'))->setDefault('theme_name', null); }
/** * {@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('slug', function (Options $options) { return $this->taxonSlugGenerator->generate($options['name']); })->setDefault('description', function (Options $options) { return $this->faker->paragraph; })->setDefault('children', [])->setAllowedTypes('children', ['array']); }
/** * @param FactoryInterface $productOptionFactory * @param FactoryInterface $productOptionValueFactory * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $productOptionFactory, FactoryInterface $productOptionValueFactory, RepositoryInterface $localeRepository) { $this->productOptionFactory = $productOptionFactory; $this->productOptionValueFactory = $productOptionValueFactory; $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('values', null)->setDefault('values', function (Options $options, $values) { if (is_array($values)) { return $values; } $values = []; for ($i = 1; $i <= 5; ++$i) { $values[sprintf('%s-option#%d', $options['code'], $i)] = sprintf('%s #i%d', $options['name'], $i); } return $values; })->setAllowedTypes('values', 'array'); }
/** * {@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('description', function (Options $options) { return $this->faker->sentence(); })->setDefault('gateway', 'offline')->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setAllowedTypes('enabled', 'bool'); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', $this->faker->words(3, true))->setDefault('description', $this->faker->sentence())->setDefault('usage_limit', null)->setDefault('coupon_based', false)->setDefault('exclusive', $this->faker->boolean(25))->setDefault('priority', 0)->setDefault('starts_at', null)->setAllowedTypes('starts_at', ['null', 'string'])->setDefault('ends_at', null)->setAllowedTypes('ends_at', ['null', 'string'])->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setDefined('rules')->setNormalizer('rules', function (Options $options, array $rules) { if (empty($rules)) { return [[]]; } return $rules; })->setDefined('actions')->setNormalizer('actions', function (Options $options, array $actions) { if (empty($actions)) { return [[]]; } return $actions; }); }
/** * {@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('values', null)->setDefault('values', function (Options $options, $values) { if (is_array($values)) { return $values; } $values = []; for ($i = 1; $i <= 5; ++$i) { $values[sprintf('%s-option#%d', $options['code'], $i)] = sprintf('%s #i%d', $options['name'], $i); } return $values; })->setAllowedTypes('values', 'array'); }
/** * {@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('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('tax_calculation_strategy', 'order_items_based')->setAllowedTypes('tax_calculation_strategy', 'string')->setDefault('default_locale', function (Options $options) { return $this->faker->randomElement($options['locales']); })->setAllowedTypes('default_locale', ['string', LocaleInterface::class])->setNormalizer('default_locale', LazyOption::findOneBy($this->localeRepository, 'code'))->setDefault('locales', LazyOption::all($this->localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($this->localeRepository, 'code'))->setDefault('base_currency', function (Options $options) { return $this->faker->randomElement($options['currencies']); })->setAllowedTypes('base_currency', ['string', CurrencyInterface::class])->setNormalizer('base_currency', LazyOption::findOneBy($this->currencyRepository, 'code'))->setDefault('currencies', LazyOption::all($this->currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($this->currencyRepository, 'code'))->setDefault('theme_name', null); }
/** * {@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')); }
/** * Create a random ProjectPhaseDocument. * * @param int VisualAppeal\Connect\ProjectPhase $projectPhase (Default: null, newly created) * * @return VisualAppeal\Connect\ProjectPhaseDocument */ public function createProjectPhaseDocument($projectPhase = null) { $projectPhase = $projectPhase ?: $this->createProjectPhase(); return \VisualAppeal\Connect\ProjectPhaseDocument::create(['project_phase_id' => $projectPhase->id, 'title' => implode(' ', $this->faker->words(4)), 'content' => implode("\n", $this->faker->paragraphs(3)), 'type' => 'published']); }
/** * {@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'); }