File: D:/HostingSpaces/SBogers10/shop.komma.nl/database/seeds/TestProducts.php
<?php
namespace App\seeds;
use App\Categories\Models\Category;
use App\Vat\VatScenarioEnum;
use \Illuminate\Database\Eloquent\Collection as DatabaseCollection;
use \Illuminate\Support\Collection as RegularCollection;
use Illuminate\Support\Str;
use Komma\KMS\Globalization\Languages\Models\Language;
use App\Products\Product\Product;
use App\Products\Product\ProductTranslation;
use App\Products\ProductGroup\ProductGroup;
use App\Products\ProductGroup\ProductGroupTranslation;
use App\Products\ProductGroupBehaviour\ProductGroupBehaviour;
use Illuminate\Database\Seeder;
class TestProducts extends Seeder
{
/** @var Language[]|DatabaseCollection */
private $languages;
/** @var int */
private $eanNumberCounter = 1000000;
/** @var ProductGroupBehaviour[]|DatabaseCollection */
private $productGroupBehaviors;
/** @var Category[]|DatabaseCollection */
private $categories;
public function run()
{
$this->languages = Language::whereIn('iso_2', ['nl', 'de', 'en'])->get()->keyBy('iso_2');
$this->productGroupBehaviors = ProductGroupBehaviour::all()->keyBy('name');
$this->categories = Category::all()->keyBy('code_name');
$handTools = $this->createHandToolsProducts();
$greenEggProducts = $this->createBarbequeProducts();
$studioLightningProducts = $this->createStudioLightningProducts();
$lowVatProducts = $this->createLowVatProducts();
$this->createBigGreenEggGroup($greenEggProducts);
$this->createLedSetPlusStandGroup($studioLightningProducts);
}
/**
* @return RegularCollection
*/
public function createBarbequeProducts() {
$products = collect();
$product = new Product([
'active' => '1',
'price' => '88500',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Big Green Egg Small', 'slug' => Str::slug('Big Green Egg Small'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Big Green Egg Small', 'slug' => Str::slug('Big Green Egg Small'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Big Green Egg Small', 'slug' => Str::slug('Big Green Egg Small'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('barbecues'));
$products->push($product);
$product = new Product([
'active' => '1',
'price' => '99500',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Big Green Egg Medium', 'slug' => Str::slug('Big Green Egg Medium'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Big Green Egg Medium', 'slug' => Str::slug('Big Green Egg Medium'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Big Green Egg Medium', 'slug' => Str::slug('Big Green Egg Medium'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('barbecues'));
$products->push($product);
$product = new Product([
'active' => '1',
'price' => '128900',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Big Green Egg Large', 'slug' => Str::slug('Big Green Egg Large'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Big Green Egg Large', 'slug' => Str::slug('Big Green Egg Large'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Big Green Egg Large', 'slug' => Str::slug('Big Green Egg Large'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('barbecues'));
$products->push($product);
return $products;
}
/**
* @return RegularCollection
*/
public function createLowVatProducts() {
$products = collect();
$product = new Product([
'active' => '1',
'price' => '5595',
'vat_scenario_enum' => VatScenarioEnum::low_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Dry aged Tomahawk', 'slug' => Str::slug('Dry aged Tomahawk'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Gerijpte Tomahawk', 'slug' => Str::slug('Gerijpte Tomahawk'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Trocken gealtert Tomahawk', 'slug' => Str::slug('Trocken gealtert Tomahawk'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('barbecues'));
$products->push($product);
return $products;
}
/**
* @return RegularCollection
*/
public function createHandToolsProducts() {
$products = collect();
$product = new Product([
'active' => '1',
'price' => '1699',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Hammer', 'slug' => Str::slug('Hammer'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Hamer', 'slug' => Str::slug('Hamer'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Hammer', 'slug' => Str::slug('Hammer'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('handtools'));
$products->push($product);
$product = new Product([
'active' => '1',
'price' => '1199',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Handsaw', 'slug' => Str::slug('Handsaw'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Handzaag', 'slug' => Str::slug('Handzaag'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Handsäge', 'slug' => Str::slug('Handsäge'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('handtools'));
$products->push($product);
return $products;
}
/**
* @return RegularCollection
*/
public function createStudioLightningProducts() {
$products = collect();
$product = new Product([
'active' => '1',
'price' => '18900',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'LED lamp', 'slug' => Str::slug('LED lamp'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'LED lamp', 'slug' => Str::slug('LED lamp'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'LED Lampe', 'slug' => Str::slug('LED Lampe'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('studio_lightning'));
$products->push($product);
$product = new Product([
'active' => '1',
'price' => '2400',
'vat_scenario_enum' => VatScenarioEnum::high_inc,
'stock_keeping_unit' => 'EAN'.$this->eanNumberCounter++,
'stock' => mt_rand(1, 100),
]);
$product->save();
$product->translation()->saveMany([
new ProductTranslation(['name' => 'Lamp stand', 'slug' => Str::slug('Lamp stand'), 'language_id' => $this->languages->get('en')->id]),
new ProductTranslation(['name' => 'Lampstatief', 'slug' => Str::slug('Lampstatief'), 'language_id' => $this->languages->get('nl')->id]),
new ProductTranslation(['name' => 'Lampenständer', 'slug' => Str::slug('Lampenständer'), 'language_id' => $this->languages->get('de')->id]),
]);
$product->categories()->save($this->categories->get('studio_lightning'));
$products->push($product);
return $products;
}
/**
* @param RegularCollection $productsToLink
* @return ProductGroup
*/
public function createBigGreenEggGroup(RegularCollection $productsToLink): ProductGroup {
$productGroup = new ProductGroup([
'active' => '1',
]);
$productGroup->productGroupBehaviour()->associate($this->productGroupBehaviors->get('xor'));
$productGroup->save();
$productGroup->translation()->saveMany([
new ProductGroupTranslation(['name' => 'Big Green Egg BBQ (concept)', 'slug' => Str::slug('Big Green Egg BBQ (concept)'), 'language_id' => $this->languages->get('en')->id]),
new ProductGroupTranslation(['name' => 'Big Green Egg BBQ (concept)', 'slug' => Str::slug('Big Green Egg BBQ (concept)'), 'language_id' => $this->languages->get('nl')->id]),
new ProductGroupTranslation(['name' => 'Big Green Egg BBQ (Konzept)', 'slug' => Str::slug('Big Green Egg BBQ (Konzept)'), 'language_id' => $this->languages->get('de')->id]),
]);
$productGroup->categories()->save($this->categories->get('barbecues'));
$productGroup->products()->saveMany($productsToLink);
return $productGroup;
}
/**
* @param RegularCollection $productsToLink
* @return ProductGroup
*/
public function createLedSetPlusStandGroup(RegularCollection $productsToLink): ProductGroup {
$productGroup = new ProductGroup([
'active' => '1',
]);
$productGroup->productGroupBehaviour()->associate($this->productGroupBehaviors->get('and'));
$productGroup->save();
$productGroup->translation()->saveMany([
new ProductGroupTranslation(['name' => 'LED set lamp + statief (concept)', 'slug' => Str::slug('LED set lamp + statief (concept)'), 'language_id' => $this->languages->get('en')->id]),
new ProductGroupTranslation(['name' => 'LED set lamp + tripod (concept)', 'slug' => Str::slug('LED set lamp + tripod (concept)'), 'language_id' => $this->languages->get('nl')->id]),
new ProductGroupTranslation(['name' => 'LED Set Lampe + Stativ (Konzept)', 'slug' => Str::slug('LED Set Lampe + Stativ (Konzept)'), 'language_id' => $this->languages->get('de')->id]),
]);
$productGroup->categories()->save($this->categories->get('studio_lightning'));
$productGroup->products()->saveMany($productsToLink);
return $productGroup;
}
}