sarga/packages/Sarga/API/Http/Resources/Customer/OrderItemResource.php

64 lines
3.6 KiB
PHP
Raw Normal View History

2022-03-09 12:34:01 +00:00
<?php
namespace Sarga\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
2022-05-30 12:03:39 +00:00
use Sarga\API\Http\Resources\Catalog\Product;
2022-03-10 08:24:15 +00:00
use Sarga\API\Http\Resources\Checkout\CartItemProduct;
2022-03-09 12:34:01 +00:00
2022-03-10 08:08:37 +00:00
class OrderItemResource extends JsonResource
2022-03-09 12:34:01 +00:00
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'sku' => $this->sku,
'type' => $this->type,
'name' => $this->name,
2022-05-30 11:20:34 +00:00
'product' => $this->when($this->product_id, new CartItemProduct($this->child->product ?? $this->product)),
2022-03-09 12:34:01 +00:00
'coupon_code' => $this->coupon_code,
'weight' => (double) $this->weight,
2022-03-10 08:53:58 +00:00
'total_weight' => (double) $this->total_weight,
2022-03-09 12:34:01 +00:00
'qty_ordered' => (int) $this->qty_ordered,
'qty_canceled' => (int) $this->qty_canceled,
'qty_invoiced' => (int) $this->qty_invoiced,
'qty_shipped' => (int) $this->qty_shipped,
'qty_refunded' => (int) $this->qty_refunded,
'price' => (double) $this->price,
2023-03-24 08:13:05 +00:00
'formatted_price' => core()->formatPrice($this->price, $this->order->order_currency_code),
2022-03-10 08:29:47 +00:00
'total' => (double) $this->total,
2023-03-24 08:13:05 +00:00
'formatted_total' => core()->formatPrice($this->total, $this->order->order_currency_code),
2022-03-09 12:34:01 +00:00
2022-03-10 08:29:47 +00:00
'total_invoiced' => (double) $this->total_invoiced,
2023-03-24 08:13:05 +00:00
'formatted_total_invoiced' => core()->formatPrice($this->total_invoiced, $this->order->order_currency_code),
2022-03-09 12:34:01 +00:00
2022-03-10 08:29:47 +00:00
'amount_refunded' => (double) $this->amount_refunded,
2023-03-24 08:13:05 +00:00
'formatted_amount_refunded' => core()->formatPrice($this->amount_refunded, $this->order->order_currency_code),
2022-03-09 12:34:01 +00:00
2022-03-10 08:29:47 +00:00
'discount_percent' => (double) $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->order->order_currency_code),
2022-03-09 12:34:01 +00:00
2022-03-10 08:29:47 +00:00
'discount_invoiced' => (double) $this->discount_invoiced,
2023-03-24 08:13:05 +00:00
'formatted_discount_invoiced' => core()->formatPrice($this->discount_invoiced, $this->order->order_currency_code),
2022-03-09 12:34:01 +00:00
2022-03-10 08:29:47 +00:00
'discount_refunded' => (double) $this->discount_refunded,
2023-03-24 08:13:05 +00:00
'formatted_discount_refunded' => core()->formatPrice($this->discount_refunded, $this->order->order_currency_code),
2022-03-09 12:34:01 +00:00
'grant_total' => $this->total + $this->tax_amount,
2023-03-24 08:13:05 +00:00
'formatted_grant_total' => core()->formatPrice($this->total + $this->tax_amount, $this->order->order_currency_code),
2022-05-30 11:20:34 +00:00
// 'downloadable_links' => $this->downloadable_link_purchased,
// 'additional' => is_array($this->resource->additional)
// ? $this->resource->additional
// : json_decode($this->resource->additional, true),
2022-05-30 12:03:39 +00:00
'main_product' => new Product($this->product),
2022-05-30 11:20:34 +00:00
// 'children' => Self::collection($this->children),
2022-03-09 12:34:01 +00:00
];
}
}