Refactor VM resource specs resolution and enhance order payment success email with addon summary; add UpdateVmConfigJob for CPU/RAM updates
This commit is contained in:
@@ -12,6 +12,25 @@ class VpsServiceResource extends JsonResource
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function resolveSpecs($product): ?array
|
||||
{
|
||||
$addons = $this->addons ?? collect();
|
||||
if ($addons->isNotEmpty()) {
|
||||
return [
|
||||
'cpu' => (int) $addons->where('addon_type', 'cpu')->sum('addon_value'),
|
||||
'ram' => (int) $addons->where('addon_type', 'ram')->sum('addon_value'),
|
||||
'disk' => (int) $addons->where('addon_type', 'disk')->sum('addon_value'),
|
||||
'bandwidth' => (int) $addons->where('addon_type', 'bandwidth')->sum('addon_value'),
|
||||
];
|
||||
}
|
||||
return $product ? [
|
||||
'cpu' => (int) ($product->cpu ?? 0),
|
||||
'ram' => (int) ($product->ram ?? 0),
|
||||
'disk' => (int) ($product->disk ?? 0),
|
||||
'bandwidth' => (int) ($product->bandwidth ?? 0),
|
||||
] : null;
|
||||
}
|
||||
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$orderItem = $this->orderItem;
|
||||
@@ -43,13 +62,7 @@ class VpsServiceResource extends JsonResource
|
||||
'product_type' => $product->product_type,
|
||||
'page_type' => 'service_vps',
|
||||
] : null,
|
||||
'specs' => $product ? [
|
||||
'cpu' => (int) ($product->cpu ?? 0),
|
||||
'ram' => (int) ($product->ram ?? 0),
|
||||
'disk' => (int) ($product->disk ?? 0),
|
||||
'bandwidth' => (int) ($product->bandwidth ?? 0),
|
||||
'gpu' => $product->gpu,
|
||||
] : null,
|
||||
'specs' => $this->resolveSpecs($product),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user