HOME


Mini Shell 1.0
La Pieza.DO | Todo lo que buscas!

Bienvenido de nuevo!

Acceso Cuenta Delivery
DIR: /var/www/devs.lapieza.net/app/Http/Resources/V2/Seller/
Upload File :
Current File : /var/www/devs.lapieza.net/app/Http/Resources/V2/Seller/OrderDetailResource.php
<?php
namespace App\Http\Resources\V2\Seller;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderDetailResource extends JsonResource {
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request) {
        if (is_null($this->shipping_addres)) {
            $shipping_address = json_decode($this->shop->user->addresses()->default()->first());
        } else {
            $shipping_address = json_decode($this->shipping_address);
        }

        $shipping_type = 'En Tienda'; // Default value
        if (!empty($this->shipping_type)) {
            if (in_array($this->shipping_type, ['PY + TB', 'TB + PY'])) $shipping_type = 'TRANSPORTE BLANCO';
            else $shipping_type = $this->shipping_type;
        }



        return [
            'order_code' => $this->code,
            'total' => format_price($this->grand_total),
            'order_date' => date('d-m-Y', strtotime($this->created_at)),
            'payment_status' => translate($this->payment_status),
            'payment_type' => translate(ucwords(str_replace('_', ' ', $this->payment_type))),
            'delivery_status' => translate($this->delivery_status),
            'shipping_type' => $shipping_type,
            'payment_method' => translate($this->payment_type),
            'shipping_address' => $shipping_address,
            'shipping_cost' => format_price($this->orderDetails->sum('shipping_cost')),
            'subtotal' => format_price($this->orderDetails->sum('price')),
            'coupon_discount' => format_price($this->coupon_discount),
            'tax' => format_price($this->orderDetails->sum('tax')),
            'order_items' => OrderItemResource::collection($this->orderDetails)
        ];
    }
}