feat: implement product management module with CRUD operations, service layer, and validation logic

This commit is contained in:
2026-06-30 09:50:40 -03:00
parent f664fbe2dc
commit 72261bf422
5 changed files with 125 additions and 8 deletions

View File

@@ -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(),
];
}
),
];
}
}