39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Entrepreneur\Resources\Order;
|
|
|
|
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class OrderShowResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'status' => OrderStatus::formattedStatusFor($this->status),
|
|
'shipping_method' => $this->formattedShippingMethod(),
|
|
'notes' => $this->notes,
|
|
'delivery_time' => $this->delivery_time,
|
|
'delivery_at' => $this->delivery_at,
|
|
'region' => $this->region,
|
|
'payment_type' => $this->paymentType?->name,
|
|
'products' => $this->items->map(fn ($item) => [
|
|
'quantity' => $item->quantity,
|
|
'product' => [
|
|
'id' => $item->product->id,
|
|
'name' => $item->product->name,
|
|
'price_amount' => $item->product->price_amount,
|
|
'thumbnail' => $item->product->thumbnail('thumb150x150'),
|
|
],
|
|
]),
|
|
];
|
|
}
|
|
}
|