feat: create ProductService to handle product, variant, and attribute lifecycle management

This commit is contained in:
ncoronel 2026-07-01 10:22:02 -03:00
parent a0a0cc7255
commit 67c2a7350e
1 changed files with 5 additions and 7 deletions

View File

@ -122,13 +122,11 @@ class ProductService
$isPlaceholder = $data['is_placeholder'] ?? (! $hasDefinitions);
$data['is_placeholder'] = $isPlaceholder;
// If the variant being created is not a placeholder variant, remove any existing placeholder variants
if (! $isPlaceholder) {
$defaultVariants = $product->variants()->where('is_placeholder', true)->get();
foreach ($defaultVariants as $defaultVariant) {
$this->deleteVariantAttachments($defaultVariant);
$product->deleteVariant($defaultVariant);
}
// Remove any existing placeholder variants
$defaultVariants = $product->variants()->where('is_placeholder', true)->get();
foreach ($defaultVariants as $defaultVariant) {
$this->deleteVariantAttachments($defaultVariant);
$product->deleteVariant($defaultVariant);
}
$variant = $product->createVariant($data);