guest checkout

This commit is contained in:
Edward Yang 2022-06-28 16:39:38 +08:00
parent 223aeaa46f
commit a67b754b8f
2 changed files with 6 additions and 3 deletions

View File

@ -18,7 +18,7 @@ class CartController extends Controller
->whereRelation('product', 'active', '=', true)
->findOrFail($skuId);
$cart = CartService::add($customer, $sku, $quantity);
$cart = CartService::add($sku, $quantity, $customer);
return $cart;
}

View File

@ -28,12 +28,15 @@ class CartService
}
public static function add(Customer $customer, ProductSku $sku, int $quantity)
public static function add($sku, int $quantity, $customer = null)
{
$customerId = $customer->id;
$customerId = $customer->id ?? 0;
$productId = $sku->product_id;
$skuId = $sku->id;
if (empty($sku)) {
throw new \Exception("无效的SKU ID");
}
$cart = Cart::query()
->where('customer_id', $customerId)
->where('product_id', $productId)