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

92 lines
5.4 KiB
PHP
Raw Normal View History

2022-03-09 10:39:22 +00:00
<?php
namespace Sarga\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
2022-03-09 12:34:01 +00:00
2022-03-09 10:39:22 +00:00
use Webkul\RestApi\Http\Resources\V1\Admin\Sale\InvoiceResource;
use Webkul\RestApi\Http\Resources\V1\Admin\Sale\OrderAddressResource;
use Webkul\RestApi\Http\Resources\V1\Admin\Sale\ShipmentResource;
class OrderResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request){
return [
'id' => $this->id,
'increment_id' => $this->increment_id,
'status' => $this->status,
'status_label' => $this->status_label,
'customer_first_name' => $this->customer_first_name,
'customer_last_name' => $this->customer_last_name,
'shipping_method' => $this->shipping_method,
'shipping_title' => $this->shipping_title,
'payment_title' => core()->getConfigData('sales.paymentmethods.' . $this->payment->method . '.title'),
'shipping_description' => $this->shipping_description,
'coupon_code' => $this->coupon_code,
'is_gift' => $this->is_gift,
'total_item_count' => (int)$this->total_item_count,
'total_qty_ordered' => (int)$this->total_qty_ordered,
'base_currency_code' => $this->base_currency_code,
'channel_currency_code' => $this->channel_currency_code,
'order_currency_code' => $this->order_currency_code,
'grand_total' => (double)$this->grand_total,
2022-03-09 12:34:01 +00:00
'formated_grand_total' => core()->formatPrice($this->base_grand_total, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'grand_total_invoiced' => (double)$this->grand_total_invoiced,
2022-03-09 12:34:01 +00:00
'formated_grand_total_invoiced' => core()->formatPrice($this->base_grand_total_invoiced, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'grand_total_refunded' => (double)$this->grand_total_refunded,
2022-03-09 12:34:01 +00:00
'formated_grand_total_refunded' => core()->formatPrice($this->base_grand_total_refunded, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'sub_total' => (double)$this->sub_total,
2022-03-09 12:34:01 +00:00
'formated_sub_total' => core()->formatPrice($this->base_sub_total, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'sub_total_invoiced' => (double)$this->sub_total_invoiced,
2022-03-09 12:34:01 +00:00
'formated_sub_total_invoiced' => core()->formatPrice($this->base_sub_total_invoiced, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'sub_total_refunded' => (double)$this->sub_total_refunded,
2022-03-09 12:34:01 +00:00
// 'formated_sub_total_refunded' => core()->formatPrice($this->sub_total_refunded, $this->order_currency_code),
'discount_percent' => $this->discount_percent,
2022-03-09 10:39:22 +00:00
'discount_amount' => (double)$this->discount_amount,
2022-03-09 12:34:01 +00:00
'formated_discount_amount' => core()->formatPrice($this->base_discount_amount, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'discount_invoiced' => (double)$this->discount_invoiced,
2022-03-09 12:34:01 +00:00
'formated_discount_invoiced' => core()->formatPrice($this->base_discount_invoiced, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'discount_refunded' => (double)$this->discount_refunded,
2022-03-09 12:34:01 +00:00
'formated_discount_refunded' => core()->formatPrice($this->base_discount_refunded, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'shipping_amount' => (double)$this->shipping_amount,
2022-03-09 12:34:01 +00:00
'formated_shipping_amount' => core()->formatPrice($this->base_shipping_amount, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'shipping_invoiced' => $this->shipping_invoiced,
2022-03-09 12:34:01 +00:00
'formated_shipping_invoiced' => core()->formatPrice($this->base_shipping_invoiced, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'shipping_refunded' => $this->shipping_refunded,
2022-03-09 12:34:01 +00:00
'formated_shipping_refunded' => core()->formatPrice($this->base_shipping_refunded, $this->order_currency_code),
2022-03-09 10:39:22 +00:00
'shipping_address' => new OrderAddressResource($this->shipping_address),
'billing_address' => new OrderAddressResource($this->billing_address),
2022-03-09 12:34:01 +00:00
'vendors' => $this->groupByVendors($this->items),
2022-03-09 10:39:22 +00:00
'invoices' => InvoiceResource::collection($this->invoices),
'shipments' => ShipmentResource::collection($this->shipments),
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
];
}
2022-03-09 12:34:01 +00:00
private function groupByVendors($items){
$data = array();
foreach($items as $item){
$seller = $this->sellerProductRepository->getSellerByProductId($item->product_id);
$data[$seller->shop_title ?? 'outlet'][] = OrderItemResource::make($item);
}
return $data;
}
2022-03-09 10:39:22 +00:00
}