* Optimize cart list.
* 结账优化
This commit is contained in:
mengwb 2023-06-06 00:43:20 +00:00 committed by Edward Yang
parent d935eb4ff3
commit 0a5518d801
1 changed files with 14 additions and 5 deletions

View File

@ -94,8 +94,8 @@ class CheckoutService
$this->updateGuestPaymentAddress($guestPaymentAddress); $this->updateGuestPaymentAddress($guestPaymentAddress);
} }
$data = $this->checkoutData();
hook_action('service.checkout.update.after', ['request_data' => $requestData, 'checkout' => $this]); hook_action('service.checkout.update.after', ['request_data' => $requestData, 'checkout' => $this]);
$data = $this->checkoutData();
return $data; return $data;
} }
@ -218,6 +218,14 @@ class CheckoutService
$this->cart->update(['payment_method_code' => $paymentMethodCode]); $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); $cartList = CartService::list($customer, true);
$carts = CartService::reloadData($cartList); $carts = CartService::reloadData($cartList);
$totalClass = hook_filter('service.checkout.total_service', 'Beike\Shop\Services\TotalService');
$totalService = (new $totalClass($currentCart, $cartList)); if (!$this->totalService) {
$this->totalService = $totalService; $this->initTotalService();
}
$addresses = AddressRepo::listByCustomer($customer); $addresses = AddressRepo::listByCustomer($customer);
$shipments = ShippingMethodService::getShippingMethods($this); $shipments = ShippingMethodService::getShippingMethods($this);
@ -265,7 +274,7 @@ class CheckoutService
'shipping_methods' => $shipments, 'shipping_methods' => $shipments,
'payment_methods' => $payments, 'payment_methods' => $payments,
'carts' => $carts, 'carts' => $carts,
'totals' => $totalService->getTotals($this), 'totals' => $this->totalService->getTotals($this),
]; ];
return hook_filter('service.checkout.data', $data); return hook_filter('service.checkout.data', $data);