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

29 lines
828 B
PHP
Raw Normal View History

2022-11-17 07:29:01 +00:00
<?php
namespace Sarga\API\Http\Resources\Checkout;
use Illuminate\Http\Resources\Json\JsonResource;
class CartRuleResource extends JsonResource
{
public function __construct($resource,$currency){
parent::__construct($resource);
$this->currency = $currency;
}
public function toArray($request): array
{
2022-11-17 11:08:28 +00:00
$is_fixed = str_contains($this->action_type,'fixed');
2022-11-17 07:29:01 +00:00
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
2022-11-17 11:08:28 +00:00
'is_fixed' => $is_fixed,
2022-11-26 05:05:38 +00:00
'is_discount' => $this->discount_amount >0,
2022-11-17 11:14:38 +00:00
'amount' => abs($is_fixed ?
2022-11-17 11:08:28 +00:00
core()->convertPrice($this->discount_amount, $this->currency):
$this->discount_amount)
2022-11-17 07:29:01 +00:00
];
}
}