sarga/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php

39 lines
1.8 KiB
PHP
Raw Normal View History

2022-02-08 10:32:33 +00:00
<?php
namespace Sarga\API\Http\Resources\Checkout;
use Illuminate\Http\Resources\Json\JsonResource;
2022-05-30 12:03:39 +00:00
use Sarga\API\Http\Resources\Catalog\Product;
2022-02-08 10:32:33 +00:00
class CartItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
2022-03-09 12:34:01 +00:00
'quantity' => (int)$this->quantity,
2022-02-08 10:32:33 +00:00
'name' => $this->name,
2022-03-09 12:34:01 +00:00
'base_total_weight' => (double)$this->base_total_weight,
'price' => (double)$this->price,
2023-03-24 08:13:05 +00:00
'formatted_price' => core()->formatPrice($this->price, $this->cart->cart_currency_code),
2022-03-09 12:34:01 +00:00
'custom_price' => (double)$this->custom_price,
'total' => (double)$this->total,
2023-03-24 08:13:05 +00:00
'formatted_total' => core()->formatPrice($this->total, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'discount_percent' => $this->discount_percent,
2022-03-09 12:34:01 +00:00
'discount_amount' => (double)$this->discount_amount,
2023-03-24 08:13:05 +00:00
'formatted_discount_amount' => core()->formatPrice($this->discount_amount, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'additional' => is_array($this->resource->additional)
? $this->resource->additional
: json_decode($this->resource->additional, true),
2022-06-03 07:14:12 +00:00
'main_product' => $this->when($this->product_id, new Product($this->product)),
2022-05-30 12:03:39 +00:00
'product' => $this->when($this->product_id, new CartItemProduct($this->child->product ?? $this->product)),
2022-02-08 10:32:33 +00:00
];
}
}