feat: implement product management module with CRUD operations, service layer, and validation logic
This commit is contained in:
@@ -32,6 +32,22 @@ class ProductResource extends JsonResource
|
||||
->values()
|
||||
),
|
||||
'attributes' => AttributeResource::collection($this->whenLoaded('attributes')),
|
||||
'variants' => ProductVariantResource::collection($this->whenLoaded('variants')),
|
||||
'default_variant' => $this->when(
|
||||
$this->getDefaultVariant() !== null,
|
||||
function () {
|
||||
$defaultVariant = $this->getDefaultVariant();
|
||||
return [
|
||||
'variant_id' => $defaultVariant->id,
|
||||
'images' => $defaultVariant->attachments->isNotEmpty()
|
||||
? $defaultVariant->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values()
|
||||
: $this->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values(),
|
||||
'attributes' => $defaultVariant->definitions->mapWithKeys(function ($definition) {
|
||||
return [$definition->attribute?->codigo => $definition->value];
|
||||
})->toArray(),
|
||||
];
|
||||
}
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user