101 lines
3.6 KiB
PHP
101 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\PriceType;
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class ProductSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$categoryIds = Category::pluck('id')->toArray();
|
|
$products = [
|
|
[
|
|
'name' => 'Gamis Syari Khadijah',
|
|
'description' => 'Gamis syari berbahan wolfis premium dengan potongan elegan.',
|
|
'is_active' => true,
|
|
'prices' => [
|
|
PriceType::PURCHASE->value => 120000,
|
|
PriceType::DISTRIBUTOR->value => 140000,
|
|
PriceType::AGENT->value => 160000,
|
|
PriceType::RESELLER->value => 180000,
|
|
PriceType::RETAIL->value => 210000,
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Dress Brokat Aisyah',
|
|
'description' => 'Dress dengan balutan brokat mewah cocok untuk kondangan.',
|
|
'is_active' => true,
|
|
'prices' => [
|
|
PriceType::PURCHASE->value => 150000,
|
|
PriceType::DISTRIBUTOR->value => 170000,
|
|
PriceType::AGENT->value => 195000,
|
|
PriceType::RESELLER->value => 220000,
|
|
PriceType::RETAIL->value => 250000,
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Tunik Muslimah Daily',
|
|
'description' => 'Tunik kasual berbahan katun rayon yang nyaman dipakai sehari-hari.',
|
|
'is_active' => true,
|
|
'prices' => [
|
|
PriceType::PURCHASE->value => 80000,
|
|
PriceType::DISTRIBUTOR->value => 95000,
|
|
PriceType::AGENT->value => 110000,
|
|
PriceType::RESELLER->value => 130000,
|
|
PriceType::RETAIL->value => 150000,
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Abaya Dubai Hitam',
|
|
'description' => 'Abaya gaya timur tengah dengan bordir benang emas yang anggun.',
|
|
'is_active' => true,
|
|
'prices' => [
|
|
PriceType::PURCHASE->value => 180000,
|
|
PriceType::DISTRIBUTOR->value => 210000,
|
|
PriceType::AGENT->value => 240000,
|
|
PriceType::RESELLER->value => 270000,
|
|
PriceType::RETAIL->value => 310000,
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Setelan Kulot Fatima',
|
|
'description' => 'Setelan atasan asimetris dan celana kulot dengan desain modern.',
|
|
'is_active' => true,
|
|
'prices' => [
|
|
PriceType::PURCHASE->value => 135000,
|
|
PriceType::DISTRIBUTOR->value => 155000,
|
|
PriceType::AGENT->value => 175000,
|
|
PriceType::RESELLER->value => 195000,
|
|
PriceType::RETAIL->value => 230000,
|
|
],
|
|
],
|
|
];
|
|
|
|
foreach ($products as $data) {
|
|
$prices = $data['prices'];
|
|
unset($data['prices']);
|
|
|
|
$product = Product::create($data);
|
|
|
|
if (! empty($categoryIds)) {
|
|
$randomCategories = collect($categoryIds)->random(rand(1, min(3, count($categoryIds))))->toArray();
|
|
$product->categories()->sync($randomCategories);
|
|
}
|
|
|
|
foreach ($prices as $type => $price) {
|
|
$product->prices()->create([
|
|
'price_type' => $type,
|
|
'price' => $price,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|