'vps'], [ 'name' => 'VPS', 'is_active' => true, 'sort_order' => 1, 'type' => 'vps', ] ); // Create child categories for VPS $ubuntuCategory = ProductCategories::updateOrCreate( ['slug' => 'vps-ubuntu'], [ 'name' => 'VPS Ubuntu', 'parent_id' => $vpsCategory->id, 'is_active' => true, 'sort_order' => 1, 'type' => 'vps', ] ); $windowsCategory = ProductCategories::updateOrCreate( ['slug' => 'vps-windows'], [ 'name' => 'VPS Windows', 'parent_id' => $vpsCategory->id, 'is_active' => true, 'sort_order' => 2, 'type' => 'vps', ] ); // Get or create Ubuntu OS Group - each version has different template_id from vCenter $ubuntuGroup = OsGroup::updateOrCreate( ['name' => 'Ubuntu'], [ 'thumbnail' => 'ubuntu.png', 'status' => 1, ] ); // Create Ubuntu OS versions - each with DIFFERENT template_id from vCenter $ubuntuVersions = [ ['version' => '20.04 LTS', 'template_id' => 'vm-3005'], // Ubuntu 20.04 ['version' => '22.04 LTS', 'template_id' => 'vm-3010'], // Ubuntu 22.04 ['version' => '24.04 LTS', 'template_id' => 'vm-3011'], // Ubuntu 24.04 ]; $ubuntuOS = []; foreach ($ubuntuVersions as $uv) { $os = Os::updateOrCreate( [ 'os_group_id' => $ubuntuGroup->id, 'version' => $uv['version'], ], [ 'template_id' => $uv['template_id'], 'status' => 1, ] ); $ubuntuOS[] = $os; $this->command->info("Created Ubuntu {$uv['version']} with template_id: {$uv['template_id']}"); } // Create Windows OS Group - each version has different template_id from vCenter $windowsGroup = OsGroup::updateOrCreate( ['name' => 'Windows Server'], [ 'thumbnail' => 'windows.png', 'status' => 1, ] ); $windowsVersions = [ ['version' => '2019', 'template_id' => 'vm-3006'], // Windows 2019 ['version' => '2022', 'template_id' => 'vm-3007'], // Windows 2022 ]; $windowsOS = []; foreach ($windowsVersions as $wv) { $os = Os::updateOrCreate( [ 'os_group_id' => $windowsGroup->id, 'version' => $wv['version'], ], [ 'template_id' => $wv['template_id'], 'status' => 1, ] ); $windowsOS[] = $os; $this->command->info("Created Windows {$wv['version']} with template_id: {$wv['template_id']}"); } // VPS Products Data - using vm-3008 as template_id for items $vpsProducts = [ // Ubuntu VPS Plans [ 'name' => 'VPS Basic Ubuntu', 'slug' => 'vps-basic-ubuntu', 'short_description' => 'VPS Basic với Ubuntu - Phù hợp cho website nhỏ', 'description' => '
VPS Basic với Ubuntu 22.04 LTS - Phù hợp cho website cá nhân, blog
', 'thumbnail' => '/images/vps/basic.png', 'cpu' => 1, 'ram' => 1, 'disk' => 25, 'bandwidth' => 100, 'stock' => 100, 'is_active' => true, 'product_categories_id' => $ubuntuCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 150000, 'price_sale' => 99000], ['billing_cycle' => 'quarterly', 'price' => 450000, 'price_sale' => 297000], ['billing_cycle' => 'semi_annually', 'price' => 900000, 'price_sale' => 594000], ['billing_cycle' => 'annually', 'price' => 1800000, 'price_sale' => 1188000], ], 'os' => [0, 1, 2], // Ubuntu versions ], [ 'name' => 'VPS Standard Ubuntu', 'slug' => 'vps-standard-ubuntu', 'short_description' => 'VPS Standard với Ubuntu - Cân bằng giá và hiệu suất', 'description' => 'VPS Standard với Ubuntu 22.04 LTS - Phù hợp cho website vừa và nhỏ
', 'thumbnail' => '/images/vps/standard.png', 'cpu' => 2, 'ram' => 2, 'disk' => 50, 'bandwidth' => 200, 'stock' => 100, 'is_active' => true, 'product_categories_id' => $ubuntuCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 250000, 'price_sale' => 199000], ['billing_cycle' => 'quarterly', 'price' => 750000, 'price_sale' => 597000], ['billing_cycle' => 'semi_annually', 'price' => 1500000, 'price_sale' => 1194000], ['billing_cycle' => 'annually', 'price' => 3000000, 'price_sale' => 2388000], ], 'os' => [0, 1, 2], ], [ 'name' => 'VPS Professional Ubuntu', 'slug' => 'vps-professional-ubuntu', 'short_description' => 'VPS Professional với Ubuntu - Cho ứng dụng web', 'description' => 'VPS Professional với Ubuntu 22.04 LTS - Phù hợp cho website thương mại điện tử
', 'thumbnail' => '/images/vps/professional.png', 'cpu' => 4, 'ram' => 4, 'disk' => 100, 'bandwidth' => 500, 'stock' => 50, 'is_active' => true, 'product_categories_id' => $ubuntuCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 450000, 'price_sale' => 399000], ['billing_cycle' => 'quarterly', 'price' => 1350000, 'price_sale' => 1197000], ['billing_cycle' => 'semi_annually', 'price' => 2700000, 'price_sale' => 2394000], ['billing_cycle' => 'annually', 'price' => 5400000, 'price_sale' => 4788000], ], 'os' => [0, 1, 2], ], [ 'name' => 'VPS Enterprise Ubuntu', 'slug' => 'vps-enterprise-ubuntu', 'short_description' => 'VPS Enterprise với Ubuntu - Hiệu suất cao', 'description' => 'VPS Enterprise với Ubuntu 22.04 LTS - Cho ứng dụng enterprise
', 'thumbnail' => '/images/vps/enterprise.png', 'cpu' => 8, 'ram' => 8, 'disk' => 200, 'bandwidth' => 1000, 'stock' => 20, 'is_active' => true, 'product_categories_id' => $ubuntuCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 850000, 'price_sale' => 799000], ['billing_cycle' => 'quarterly', 'price' => 2550000, 'price_sale' => 2397000], ['billing_cycle' => 'semi_annually', 'price' => 5100000, 'price_sale' => 4794000], ['billing_cycle' => 'annually', 'price' => 10200000, 'price_sale' => 9588000], ], 'os' => [0, 1, 2], ], // Windows VPS Plans [ 'name' => 'VPS Basic Windows', 'slug' => 'vps-basic-windows', 'short_description' => 'VPS Basic với Windows Server', 'description' => 'VPS Basic với Windows Server 2019 - Phù hợp cho ứng dụng .NET
', 'thumbnail' => '/images/vps/windows-basic.png', 'cpu' => 1, 'ram' => 2, 'disk' => 40, 'bandwidth' => 100, 'stock' => 50, 'is_active' => true, 'product_categories_id' => $windowsCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 250000, 'price_sale' => 199000], ['billing_cycle' => 'quarterly', 'price' => 750000, 'price_sale' => 597000], ['billing_cycle' => 'semi_annually', 'price' => 1500000, 'price_sale' => 1194000], ['billing_cycle' => 'annually', 'price' => 3000000, 'price_sale' => 2388000], ], 'os' => [0, 1], // Windows versions ], [ 'name' => 'VPS Standard Windows', 'slug' => 'vps-standard-windows', 'short_description' => 'VPS Standard với Windows Server', 'description' => 'VPS Standard với Windows Server 2022 - Phù hợp cho enterprise
', 'thumbnail' => '/images/vps/windows-standard.png', 'cpu' => 2, 'ram' => 4, 'disk' => 80, 'bandwidth' => 200, 'stock' => 30, 'is_active' => true, 'product_categories_id' => $windowsCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 450000, 'price_sale' => 399000], ['billing_cycle' => 'quarterly', 'price' => 1350000, 'price_sale' => 1197000], ['billing_cycle' => 'semi_annually', 'price' => 2700000, 'price_sale' => 2394000], ['billing_cycle' => 'annually', 'price' => 5400000, 'price_sale' => 4788000], ], 'os' => [0, 1], ], [ 'name' => 'VPS Professional Windows', 'slug' => 'vps-professional-windows', 'short_description' => 'VPS Professional với Windows Server', 'description' => 'VPS Professional với Windows Server 2022 - Cho enterprise
', 'thumbnail' => '/images/vps/windows-professional.png', 'cpu' => 4, 'ram' => 8, 'disk' => 160, 'bandwidth' => 500, 'stock' => 15, 'is_active' => true, 'product_categories_id' => $windowsCategory->id, 'template_id' => 'vm-3008', 'pricing' => [ ['billing_cycle' => 'monthly', 'price' => 850000, 'price_sale' => 749000], ['billing_cycle' => 'quarterly', 'price' => 2550000, 'price_sale' => 2247000], ['billing_cycle' => 'semi_annually', 'price' => 5100000, 'price_sale' => 4494000], ['billing_cycle' => 'annually', 'price' => 10200000, 'price_sale' => 8988000], ], 'os' => [0, 1], ], ]; // Create Products foreach ($vpsProducts as $productData) { $productCategoriesId = $productData['product_categories_id']; $templateId = $productData['template_id']; $pricingData = $productData['pricing']; $osIndices = $productData['os']; unset($productData['product_categories_id'], $productData['template_id'], $productData['pricing'], $productData['os']); // Determine OS list based on category $osList = ($productCategoriesId === $ubuntuCategory->id) ? $ubuntuOS : $windowsOS; $product = Product::updateOrCreate( ['slug' => $productData['slug']], array_merge($productData, [ 'product_categories_id' => $productCategoriesId, ]) ); // Add template_id as attribute (stored in a separate table or as meta) // For now, we store it as part of product's custom attributes if needed // The template_id will be used when creating VM // Attach OS versions $osToAttach = []; foreach ($osIndices as $index) { if (isset($osList[$index])) { $osToAttach[] = $osList[$index]->id; } } if (!empty($osToAttach)) { $product->osVersions()->sync($osToAttach); } // Create pricing tiers foreach ($pricingData as $pricing) { ProductPricings::updateOrCreate( [ 'product_id' => $product->id, 'billing_cycle' => $pricing['billing_cycle'], ], [ 'price' => $pricing['price'], 'price_sale' => $pricing['price_sale'], 'currency' => 'VND', 'is_active' => true, ] ); } $this->command->info("Created product: {$product->name}"); } // Make sure we have VPS addons $this->ensureVPSAddons(); $this->command->info('VPS Products seeding completed!'); } private function ensureVPSAddons(): void { $vpsAddons = [ [ 'type' => 'vps', 'code' => 'cpu', 'name' => 'CPU', 'price' => 25000, 'min' => 1, 'max' => 32, 'step' => 1, 'prefix' => 'vCore', 'input_type' => 'number', 'status' => true, 'sort_order' => 0, ], [ 'type' => 'vps', 'code' => 'ram', 'name' => 'RAM', 'price' => 15000, 'min' => 1, 'max' => 64, 'step' => 1, 'prefix' => 'GB', 'input_type' => 'number', 'status' => true, 'sort_order' => 1, ], [ 'type' => 'vps', 'code' => 'disk', 'name' => 'SSD', 'price' => 5000, 'min' => 10, 'max' => 1000, 'step' => 10, 'prefix' => 'GB', 'input_type' => 'number', 'status' => true, 'sort_order' => 2, ], ]; foreach ($vpsAddons as $addon) { Addon::updateOrCreate( ['code' => $addon['code'], 'type' => $addon['type']], $addon ); } } }