From 2f4aed39227fa596c59e9fdd04dde6efee792866 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 29 Jun 2022 08:56:40 +0800 Subject: [PATCH] wip --- beike/Shop/Services/CartService.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/beike/Shop/Services/CartService.php b/beike/Shop/Services/CartService.php index f3ef72a1..86f6798a 100644 --- a/beike/Shop/Services/CartService.php +++ b/beike/Shop/Services/CartService.php @@ -100,7 +100,7 @@ class CartService } Cart::query()->where('customer_id', $customer->id) ->where('id', $cartId) - ->update(['quantity' => $quantity]); + ->update(['quantity' => $quantity, 'selected' => 1]); } @@ -126,10 +126,12 @@ class CartService if (empty($carts)) { $carts = CartService::list(current_customer()); } - $amount = collect($carts)->sum('subtotal'); + $selected = collect($carts)->where('selected', 1); + $quantity = $selected->sum('quantity'); + $amount = $selected->sum('subtotal'); $data = [ 'carts' => $carts, - 'quantity' => collect($carts)->sum('quantity'), + 'quantity' => $quantity, 'amount' => $amount, 'amount_format' => currency_format($amount) ];