wip
This commit is contained in:
36
app/Http/Resources/Api/V1/Order/OrderIndexResource.php
Normal file
36
app/Http/Resources/Api/V1/Order/OrderIndexResource.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\V1\Order;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Shipping\OrderShipping;
|
||||
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderIndexResource 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' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'notes' => $this->notes,
|
||||
'customer_name' => $this->customer_name,
|
||||
'customer_phone' => $this->customer_phone,
|
||||
'customer_address' => $this->customer_address,
|
||||
'delivery_time' => $this->delivery_time,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
'region' => $this->region,
|
||||
'user_id' => $this->user_id,
|
||||
'province_id' => $this->province_id,
|
||||
'payment_type' => $this->paymentType?->name,
|
||||
'orderItems' => OrderItemResource::collection($this->whenLoaded('items')),
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Resources/Api/V1/Order/OrderItemResource.php
Normal file
33
app/Http/Resources/Api/V1/Order/OrderItemResource.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\V1\Order;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderItemResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'product' => [
|
||||
'id' => $this->product_id,
|
||||
'name' => $this->product->name,
|
||||
'thumbnail' => $this->product->thumbnail(),
|
||||
'images_400x400' => $this->product->getFirstMediaUrl('uploads', 'thumb400x400'),
|
||||
'images_800x800' => $this->product->getFirstMediaUrl('uploads', 'thumb800x800'),
|
||||
'images_1200x1200' => $this->product->getFirstMediaUrl('uploads', 'thumb1200x1200'),
|
||||
],
|
||||
'order' => [
|
||||
'id' => $this->order_id,
|
||||
],
|
||||
'quantity' => $this->quantity,
|
||||
'unit_price_amount' => $this->unit_price_amount,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user