fix: group products by design to eliminate duplicates
This commit is contained in:
parent
ce77530efc
commit
c10e1fb453
|
|
@ -170,28 +170,44 @@ class DesignService:
|
||||||
products = []
|
products = []
|
||||||
|
|
||||||
for design in designs:
|
for design in designs:
|
||||||
for dp in design.products:
|
# Skip designs with no products
|
||||||
# Filter by product type if specified
|
if not design.products:
|
||||||
if product_type and dp.type != product_type:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
variants = [
|
# Filter by product type if specified
|
||||||
ProductVariant(
|
matching_products = [
|
||||||
name=v,
|
dp for dp in design.products
|
||||||
sku=f"{dp.sku}-{v}",
|
if not product_type or dp.type == product_type
|
||||||
provider=dp.provider,
|
|
||||||
price=dp.retail_price,
|
|
||||||
)
|
|
||||||
for v in dp.variants
|
|
||||||
] if dp.variants else [
|
|
||||||
ProductVariant(
|
|
||||||
name="default",
|
|
||||||
sku=dp.sku,
|
|
||||||
provider=dp.provider,
|
|
||||||
price=dp.retail_price,
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not matching_products:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Use the first matching product for base info, combine all variants
|
||||||
|
dp = matching_products[0]
|
||||||
|
all_variants = []
|
||||||
|
|
||||||
|
for mp in matching_products:
|
||||||
|
if mp.variants:
|
||||||
|
for v in mp.variants:
|
||||||
|
all_variants.append(
|
||||||
|
ProductVariant(
|
||||||
|
name=f"{v} ({mp.provider})",
|
||||||
|
sku=f"{mp.sku}-{v}",
|
||||||
|
provider=mp.provider,
|
||||||
|
price=mp.retail_price,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
all_variants.append(
|
||||||
|
ProductVariant(
|
||||||
|
name=f"default ({mp.provider})",
|
||||||
|
sku=mp.sku,
|
||||||
|
provider=mp.provider,
|
||||||
|
price=mp.retail_price,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
products.append(
|
products.append(
|
||||||
Product(
|
Product(
|
||||||
slug=design.slug,
|
slug=design.slug,
|
||||||
|
|
@ -202,7 +218,7 @@ class DesignService:
|
||||||
tags=design.tags,
|
tags=design.tags,
|
||||||
image_url=design.image_url,
|
image_url=design.image_url,
|
||||||
base_price=dp.retail_price,
|
base_price=dp.retail_price,
|
||||||
variants=variants,
|
variants=all_variants,
|
||||||
is_active=True,
|
is_active=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue