feat: create ProductService to handle product, variant, and attribute lifecycle management
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user