feat: implement VMware vCenter integration, enhance product pricing display, and update order processing logic.
This commit is contained in:
@@ -178,4 +178,57 @@ class ServiceController extends Controller
|
||||
'data' => new ServiceResource($product),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get addons for a specific product
|
||||
* GET /v1/products/{productId}/addons
|
||||
*/
|
||||
public function getProductAddons(Request $request, string $productId)
|
||||
{
|
||||
$product = Product::where('uuid', $productId)->first();
|
||||
|
||||
if (!$product) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Sản phẩm không tồn tại'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$addons = $product->addons()
|
||||
->where('status', true)
|
||||
->get();
|
||||
|
||||
$groupedAddons = [
|
||||
'cpu' => [],
|
||||
'ram' => [],
|
||||
'disk' => [],
|
||||
'other' => []
|
||||
];
|
||||
|
||||
foreach ($addons as $addon) {
|
||||
// Group by code field (cpu, ram, disk, gpu, bandwidth, etc.)
|
||||
$key = strtolower(trim($addon->code));
|
||||
if (!in_array($key, ['cpu', 'ram', 'disk'])) {
|
||||
$key = 'other';
|
||||
}
|
||||
$groupedAddons[$key][] = [
|
||||
'id' => $addon->id,
|
||||
'name' => $addon->name,
|
||||
'type' => $addon->type,
|
||||
'code' => $addon->code,
|
||||
'price' => $addon->price,
|
||||
'description' => $addon->description,
|
||||
'min' => $addon->min,
|
||||
'max' => $addon->max,
|
||||
'step' => $addon->step,
|
||||
'prefix' => $addon->prefix,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'data' => $groupedAddons
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user