64 lines
3.6 KiB
PHP
64 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Sarga\API\Http\Resources\Customer;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Sarga\API\Http\Resources\Catalog\Product;
|
|
use Sarga\API\Http\Resources\Checkout\CartItemProduct;
|
|
|
|
class OrderItemResource extends JsonResource
|
|
{
|
|
/**
|
|
* 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,
|
|
'product' => $this->when($this->product_id, new CartItemProduct($this->child->product ?? $this->product)),
|
|
'coupon_code' => $this->coupon_code,
|
|
'weight' => (double) $this->weight,
|
|
'total_weight' => (double) $this->total_weight,
|
|
'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,
|
|
'formatted_price' => core()->formatBasePrice($this->price),
|
|
'total' => (double) $this->total,
|
|
'formatted_total' => core()->formatBasePrice($this->total),
|
|
|
|
'total_invoiced' => (double) $this->total_invoiced,
|
|
'formatted_total_invoiced' => core()->formatBasePrice($this->total_invoiced, $this->order->order_currency_code),
|
|
|
|
'amount_refunded' => (double) $this->amount_refunded,
|
|
'formatted_amount_refunded' => core()->formatBasePrice($this->amount_refunded, $this->order->order_currency_code),
|
|
|
|
'discount_percent' => (double) $this->discount_percent,
|
|
'discount_amount' => (double) $this->discount_amount,
|
|
'formatted_discount_amount' => core()->formatBasePrice($this->base_discount_amount, $this->order->order_currency_code),
|
|
|
|
'discount_invoiced' => (double) $this->discount_invoiced,
|
|
'formatted_discount_invoiced' => core()->formatBasePrice($this->discount_invoiced, $this->order->order_currency_code),
|
|
|
|
'discount_refunded' => (double) $this->discount_refunded,
|
|
'formatted_discount_refunded' => core()->formatBasePrice($this->discount_refunded, $this->order->order_currency_code),
|
|
|
|
'grant_total' => $this->total + $this->tax_amount,
|
|
'formatted_grant_total' => core()->formatBasePrice($this->total + $this->tax_amount, $this->order->order_currency_code),
|
|
// 'downloadable_links' => $this->downloadable_link_purchased,
|
|
// 'additional' => is_array($this->resource->additional)
|
|
// ? $this->resource->additional
|
|
// : json_decode($this->resource->additional, true),
|
|
'main_product' => new Product($this->product),
|
|
// 'children' => Self::collection($this->children),
|
|
];
|
|
}
|
|
} |