/** * Only seed shops. * * @param Shop $owner */ private function seedAttributes($owner) { if (!$owner instanceof Shop) { return; } if ($this->faker->boolean(20)) { return; } $attributeGroups = $owner->attributeGroups()->saveMany(factory(AttributeGroup::class, $this->faker->numberBetween(2, 4))->make()); $attributeGroups->each(function (AttributeGroup $attributeGroup) { $attributeGroup->attributeOptions()->saveMany(factory(AttributeOption::class, $this->faker->numberBetween(2, 4))->make()); }); $variantManager = app(\App\Modules\ProductModule\Managers\VariantManager::class); /** @var Product[] $products */ $products = $owner->products()->get(); foreach ($products as $product) { if ($this->faker->boolean(20)) { continue; } $options = $attributeGroups->random(2)->pluck('attributeOptions')->flatten(1); $product->attributeOptions()->sync($options->pluck('id')->toArray()); $variantManager->refreshVariants($product); } }