diff --git a/backend/app/services/design_service.py b/backend/app/services/design_service.py index 834ad3d..eb1029c 100644 --- a/backend/app/services/design_service.py +++ b/backend/app/services/design_service.py @@ -170,42 +170,58 @@ class DesignService: products = [] for design in designs: - for dp in design.products: - # Filter by product type if specified - if product_type and dp.type != product_type: - continue + # Skip designs with no products + if not design.products: + continue - variants = [ - ProductVariant( - name=v, - sku=f"{dp.sku}-{v}", - 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, - ) - ] + # Filter by product type if specified + matching_products = [ + dp for dp in design.products + if not product_type or dp.type == product_type + ] - products.append( - Product( - slug=design.slug, - name=design.name, - description=design.description, - category=design.category, - product_type=dp.type, - tags=design.tags, - image_url=design.image_url, - base_price=dp.retail_price, - variants=variants, - is_active=True, + 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( + Product( + slug=design.slug, + name=design.name, + description=design.description, + category=design.category, + product_type=dp.type, + tags=design.tags, + image_url=design.image_url, + base_price=dp.retail_price, + variants=all_variants, + is_active=True, ) + ) return products