fixed cart

This commit is contained in:
Edward Yang 2022-06-28 18:39:27 +08:00
parent f9d86bdaf5
commit ed40c22072
2 changed files with 6 additions and 1 deletions

View File

@ -18,10 +18,12 @@ class CartList extends JsonResource
{
$sku = $this->sku;
$price = $sku->price;
$description = $sku->product->description;
$subTotal = $price * $this->quantity;
return [
'product_id' => $this->product_id,
'sku_id' => $this->product_sku_id,
'name' => $description->name,
'image' => image_resize($sku->image),
'price' => $price,
'price_format' => currency_format($price),

View File

@ -21,7 +21,10 @@ class CartService
if (empty($customer)) {
return [];
}
$cartItems = Cart::query()->where('customer_id', $customer->id)->get();
$cartItems = Cart::query()
->with(['sku.product.description'])
->where('customer_id', $customer->id)
->get();
$cartList = CartList::collection($cartItems)->jsonSerialize();
return $cartList;
}