mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-15 11:07:53 -04:00
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\StudioPlus\Transformers;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class AmazonASINResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$product = $this;
|
|
$title = Arr::first(explode(',', $product['title']));
|
|
$brand = Arr::get($product, 'brand') ?? null;
|
|
|
|
if (Str::startsWith($brand, 'Visit the')) {
|
|
$newBrand = Str::replace('Visit the', '', $brand);
|
|
}
|
|
|
|
if (Str::startsWith($brand, 'Brand:')) {
|
|
$newBrand = Str::replace('Brand:', '', $brand);
|
|
}
|
|
|
|
return [
|
|
'product_name' => $title ?? null,
|
|
'studio_plus_category_id' => $product['category_id'] ?? null,
|
|
'amazon_total_reviews' => Arr::get($product, 'amazon_total_reviews') ?? null,
|
|
'price' => Arr::get($product, 'price', 0),
|
|
'brand' => $newBrand ?? $brand,
|
|
'amazon_url' => null,
|
|
'exists' => $this['exists']
|
|
];
|
|
}
|
|
}
|