From d8e5ac0b5e38bd87dad824f5262c66a7c99d856f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Wed, 15 Dec 2021 20:00:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resources/ShoppingCartItemResource.php | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php b/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php index 3d39c90f..0087c180 100644 --- a/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php +++ b/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php @@ -2,6 +2,7 @@ namespace App\Endpoint\Api\Http\Resources; +use App\Endpoint\Api\Http\Resources\ProductSku\ProductSkuSimpleResource; use Illuminate\Http\Resources\Json\JsonResource; class ShoppingCartItemResource extends JsonResource @@ -16,27 +17,22 @@ class ShoppingCartItemResource extends JsonResource { return [ 'id' => $this->id, - 'sku' => $this->when($this->relationLoaded('sku') && $this->sku, function () { + 'sku' => $this->when($this->relationLoaded('sku'), function () { + if ($this->sku) { + return ProductSkuSimpleResource::make($this->sku); + } + return [ - 'id' => $this->sku->id, - 'name' => $this->sku->name, - 'cover' => (string) $this->sku->cover, - 'sell_price' => $this->sku->sell_price, - 'vip_price' => (string) $this->sku->vip_price, - 'specs' => array_values((array) $this->sku->specs), - 'stock' => (int) $this->sku->saleable_stock, - 'is_online' => $this->sku->isOnline(), + 'id' => $this->id, + 'name' => $this->name, + 'cover' => (string) $this->cover, + 'sell_price' => $this->sell_price, + 'vip_price' => (string) $this->vip_price, + 'specs' => array_values((array) $this->specs), + 'stock' => 0, + 'is_online' => false, ]; - }, [ - 'id' => $this->id, - 'name' => $this->name, - 'cover' => (string) $this->cover, - 'sell_price' => $this->sell_price, - 'vip_price' => (string) $this->vip_price, - 'specs' => array_values((array) $this->specs), - 'stock' => 0, - 'is_online' => false, - ]), + }), 'quantity' => $this->quantity, ]; }