- Updated the OwnerVerificationRequest model to change pendingToggleIsActive to pendingToggleStatus, reflecting the new status structure. - Refactored the Product model to replace is_active with status, utilizing the ProductStatus enum for better clarity and type safety. - Modified the ProductService to accommodate the new status field, including pagination and creation logic. - Adjusted the AnalysisService to filter products based on their status. - Updated the VerificationChangeFormatter to handle the new status field. - Created a migration to remove is_active from the products table and add status with appropriate default values. - Refactored the ProductSeeder to use the new status field. - Updated frontend components and types to reflect the changes from is_active to status. - Adjusted tests to ensure they validate the new status logic correctly.
104 lines
3.8 KiB
PHP
104 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\ProductStatus;
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use App\Models\ProductVariant;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ProductSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$categories = Category::query()->pluck('id', 'slug');
|
|
|
|
$products = [
|
|
[
|
|
'name' => 'Daster Batik Parang',
|
|
'description' => 'Daster batik motif parang dengan bahan katun nyaman untuk pemakaian sehari-hari.',
|
|
'category_slugs' => ['daster'],
|
|
'variants' => [
|
|
['name' => 'S', 'stock' => 25],
|
|
['name' => 'M', 'stock' => 40],
|
|
['name' => 'L', 'stock' => 35],
|
|
['name' => 'XL', 'stock' => 20],
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Setelan Celana Batik Modern',
|
|
'description' => 'Setelan atasan dan celana batik dengan potongan modern untuk acara formal maupun kasual.',
|
|
'category_slugs' => ['setelan-celana'],
|
|
'variants' => [
|
|
['name' => 'S', 'stock' => 15],
|
|
['name' => 'M', 'stock' => 20],
|
|
['name' => 'L', 'stock' => 18],
|
|
['name' => 'XL', 'stock' => 12],
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Blouse Batik Lengan Panjang',
|
|
'description' => 'Blouse batik lengan panjang dengan detail kerah mandarin.',
|
|
'category_slugs' => ['atasan'],
|
|
'variants' => [
|
|
['name' => 'S', 'stock' => 30],
|
|
['name' => 'M', 'stock' => 35],
|
|
['name' => 'L', 'stock' => 28],
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Rok Lilit Batik',
|
|
'description' => 'Rok lilit batik dengan motif klasik, mudah disesuaikan dengan berbagai ukuran.',
|
|
'category_slugs' => ['bawahan'],
|
|
'variants' => [
|
|
['name' => 'All Size', 'stock' => 50],
|
|
],
|
|
],
|
|
[
|
|
'name' => 'Daster Busui Nursing',
|
|
'description' => 'Daster busui dengan akses bukaan menyusui praktis dan bahan adem.',
|
|
'category_slugs' => ['busui', 'daster'],
|
|
'variants' => [
|
|
['name' => 'M', 'stock' => 22],
|
|
['name' => 'L', 'stock' => 26],
|
|
['name' => 'XL', 'stock' => 18],
|
|
],
|
|
],
|
|
];
|
|
|
|
try {
|
|
DB::transaction(function () use ($products, $categories): void {
|
|
foreach ($products as $productData) {
|
|
$product = Product::factory()->create([
|
|
'name' => $productData['name'],
|
|
'slug' => str()->slug($productData['name']),
|
|
'description' => $productData['description'],
|
|
'status' => ProductStatus::ACTIVE,
|
|
]);
|
|
|
|
$product->categories()->sync(
|
|
collect($productData['category_slugs'])
|
|
->map(fn (string $slug) => $categories[$slug])
|
|
->all()
|
|
);
|
|
|
|
foreach ($productData['variants'] as $variantData) {
|
|
ProductVariant::factory()->create([
|
|
'product_id' => $product->id,
|
|
'name' => $variantData['name'],
|
|
'stock' => $variantData['stock'],
|
|
]);
|
|
}
|
|
}
|
|
});
|
|
} catch (\Throwable $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|