Viewing File: /home/ubuntu/vedadeals-backend-base/app/Http/Resources/ProductPreviewResource.php
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Cache;
class ProductPreviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$user_wishlist_product_ids = $user_cart_product_ids = [];
if($request->id) {
$user_wishlist_product_ids = Cache::get("user_wishlists_$request->id") ? : [];
$user_cart_product_ids = Cache::get("user_carts_$request->id") ? : [];
}
$sub_days = strtotime(now()->subDays(15)->format('Y-m-d H:i:s'));
return [
'product_id' => $this->product_id,
'product_unique_id' => $this->product_unique_id,
'name' => $this->name,
'file' => $this->file,
'original_price_formatted' => formatted_amount($this->original_price),
'discount_price_formatted' => formatted_amount($this->discount_price),
'selling_price_formatted' => formatted_amount($this->price),
'discount_tag' => $this->discount_price ? formatted_discount($this->discount->discount_type, $this->discount->discount) : '',
'is_wishlisted' => in_array($this->id, $user_wishlist_product_ids) ? YES : NO,
'is_carted' => in_array($this->id, $user_cart_product_ids) ? YES : NO,
'category_name' => $this->category->name,
'gross_weight_formatted' => $this->gross_weight.' '.$this->unit,
'thc_drug_content' => $this->thc_drug_content,
'cbd_drug_content' => $this->cbd_drug_content,
'is_new' => strtotime($this->created_at) > $sub_days ? YES : NO,
];
}
}
Back to Directory
File Manager