93 lines
2.3 KiB
PHP
93 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\PriceType;
|
|
use App\Enums\ProductStatus;
|
|
use App\Enums\ProductType;
|
|
use App\Models\Hub;
|
|
use App\Models\Partner;
|
|
use App\Models\Product;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends Factory<Product>
|
|
*/
|
|
class ProductFactory extends Factory
|
|
{
|
|
protected $model = Product::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$name = fake()->words(3, true);
|
|
|
|
return [
|
|
'partner_id' => Partner::factory(),
|
|
'name' => ucfirst($name),
|
|
'slug' => Str::slug($name).'-'.fake()->unique()->numberBetween(1000, 9999),
|
|
'product_type' => ProductType::LocalStock,
|
|
'status' => ProductStatus::Draft,
|
|
'price_type' => PriceType::Fixed,
|
|
'description_short' => fake()->sentence(),
|
|
'description_long' => fake()->paragraphs(2, true),
|
|
'is_curated' => false,
|
|
'is_available' => true,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Teaser-Produkt (Säule A: Local Express).
|
|
*/
|
|
public function localStock(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'product_type' => ProductType::LocalStock,
|
|
'price_type' => PriceType::Fixed,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Konfigurations-Produkt (Säule B: Smart Club).
|
|
*/
|
|
public function smartOrder(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'product_type' => ProductType::SmartOrder,
|
|
'price_type' => PriceType::FromPrice,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Aktives und kuratiertes Produkt.
|
|
*/
|
|
public function active(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => ProductStatus::Active,
|
|
'is_curated' => true,
|
|
'curated_at' => now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Produkt in einem bestimmten Hub.
|
|
*/
|
|
public function inHub(Hub $hub): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'hub_id' => $hub->id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Verkauftes Produkt.
|
|
*/
|
|
public function sold(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => ProductStatus::Sold,
|
|
'is_available' => false,
|
|
]);
|
|
}
|
|
}
|