updat
This commit is contained in:
@@ -56,7 +56,7 @@ class ProductCategoryController extends Controller
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$this->productCategoryService->delete($id);
|
||||
return response()->json(['success' => true]);
|
||||
return redirect()->route('products.group.index')->with('success', 'Delete Group Success');
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
|
||||
@@ -48,8 +48,11 @@ class ProductController extends Controller
|
||||
// Fetch OS versions with their group for the OS selector component
|
||||
$osVersions = \App\Models\Os::with('osGroup')->where('status', 1)->get();
|
||||
|
||||
// Fetch Control Panels for Hosting products
|
||||
$controlPanels = \App\Models\ControlPanel::active()->ordered()->get();
|
||||
|
||||
if ($step === 1) {
|
||||
return view("administrator.pages.product.create", compact('group', 'type', 'title', 'osVersions'));
|
||||
return view("administrator.pages.product.create", compact('group', 'type', 'title', 'osVersions', 'controlPanels'));
|
||||
}
|
||||
|
||||
if (!$request->has(['step', 'type'])) {
|
||||
@@ -97,7 +100,10 @@ class ProductController extends Controller
|
||||
|
||||
$view = "administrator.pages.product.edit";
|
||||
|
||||
$data = compact('product', 'title', 'group', 'type', 'osVersions');
|
||||
// Fetch Control Panels for Hosting products
|
||||
$controlPanels = \App\Models\ControlPanel::active()->ordered()->get();
|
||||
|
||||
$data = compact('product', 'title', 'group', 'type', 'osVersions', 'controlPanels');
|
||||
|
||||
return view($view, $data);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ class ProductRequest extends FormRequest
|
||||
],
|
||||
'short_description' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'thumbnail' => ['nullable', 'string', 'max:255'],
|
||||
'gallery' => ['nullable', 'array'],
|
||||
'gallery.*' => ['nullable', 'string', 'max:255'],
|
||||
'stock' => ['nullable', 'integer', 'min:0'],
|
||||
'is_unlimited' => ['boolean'],
|
||||
'cpu' => ['nullable', 'string', 'max:255'],
|
||||
@@ -64,11 +67,23 @@ class ProductRequest extends FormRequest
|
||||
'is_active' => ['boolean'],
|
||||
'sort_order' => ['nullable', 'integer'],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
|
||||
// OS versions (pivot table os_product)
|
||||
|
||||
// OS versions (pivot table os_product) - for VPS
|
||||
'os_ids' => ['nullable', 'array'],
|
||||
'os_ids.*' => ['exists:os,id'],
|
||||
|
||||
|
||||
// Control Panels (pivot table product_control_panel) - for Hosting
|
||||
'control_panel_ids' => ['nullable', 'array'],
|
||||
'control_panel_ids.*' => ['exists:control_panels,id'],
|
||||
'control_panel_price_modifiers' => ['nullable', 'array'],
|
||||
'control_panel_price_modifiers.*' => ['nullable', 'numeric', 'min:0'],
|
||||
'control_panel_default' => ['nullable', 'exists:control_panels,id'],
|
||||
|
||||
// Images
|
||||
'thumbnail' => ['nullable', 'string', 'max:255'],
|
||||
'gallery' => ['nullable', 'array'],
|
||||
'gallery.*' => ['nullable', 'string', 'max:255'],
|
||||
|
||||
// Pricing cycles (table product_pricings)
|
||||
'pricing' => ['nullable', 'array'],
|
||||
];
|
||||
@@ -127,7 +142,14 @@ class ProductRequest extends FormRequest
|
||||
'short_description.max' => 'Mô tả ngắn không được vượt quá 255 ký tự.',
|
||||
|
||||
'description.string' => 'Mô tả phải là chuỗi ký tự.',
|
||||
|
||||
|
||||
'thumbnail.string' => 'Đường dẫn ảnh đại diện phải là chuỗi ký tự.',
|
||||
'thumbnail.max' => 'Đường dẫn ảnh đại diện không được vượt quá 255 ký tự.',
|
||||
|
||||
'gallery.array' => 'Thư viện ảnh không hợp lệ.',
|
||||
'gallery.*.string' => 'Đường dẫn ảnh trong thư viện phải là chuỗi ký tự.',
|
||||
'gallery.*.max' => 'Đường dẫn ảnh trong thư viện không được vượt quá 255 ký tự.',
|
||||
|
||||
'stock.integer' => 'Số lượng tồn kho phải là số nguyên.',
|
||||
'stock.min' => 'Số lượng tồn kho không được âm.',
|
||||
|
||||
@@ -168,7 +190,14 @@ class ProductRequest extends FormRequest
|
||||
|
||||
'os_ids.array' => 'Danh sách hệ điều hành không hợp lệ.',
|
||||
'os_ids.*.exists' => 'Hệ điều hành được chọn không tồn tại.',
|
||||
|
||||
|
||||
'control_panel_ids.array' => 'Danh sách Control Panel không hợp lệ.',
|
||||
'control_panel_ids.*.exists' => 'Control Panel được chọn không tồn tại.',
|
||||
'control_panel_price_modifiers.array' => 'Danh sách phụ phí Control Panel không hợp lệ.',
|
||||
'control_panel_price_modifiers.*.numeric' => 'Phụ phí Control Panel phải là số.',
|
||||
'control_panel_price_modifiers.*.min' => 'Phụ phí Control Panel không được âm.',
|
||||
'control_panel_default.exists' => 'Control Panel mặc định không tồn tại.',
|
||||
|
||||
'pricing.array' => 'Thông tin giá không hợp lệ.',
|
||||
'pricing.*.price.numeric' => 'Giá phải là số.',
|
||||
'pricing.*.price.min' => 'Giá không được âm.',
|
||||
|
||||
@@ -24,11 +24,16 @@ class ProductService
|
||||
// Create product
|
||||
$product = $this->repository->create($productData);
|
||||
|
||||
// Sync OS versions if provided
|
||||
// Sync OS versions if provided (for VPS)
|
||||
if (!empty($data['os_ids'])) {
|
||||
$product->osVersions()->sync($data['os_ids']);
|
||||
}
|
||||
|
||||
// Sync Control Panels if provided (for Hosting)
|
||||
if (!empty($data['control_panel_ids'])) {
|
||||
$this->saveControlPanels($product, $data);
|
||||
}
|
||||
|
||||
// Save pricing cycles if provided
|
||||
if (!empty($data['pricing'])) {
|
||||
$this->savePricings($product, $data['pricing'], $data['currency'] ?? 'USD');
|
||||
@@ -48,11 +53,16 @@ class ProductService
|
||||
// Get the product for relationships
|
||||
$product = $this->repository->find($id);
|
||||
|
||||
// Sync OS versions if provided
|
||||
// Sync OS versions if provided (for VPS)
|
||||
if (isset($data['os_ids'])) {
|
||||
$product->osVersions()->sync($data['os_ids']);
|
||||
}
|
||||
|
||||
// Sync Control Panels if provided (for Hosting)
|
||||
if (isset($data['control_panel_ids'])) {
|
||||
$this->saveControlPanels($product, $data);
|
||||
}
|
||||
|
||||
// Save pricing cycles if provided
|
||||
if (!empty($data['pricing'])) {
|
||||
$this->savePricings($product, $data['pricing'], $data['currency'] ?? 'USD');
|
||||
@@ -95,6 +105,26 @@ class ProductService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Control Panels for product (for Hosting)
|
||||
*/
|
||||
private function saveControlPanels($product, array $data): void
|
||||
{
|
||||
$syncData = [];
|
||||
|
||||
foreach ($data['control_panel_ids'] as $panelId) {
|
||||
$priceModifier = $data['control_panel_price_modifiers'][$panelId] ?? 0;
|
||||
$isDefault = isset($data['control_panel_default']) && $data['control_panel_default'] == $panelId;
|
||||
|
||||
$syncData[$panelId] = [
|
||||
'price_modifier' => $priceModifier,
|
||||
'is_default' => $isDefault,
|
||||
];
|
||||
}
|
||||
|
||||
$product->controlPanels()->sync($syncData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data for create/update
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user