fixed quantity 0
This commit is contained in:
parent
33a887c5f2
commit
c0603b0bb1
|
|
@ -43,7 +43,7 @@ class CartController extends Controller
|
||||||
public function update(Request $request, $cartId): array
|
public function update(Request $request, $cartId): array
|
||||||
{
|
{
|
||||||
$customer = current_customer();
|
$customer = current_customer();
|
||||||
$quantity = $request->get('quantity');
|
$quantity = (int)$request->get('quantity');
|
||||||
CartService::updateQuantity($customer, $cartId, $quantity);
|
CartService::updateQuantity($customer, $cartId, $quantity);
|
||||||
|
|
||||||
return CartService::reloadData();
|
return CartService::reloadData();
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ class CartService
|
||||||
$productId = $sku->product_id;
|
$productId = $sku->product_id;
|
||||||
$skuId = $sku->id;
|
$skuId = $sku->id;
|
||||||
|
|
||||||
if (empty($sku)) {
|
if (empty($sku) || $quantity == 0) {
|
||||||
throw new Exception("无效的SKU ID");
|
return null;
|
||||||
}
|
}
|
||||||
$cart = Cart::query()
|
$cart = Cart::query()
|
||||||
->where('customer_id', $customerId)
|
->where('customer_id', $customerId)
|
||||||
|
|
@ -96,7 +96,7 @@ class CartService
|
||||||
*/
|
*/
|
||||||
public static function updateQuantity($customer, $cartId, $quantity)
|
public static function updateQuantity($customer, $cartId, $quantity)
|
||||||
{
|
{
|
||||||
if (empty($cartId)) {
|
if (empty($cartId) || $quantity == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cart::query()->where('customer_id', $customer->id)
|
Cart::query()->where('customer_id', $customer->id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue