Fix product image not saving/displaying in tenant admin
Fixed two issues with product images: 1. Images weren't being preserved when editing other product fields - added logic to keep existing image value when no new image is uploaded 2. Image URLs had double underscores (e.g., /images/123__image.jpg) due to field names starting with underscore - now strips leading underscore from field name when constructing image paths
This commit is contained in:
@@ -110,8 +110,9 @@ def add_product(tenant_id):
|
|||||||
'mime_type': mime_type
|
'mime_type': mime_type
|
||||||
})
|
})
|
||||||
|
|
||||||
# Set the image URL path
|
# Set the image URL path (strip leading underscore from field_name to avoid double underscores)
|
||||||
image_path = f"/images/{product_id}_{field_name}.{extension}"
|
field_suffix = field_name[1:] if field_name.startswith('_') else field_name
|
||||||
|
image_path = f"/images/{product_id}_{field_suffix}.{extension}"
|
||||||
|
|
||||||
# For backward compatibility with _image field
|
# For backward compatibility with _image field
|
||||||
if field_name == '_image':
|
if field_name == '_image':
|
||||||
@@ -249,13 +250,15 @@ def edit_product(tenant_id, product_id):
|
|||||||
'mime_type': mime_type
|
'mime_type': mime_type
|
||||||
})
|
})
|
||||||
|
|
||||||
# Update image path
|
# Update image path (strip leading underscore from field_name to avoid double underscores)
|
||||||
existing_field["value"] = f"/images/{product_id}_{field_name}.{extension}"
|
field_suffix = field_name[1:] if field_name.startswith('_') else field_name
|
||||||
|
existing_field["value"] = f"/images/{product_id}_{field_suffix}.{extension}"
|
||||||
|
|
||||||
# For backward compatibility with _image field
|
# For backward compatibility with _image field
|
||||||
if field_name == '_image':
|
if field_name == '_image':
|
||||||
image_data = img_data
|
image_data = img_data
|
||||||
image_mime_type = mime_type
|
image_mime_type = mime_type
|
||||||
|
# If no new image uploaded, keep the existing value (already in existing_field)
|
||||||
else:
|
else:
|
||||||
# Get value from form
|
# Get value from form
|
||||||
value = request.form.get(f'field_{field_name}', '')
|
value = request.form.get(f'field_{field_name}', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user