From d3d0f0e3ec03dc6261cc23fd9f90d029590504c8 Mon Sep 17 00:00:00 2001 From: prathameshmalode-siyaratech Date: Fri, 21 Nov 2025 22:03:17 +0530 Subject: [PATCH 1/4] Improve style variant image URL generation Refactored create_style_variant to use a color-to-hex mapping and generate image URLs with appropriate background and text colors. This enhances the placeholder image logic, supports more colors, and ensures better text visibility on generated images. --- ls_shop/install_demo_data.py | 94 ++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/ls_shop/install_demo_data.py b/ls_shop/install_demo_data.py index 0da0cf1..c4669dc 100644 --- a/ls_shop/install_demo_data.py +++ b/ls_shop/install_demo_data.py @@ -488,42 +488,64 @@ def create_configurator(template_name, product_data): def create_style_variant(configurator_name, template_name, color, product_data): - """Create Style Attribute Variant for a specific color""" - - # Check if variant exists - existing = frappe.db.get_value( - "Style Attribute Variant", {"configurator": configurator_name, "attribute_value": color}, "name" - ) - - if existing: - print(f" • Style variant '{color}' already exists") - return frappe.get_doc("Style Attribute Variant", existing) - - # Route should NOT include language prefix - hooks.py handles that - route_slug = f"{product_data['code'].lower()}-{color.lower()}" - - variant = frappe.get_doc( - { - "doctype": "Style Attribute Variant", - "configurator": configurator_name, - "item_style": template_name, - "attribute_value": color, - "attribute_name": "Color", - "display_name": f"{product_data['name']} - {color}", - "item_group": product_data["item_group"], - "is_published": 1, - "route": route_slug, - "images": [ - { - "image": f"https://via.placeholder.com/800x800/{'000000' if color == 'Black' else '0000FF' if color == 'Blue' else 'FF0000' if color == 'Red' else 'FFFFFF'}/FFFFFF?text={color}+{product_data['name'].replace(' ', '+')}", - } - ], - } - ) - - variant.insert(ignore_permissions=True) - print(f" ✓ Style variant '{color}' created") - return variant + """Create Style Attribute Variant for a specific color""" + + # Check if variant exists + existing = frappe.db.get_value( + "Style Attribute Variant", {"configurator": configurator_name, "attribute_value": color}, "name" + ) + + if existing: + print(f" • Style variant '{color}' already exists") + return frappe.get_doc("Style Attribute Variant", existing) + + # Route should NOT include language prefix - hooks.py handles that + route_slug = f"{product_data['code'].lower()}-{color.lower()}" + + # Map your color names to Hex codes + color_hex_map = { + "Black": "000000", + "White": "FFFFFF", + "Blue": "0000FF", + "Red": "FF0000", + "Green": "28A745", + "Navy": "000080", + "Gray": "6C757D", + "XS": "333333", # Fallbacks for sizes if needed + } + + # Get background hex, default to Gray if unknown + bg_hex = color_hex_map.get(color, "6C757D") + + # Intelligent text color: If background is White, text is Black. Otherwise, text is White. + text_hex = "000000" if bg_hex == "FFFFFF" else "FFFFFF" + + # URL format: https://placehold.co/800x800/{BG}/{TEXT}.png?text={TEXT_CONTENT} + image_text = f"{color} {product_data['name']}".replace(" ", "+") + image_url = f"https://placehold.co/800x800/{bg_hex}/{text_hex}.png?text={image_text}" + + variant = frappe.get_doc( + { + "doctype": "Style Attribute Variant", + "configurator": configurator_name, + "item_style": template_name, + "attribute_value": color, + "attribute_name": "Color", + "display_name": f"{product_data['name']} - {color}", + "item_group": product_data["item_group"], + "is_published": 1, + "route": route_slug, + "images": [ + { + "image": image_url, + } + ], + } + ) + + variant.insert(ignore_permissions=True) + print(f" ✓ Style variant '{color}' created") + return variant def create_item_variants(template_name, product_data): From c03c3494c3f232ce04538d27ff9e0e856f7d2eb8 Mon Sep 17 00:00:00 2001 From: prathameshmalode-siyaratech Date: Fri, 21 Nov 2025 22:32:39 +0530 Subject: [PATCH 2/4] Improve style variant image URL generation Refactored create_style_variant to use a color-to-hex mapping and generate image URLs with appropriate background and text colors. This enhances the placeholder image logic, supports more colors, and ensures better text visibility on generated images. --- ls_shop/install_demo_data.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ls_shop/install_demo_data.py b/ls_shop/install_demo_data.py index 0da0cf1..d501620 100644 --- a/ls_shop/install_demo_data.py +++ b/ls_shop/install_demo_data.py @@ -502,6 +502,28 @@ def create_style_variant(configurator_name, template_name, color, product_data): # Route should NOT include language prefix - hooks.py handles that route_slug = f"{product_data['code'].lower()}-{color.lower()}" + # Map your color names to Hex codes + color_hex_map = { + "Black": "000000", + "White": "FFFFFF", + "Blue": "0000FF", + "Red": "FF0000", + "Green": "28A745", + "Navy": "000080", + "Gray": "6C757D", + "XS": "333333", # Fallbacks for sizes if needed + } + + # Get background hex, default to Gray if unknown + bg_hex = color_hex_map.get(color, "6C757D") + + # Intelligent text color: If background is White, text is Black. Otherwise, text is White. + text_hex = "000000" if bg_hex == "FFFFFF" else "FFFFFF" + + # URL format: https://placehold.co/800x800/{BG}/{TEXT}.png?text={TEXT_CONTENT} + image_text = f"{color} {product_data['name']}".replace(" ", "+") + image_url = f"https://placehold.co/800x800/{bg_hex}/{text_hex}.png?text={image_text}" + variant = frappe.get_doc( { "doctype": "Style Attribute Variant", @@ -515,7 +537,7 @@ def create_style_variant(configurator_name, template_name, color, product_data): "route": route_slug, "images": [ { - "image": f"https://via.placeholder.com/800x800/{'000000' if color == 'Black' else '0000FF' if color == 'Blue' else 'FF0000' if color == 'Red' else 'FFFFFF'}/FFFFFF?text={color}+{product_data['name'].replace(' ', '+')}", + "image": image_url, } ], } From 1484469ead6df615ecc31a80a5463730b2a09cb4 Mon Sep 17 00:00:00 2001 From: prathameshmalode-siyaratech Date: Sun, 23 Nov 2025 21:58:28 +0530 Subject: [PATCH 3/4] fix: demo placeholder image --- ls_shop/install_demo_data.py | 119 +++++++++++++++++------------------ 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/ls_shop/install_demo_data.py b/ls_shop/install_demo_data.py index 8f0da61..d501620 100644 --- a/ls_shop/install_demo_data.py +++ b/ls_shop/install_demo_data.py @@ -488,66 +488,65 @@ def create_configurator(template_name, product_data): def create_style_variant(configurator_name, template_name, color, product_data): - """Create Style Attribute Variant for a specific color""" - - # Check if variant exists - existing = frappe.db.get_value( - "Style Attribute Variant", {"configurator": configurator_name, "attribute_value": color}, "name" - ) - - if existing: - print(f" • Style variant '{color}' already exists") - return frappe.get_doc("Style Attribute Variant", existing) - - # Route should NOT include language prefix - hooks.py handles that - route_slug = f"{product_data['code'].lower()}-{color.lower()}" - - # --- START CHANGE: Color Logic for Placehold.co --- - # Map your color names to Hex codes - color_hex_map = { - "Black": "000000", - "White": "FFFFFF", - "Blue": "0000FF", - "Red": "FF0000", - "Green": "28A745", - "Navy": "000080", - "Gray": "6C757D", - "XS": "333333", # Fallbacks for sizes if needed - } - - # Get background hex, default to Gray if unknown - bg_hex = color_hex_map.get(color, "6C757D") - - # Intelligent text color: If background is White, text is Black. Otherwise, text is White. - text_hex = "000000" if bg_hex == "FFFFFF" else "FFFFFF" - - # URL format: https://placehold.co/800x800/{BG}/{TEXT}.png?text={TEXT_CONTENT} - image_text = f"{color} {product_data['name']}".replace(" ", "+") - image_url = f"https://placehold.co/800x800/{bg_hex}/{text_hex}.png?text={image_text}" - # --- END CHANGE --- - - variant = frappe.get_doc( - { - "doctype": "Style Attribute Variant", - "configurator": configurator_name, - "item_style": template_name, - "attribute_value": color, - "attribute_name": "Color", - "display_name": f"{product_data['name']} - {color}", - "item_group": product_data["item_group"], - "is_published": 1, - "route": route_slug, - "images": [ - { - "image": image_url, - } - ], - } - ) - - variant.insert(ignore_permissions=True) - print(f" ✓ Style variant '{color}' created") - return variant + """Create Style Attribute Variant for a specific color""" + + # Check if variant exists + existing = frappe.db.get_value( + "Style Attribute Variant", {"configurator": configurator_name, "attribute_value": color}, "name" + ) + + if existing: + print(f" • Style variant '{color}' already exists") + return frappe.get_doc("Style Attribute Variant", existing) + + # Route should NOT include language prefix - hooks.py handles that + route_slug = f"{product_data['code'].lower()}-{color.lower()}" + + # Map your color names to Hex codes + color_hex_map = { + "Black": "000000", + "White": "FFFFFF", + "Blue": "0000FF", + "Red": "FF0000", + "Green": "28A745", + "Navy": "000080", + "Gray": "6C757D", + "XS": "333333", # Fallbacks for sizes if needed + } + + # Get background hex, default to Gray if unknown + bg_hex = color_hex_map.get(color, "6C757D") + + # Intelligent text color: If background is White, text is Black. Otherwise, text is White. + text_hex = "000000" if bg_hex == "FFFFFF" else "FFFFFF" + + # URL format: https://placehold.co/800x800/{BG}/{TEXT}.png?text={TEXT_CONTENT} + image_text = f"{color} {product_data['name']}".replace(" ", "+") + image_url = f"https://placehold.co/800x800/{bg_hex}/{text_hex}.png?text={image_text}" + + variant = frappe.get_doc( + { + "doctype": "Style Attribute Variant", + "configurator": configurator_name, + "item_style": template_name, + "attribute_value": color, + "attribute_name": "Color", + "display_name": f"{product_data['name']} - {color}", + "item_group": product_data["item_group"], + "is_published": 1, + "route": route_slug, + "images": [ + { + "image": image_url, + } + ], + } + ) + + variant.insert(ignore_permissions=True) + print(f" ✓ Style variant '{color}' created") + return variant + def create_item_variants(template_name, product_data): """Create actual item variants for all color/size combinations""" From f5d0fbac3ca45348cc239cf635e43aeda417ac14 Mon Sep 17 00:00:00 2001 From: prathameshmalode-siyaratech Date: Sun, 23 Nov 2025 22:23:04 +0530 Subject: [PATCH 4/4] fix: removed unwanted comments --- ls_shop/install_demo_data.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ls_shop/install_demo_data.py b/ls_shop/install_demo_data.py index d501620..e5e242d 100644 --- a/ls_shop/install_demo_data.py +++ b/ls_shop/install_demo_data.py @@ -502,7 +502,6 @@ def create_style_variant(configurator_name, template_name, color, product_data): # Route should NOT include language prefix - hooks.py handles that route_slug = f"{product_data['code'].lower()}-{color.lower()}" - # Map your color names to Hex codes color_hex_map = { "Black": "000000", "White": "FFFFFF", @@ -511,16 +510,12 @@ def create_style_variant(configurator_name, template_name, color, product_data): "Green": "28A745", "Navy": "000080", "Gray": "6C757D", - "XS": "333333", # Fallbacks for sizes if needed } - # Get background hex, default to Gray if unknown bg_hex = color_hex_map.get(color, "6C757D") - # Intelligent text color: If background is White, text is Black. Otherwise, text is White. text_hex = "000000" if bg_hex == "FFFFFF" else "FFFFFF" - # URL format: https://placehold.co/800x800/{BG}/{TEXT}.png?text={TEXT_CONTENT} image_text = f"{color} {product_data['name']}".replace(" ", "+") image_url = f"https://placehold.co/800x800/{bg_hex}/{text_hex}.png?text={image_text}"