feat: refactor cart and bundle handling to support Buyable interface for improved flexibility

This commit is contained in:
2026-07-14 16:41:34 -03:00
parent 562b48b3bd
commit ab042acf9b
11 changed files with 171 additions and 144 deletions

View File

@@ -32,12 +32,12 @@ class CartService
/**
* @return array{cart: Cart, guest_token: ?string}
*/
public function addItem(Tenant $tenant, Request $request, int $productVariantId, int $quantity): array
public function addItem(Tenant $tenant, Request $request, string $buyableType, int $buyableId, int $quantity): array
{
$resolvedIdentity = $this->resolveIdentity($request, true);
$identity = $resolvedIdentity['identity'];
$cart = $this->findOrCreateCart($tenant, $identity);
$cart->addItem($productVariantId, $quantity);
$cart->addItem($buyableType, $buyableId, $quantity);
return [
'cart' => $this->loadCart($cart),
@@ -45,20 +45,20 @@ class CartService
];
}
public function updateItemQuantity(Tenant $tenant, Request $request, int $productVariantId, int $quantity): Cart
public function updateItemQuantity(Tenant $tenant, Request $request, string $buyableType, int $buyableId, int $quantity): Cart
{
$identity = $this->requireIdentity($request);
$cart = $this->findCartOrFail($tenant, $identity);
$cart->updateItem($productVariantId, $quantity);
$cart->updateItem($buyableType, $buyableId, $quantity);
return $this->loadCart($cart);
}
public function removeItem(Tenant $tenant, Request $request, int $productVariantId): Cart
public function removeItem(Tenant $tenant, Request $request, string $buyableType, int $buyableId): Cart
{
$identity = $this->requireIdentity($request);
$cart = $this->findCartOrFail($tenant, $identity);
$cart->removeItem($productVariantId);
$cart->removeItem($buyableType, $buyableId);
return $this->loadCart($cart);
}