This commit is contained in:
2025-09-25 03:03:31 +05:00
commit ae480cf2f6
2768 changed files with 1485826 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources\Attribute;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductAttributeProductShowResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request): array
{
return [
'attribute_id' => $this->attribute->id,
'name' => $this->attribute->name,
'value' => $this->values->map(fn ($val) => $val->real_value)->first(),
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources\Attribute;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductAttributeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'attribute_id' => $this->attribute->id,
'name' => $this->attribute->name,
'value' => $this->values->map(fn ($val) => $val->real_value)->first(),
];
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources;
use App\Http\Resources\MediaResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductIndexResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request): array
{
$reviews = $this->whenLoaded('reviews');
return [
'id' => $this->id,
'parent_id' => $this->parent_id,
'name' => $this->name,
'slug' => $this->slug,
'description' => '',
'sku' => $this->sku,
'barcode' => $this->barcode,
'stock' => $this->stock,
'price_amount' => $this->price_amount,
'old_price_amount' => $this->old_price_amount,
'backorder' => $this->backorder,
'weight_value' => $this->weight_value,
'weight_unit' => $this->weight_unit,
'height_value' => $this->height_value,
'height_unit' => $this->height_unit,
'media' => MediaResource::collection($this->whenLoaded('media')),
'created_at' => $this->created_at,
'seo_title' => $this->seo_title,
'seo_description' => $this->seo_description,
'colour' => PropertyRepository::getRealValue('colour', $this->colour),
'size' => PropertyRepository::getRealValue('size', $this->size),
'brand' => [
'id' => $this->brand_id,
'name' => $this->brand?->name,
],
'reviews' => [
'count' => $reviews ? $reviews->count() : 0,
'rating' => $reviews ? number_format($reviews->avg('rating'), 2) : 0,
],
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductMediaResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'thumbnail' => $this->getUrl('thumb288x431'),
'images_400x400' => $this->getUrl('thumb400x400'),
'images_720x720' => $this->getUrl('thumb720x720'),
'images_800x800' => $this->getUrl('thumb800x800'),
'images_1200x1200' => $this->getUrl('thumb1200x1200'),
];
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources;
use App\Http\Controllers\Api\V1\Product\Resources\Attribute\ProductAttributeProductShowResource;
use App\Http\Controllers\Api\V1\Product\Resources\Variant\ProductVariantResource;
use App\Http\Resources\Api\V1\Channel\ChannelResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request): array
{
$media = $this->whenLoaded('media');
$reviews = $this->whenLoaded('reviews');
$reviewsLoaded = get_class($reviews) !== 'Illuminate\\Http\\Resources\\MissingValue';
return [
'id' => $this->id,
'parent_id' => $this->parent_id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'sku' => $this->sku,
'barcode' => $this->barcode,
'stock' => $this->stock,
'price_amount' => $this->price_amount,
'old_price_amount' => $this->old_price_amount,
'backorder' => $this->backorder,
'weight_value' => $this->weight_value,
'weight_unit' => $this->weight_unit,
'height_value' => $this->height_value,
'height_unit' => $this->height_unit,
'media' => ProductMediaResource::collection($media),
'created_at' => $this->created_at,
'seo_title' => $this->seo_title,
'seo_description' => $this->seo_description,
'is_visible' => $this->is_visible,
'colour' => PropertyRepository::getRealValue('colour', $this->colour),
'size' => PropertyRepository::getRealValue('size', $this->size),
'brand' => [
'id' => $this->brand_id,
'name' => $this->brand?->name,
],
'channel' => ChannelResource::collection($this->whenLoaded('channels')),
'properties' => ProductAttributeProductShowResource::collection($this->whenLoaded('properties')),
'variations' => ProductVariantResource::collection($this->whenLoaded('variations')),
'reviews' => [
'count' => $reviewsLoaded ? $reviews->count() : 0,
'rating' => $reviewsLoaded ? number_format($reviews->avg('rating'), 2) : '',
],
];
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources;
use App\Http\Controllers\Api\V1\Product\Resources\Attribute\ProductAttributeProductShowResource;
use App\Http\Controllers\Api\V1\Product\Resources\Review\ProductReviewResource;
use App\Http\Controllers\Api\V1\Product\Resources\Variant\ProductVariantResource;
use App\Http\Resources\Api\V1\Channel\ChannelResource;
use App\Http\Resources\MediaResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductShowResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request): array
{
$reviews = $this->whenLoaded('reviews');
$categories = $this->whenLoaded('categories');
return [
'id' => $this->id,
'parent_id' => $this->parent_id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'sku' => $this->sku,
'barcode' => $this->barcode,
'stock' => $this->stock,
'price_amount' => $this->price_amount,
'old_price_amount' => $this->old_price_amount,
'backorder' => $this->backorder ? 'true' : 'false',
'weight_value' => $this->weight_value,
'weight_unit' => $this->weight_unit,
'height_value' => $this->height_value,
'height_unit' => $this->height_unit,
'media' => MediaResource::collection($this->whenLoaded('media')),
'created_at' => $this->created_at,
'seo_title' => $this->seo_title,
'seo_description' => $this->seo_description,
'colour' => PropertyRepository::getRealValue('colour', $this->colour),
'size' => PropertyRepository::getRealValue('size', $this->size),
'available_colors' => PropertyRepository::getAvailableColors($this),
'available_sizes' => PropertyRepository::getAvailableSizes($this),
'brand' => [
'id' => $this->brand_id,
'name' => $this->brand?->name,
],
'channel' => ChannelResource::collection($this->whenLoaded('channels')),
'properties' => ProductAttributeProductShowResource::collection($this->whenLoaded('properties')),
'variations' => ProductVariantResource::collection($this->whenLoaded('variations')),
'reviews' => [
'count' => $reviews ? $reviews->count() : 0,
'rating' => $reviews ? number_format($reviews->avg('rating'), 2) : 0,
],
'reviews_resources' => ProductReviewResource::collection($this->whenLoaded('reviews')),
$this->mergeWhen($categories, [
'categories' => $categories->map(fn ($category) => [
'id' => $category->id,
'name' => $category->name,
]),
]),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources\Review;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductReviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'product_id' => $this->product_id,
'rating' => $this->rating,
'title' => $this->title,
'content' => $this->content,
'is_recommended' => $this->is_recommended,
'source' => $this->source,
];
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Http\Controllers\Api\V1\Product\Resources\Variant;
use App\Http\Controllers\Api\V1\Product\Resources\Attribute\ProductAttributeResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductVariantResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'parent_id' => $this->parent_id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'sku' => $this->sku,
'barcode' => $this->barcode,
'stock' => $this->stock,
'cost_amount' => $this->cost_amount,
'price_amount' => $this->price_amount,
'old_price_amount' => $this->old_price_amount,
'backorder' => $this->backorder,
'weight_value' => $this->weight_value,
'weight_unit' => $this->weight_unit,
'height_value' => $this->height_value,
'height_unit' => $this->height_unit,
'colour' => PropertyRepository::getRealValue('colour', $this->colour),
'size' => PropertyRepository::getRealValue('size', $this->size),
'thumbnail' => $this->thumbnail(),
'images_400x400' => $this->getMedia('uploads')->map(fn ($media) => $media->getUrl('thumb400x400')),
'images_800x800' => $this->getMedia('uploads')->map(fn ($media) => $media->getUrl('thumb800x800')),
'images_1200x1200' => $this->getMedia('uploads')->map(fn ($media) => $media->getUrl('thumb1200x1200')),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'properties' => ProductAttributeResource::collection($this->whenLoaded('properties')),
];
}
}