优化购物车商品数据结构
parent
166b260d2c
commit
d8e5ac0b5e
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue