fixed quantity 0

This commit is contained in:
Edward Yang 2022-06-29 14:15:09 +08:00
parent 33a887c5f2
commit c0603b0bb1
2 changed files with 4 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class CartController extends Controller
public function update(Request $request, $cartId): array
{
$customer = current_customer();
$quantity = $request->get('quantity');
$quantity = (int)$request->get('quantity');
CartService::updateQuantity($customer, $cartId, $quantity);
return CartService::reloadData();

View File

@ -48,8 +48,8 @@ class CartService
$productId = $sku->product_id;
$skuId = $sku->id;
if (empty($sku)) {
throw new Exception("无效的SKU ID");
if (empty($sku) || $quantity == 0) {
return null;
}
$cart = Cart::query()
->where('customer_id', $customerId)
@ -96,7 +96,7 @@ class CartService
*/
public static function updateQuantity($customer, $cartId, $quantity)
{
if (empty($cartId)) {
if (empty($cartId) || $quantity == 0) {
return;
}
Cart::query()->where('customer_id', $customer->id)