From 67c2a7350e6ee84fe35f2fe606b1e16c238299f4 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 1 Jul 2026 10:22:02 -0300 Subject: [PATCH] feat: create ProductService to handle product, variant, and attribute lifecycle management --- app/Domains/Catalog/Services/ProductService.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Domains/Catalog/Services/ProductService.php b/app/Domains/Catalog/Services/ProductService.php index c4c1832..122a8a9 100644 --- a/app/Domains/Catalog/Services/ProductService.php +++ b/app/Domains/Catalog/Services/ProductService.php @@ -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);