61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Models\Product;
|
|
|
|
class ProductResource extends JsonResource
|
|
{
|
|
/** @var \App\Models\Product */
|
|
private $product;
|
|
|
|
// FIXME: Add more of the needed lines.
|
|
|
|
/** @var array */
|
|
private $skeleton = [
|
|
'id' => 0,
|
|
'name' => '',
|
|
'priceHt' => 0,
|
|
'priceTtc' => 0,
|
|
'discountAmount' => 0,
|
|
'discountRate' => 0,
|
|
'discountedPriceHt' => 0,
|
|
'discountedPriceTtc' => 0,
|
|
];
|
|
|
|
/**
|
|
* ProductResource
|
|
*
|
|
* @param \App\Models\Product $product
|
|
*/
|
|
public function __construct(Product $product)
|
|
{
|
|
$this->product = $product;
|
|
}
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param mixed $request
|
|
* @return array
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
// phpcs:enable
|
|
return array_intersect_key(
|
|
array_merge(
|
|
[
|
|
'priceHt' => $this->product->priceHt,
|
|
'priceTtc' => $this->product->priceTtc,
|
|
'discountAmount' => $this->product->discountAmount,
|
|
'discountRate' => $this->product->discountRate,
|
|
'discountedPriceHt' => $this->product->discountedPriceHt,
|
|
'discountedPriceTtc' => $this->product->discountedPriceTtc
|
|
],
|
|
$this->product->toArray(),
|
|
),
|
|
$this->skeleton
|
|
);
|
|
}
|
|
}
|