From 0a5518d80173e3020db3de1d4753c9ce1bd69e2b Mon Sep 17 00:00:00 2001 From: mengwb Date: Tue, 6 Jun 2023 00:43:20 +0000 Subject: [PATCH] =?UTF-8?q?!116=20=E7=BB=93=E8=B4=A6hook=20*=20Optimize=20?= =?UTF-8?q?cart=20list.=20*=20=E7=BB=93=E8=B4=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Shop/Services/CheckoutService.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index 5282a7dd..3941fe9c 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -94,8 +94,8 @@ class CheckoutService $this->updateGuestPaymentAddress($guestPaymentAddress); } - $data = $this->checkoutData(); hook_action('service.checkout.update.after', ['request_data' => $requestData, 'checkout' => $this]); + $data = $this->checkoutData(); return $data; } @@ -218,6 +218,14 @@ class CheckoutService $this->cart->update(['payment_method_code' => $paymentMethodCode]); } + public function initTotalService() + { + $customer = $this->customer; + $totalClass = hook_filter('service.checkout.total_service', 'Beike\Shop\Services\TotalService'); + $totalService = (new $totalClass($this->cart, CartService::list($customer, true))); + $this->totalService = $totalService; + } + /** * 获取结账页数据 * @@ -231,9 +239,10 @@ class CheckoutService $cartList = CartService::list($customer, true); $carts = CartService::reloadData($cartList); - $totalClass = hook_filter('service.checkout.total_service', 'Beike\Shop\Services\TotalService'); - $totalService = (new $totalClass($currentCart, $cartList)); - $this->totalService = $totalService; + + if (!$this->totalService) { + $this->initTotalService(); + } $addresses = AddressRepo::listByCustomer($customer); $shipments = ShippingMethodService::getShippingMethods($this); @@ -265,7 +274,7 @@ class CheckoutService 'shipping_methods' => $shipments, 'payment_methods' => $payments, 'carts' => $carts, - 'totals' => $totalService->getTotals($this), + 'totals' => $this->totalService->getTotals($this), ]; return hook_filter('service.checkout.data', $data);