feat: refactor product variant handling to use product pricing and remove unnecessary fields

This commit is contained in:
2026-06-30 15:58:19 -03:00
parent 8b10996319
commit fdeba7540b
10 changed files with 5 additions and 56 deletions

View File

@@ -22,8 +22,8 @@ class CartItemResource extends JsonResource
return [
'id' => $this->id,
'cantidad' => $this->cantidad,
'precio_unitario' => $this->formatMoney($variant?->precio),
'subtotal' => $this->formatMoney(($variant?->precio ?? 0) * $this->cantidad),
'precio_unitario' => $this->formatMoney($product?->precio),
'subtotal' => $this->formatMoney(($product?->precio ?? 0) * $this->cantidad),
'product' => $product === null ? null : [
'id' => $product->id,
'nombre' => $product->nombre,
@@ -31,8 +31,6 @@ class CartItemResource extends JsonResource
],
'variant' => $variant === null ? null : [
'id' => $variant->id,
'nombre' => $variant->nombre,
'slug' => $variant->slug,
'definitions' => ProductVariantDefinitionResource::collection($variant->definitions),
],
];

View File

@@ -20,7 +20,7 @@ class CartResource extends JsonResource
: collect();
$subtotal = $items->reduce(
fn (float $carry, $item): float => $carry + ((float) ($item->variant?->precio ?? 0) * $item->cantidad),
fn (float $carry, $item): float => $carry + ((float) ($item->variant?->product?->precio ?? 0) * $item->cantidad),
0.0,
);