Optimize cart list.
This commit is contained in:
parent
43f6fdbb40
commit
d935eb4ff3
|
|
@ -18,6 +18,8 @@ use Exception;
|
||||||
|
|
||||||
class CartService
|
class CartService
|
||||||
{
|
{
|
||||||
|
private static $cartList = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取购物车商品列表
|
* 获取购物车商品列表
|
||||||
*
|
*
|
||||||
|
|
@ -27,6 +29,10 @@ class CartService
|
||||||
*/
|
*/
|
||||||
public static function list($customer, bool $selected = false): array
|
public static function list($customer, bool $selected = false): array
|
||||||
{
|
{
|
||||||
|
if (self::$cartList !== null) {
|
||||||
|
return self::$cartList;
|
||||||
|
}
|
||||||
|
|
||||||
$cartBuilder = CartRepo::allCartProductsBuilder($customer->id ?? 0);
|
$cartBuilder = CartRepo::allCartProductsBuilder($customer->id ?? 0);
|
||||||
if ($selected) {
|
if ($selected) {
|
||||||
$cartBuilder->where('selected', true);
|
$cartBuilder->where('selected', true);
|
||||||
|
|
@ -52,7 +58,7 @@ class CartService
|
||||||
|
|
||||||
$cartList = CartDetail::collection($cartItems)->jsonSerialize();
|
$cartList = CartDetail::collection($cartItems)->jsonSerialize();
|
||||||
|
|
||||||
return hook_filter('service.cart.list', $cartList);
|
return self::$cartList = hook_filter('service.cart.list', $cartList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue