sarga/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php

44 lines
2.2 KiB
PHP
Raw Normal View History

2022-02-08 10:32:33 +00:00
<?php
namespace Sarga\API\Http\Resources\Checkout;
use Illuminate\Http\Resources\Json\JsonResource;
use Sarga\API\Http\Resources\Catalog\Product as ProductResource;
2022-02-08 13:07:26 +00:00
use Webkul\Marketplace\Repositories\ProductRepository;
2022-02-08 10:32:33 +00:00
class CartItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'quantity' => $this->quantity,
'name' => $this->name,
'base_total_weight' => $this->base_total_weight,
'price' => $this->price,
2022-03-02 13:10:22 +00:00
'formatted_price' => core()->formatPrice($this->base_price, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'custom_price' => $this->custom_price,
'formatted_custom_price' => core()->formatPrice($this->custom_price, $this->cart->cart_currency_code),
'total' => $this->total,
2022-03-02 13:10:22 +00:00
'formatted_total' => core()->formatPrice($this->base_total, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'tax_percent' => $this->tax_percent,
'tax_amount' => $this->tax_amount,
2022-03-02 13:10:22 +00:00
'formatted_tax_amount' => core()->formatPrice($this->base_tax_amount, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'discount_percent' => $this->discount_percent,
'discount_amount' => $this->discount_amount,
2022-03-02 13:10:22 +00:00
'formatted_discount_amount' => core()->formatPrice($this->base_discount_amount, $this->cart->cart_currency_code),
2022-02-08 10:32:33 +00:00
'additional' => is_array($this->resource->additional)
? $this->resource->additional
: json_decode($this->resource->additional, true),
'child' => new self($this->child),
2022-02-28 12:06:42 +00:00
'product' => $this->when($this->product_id, new CartItemProduct($this->product)),
2022-02-08 10:32:33 +00:00
];
}
}