feat: refactor cart and purchase handling to support polymorphic buyable types and improve code readability

This commit is contained in:
2026-07-16 09:55:38 -03:00
parent c05206cc51
commit 6fc6ed1fac
14 changed files with 196 additions and 79 deletions

View File

@@ -2,11 +2,12 @@
namespace App\Domains\Cart\Resources;
use App\Domains\Cart\Models\Cart;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \App\Domains\Cart\Models\Cart
* @mixin Cart
*/
class CartResource extends JsonResource
{
@@ -20,7 +21,7 @@ class CartResource extends JsonResource
: collect();
$subtotal = $items->reduce(
fn (float $carry, $item): float => $carry + ((float) ($item->variant?->product?->precio ?? 0) * $item->cantidad),
fn (float $carry, $item): float => $carry + ((float) ($item->buyable?->getPrice() ?? 0) * $item->cantidad),
0.0,
);