fix: add .png extension to image URLs — WC rejects extensionless URLs
WooCommerce requires a file extension in image src URLs to determine file type. Added filename.png to all Odoo image URLs. Also fixed variable name ordering bugs where img_name was used before defined. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -249,9 +249,9 @@ class WooProductMap(models.Model):
|
|||||||
# Variant image — pass Odoo's public URL, WC downloads it directly
|
# Variant image — pass Odoo's public URL, WC downloads it directly
|
||||||
if variant.image_variant_1920:
|
if variant.image_variant_1920:
|
||||||
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
filename = (variant.default_code or 'variant') + '.jpg'
|
filename = (variant.default_code or 'variant') + '.png'
|
||||||
if odoo_base:
|
if odoo_base:
|
||||||
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920"
|
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{filename}"
|
||||||
var_data['image'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': filename,
|
'name': filename,
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ class WooProductCreateWizard(models.TransientModel):
|
|||||||
continue
|
continue
|
||||||
filename = getattr(self, f'image_{i}_filename', '') or f'product_image_{i}.jpg'
|
filename = getattr(self, f'image_{i}_filename', '') or f'product_image_{i}.jpg'
|
||||||
img_meta = next((m for m in image_metadata if m.get('index') == i), {})
|
img_meta = next((m for m in image_metadata if m.get('index') == i), {})
|
||||||
img_url = f"{odoo_base}/web/image/product.template/{tmpl_id}/image_1920"
|
img_url = f"{odoo_base}/web/image/product.template/{tmpl_id}/image_1920/{filename}"
|
||||||
wc_img = {
|
wc_img = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': img_meta.get('title', filename),
|
'name': img_meta.get('title', filename),
|
||||||
@@ -587,8 +587,8 @@ class WooProductCreateWizard(models.TransientModel):
|
|||||||
if line.image:
|
if line.image:
|
||||||
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
if odoo_base and variant.id:
|
if odoo_base and variant.id:
|
||||||
var_filename = f"variant_{line.sku or variant.id}.jpg"
|
var_filename = f"variant_{line.sku or variant.id}.png"
|
||||||
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920"
|
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{var_filename}"
|
||||||
var_data['image'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': var_filename,
|
'name': var_filename,
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ class WooVariantPushWizard(models.TransientModel):
|
|||||||
if variant.id and (variant.image_variant_1920 or variant.image_1920):
|
if variant.id and (variant.image_variant_1920 or variant.image_1920):
|
||||||
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
if odoo_base:
|
if odoo_base:
|
||||||
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920"
|
img_name = (line.sku or variant.default_code or 'variant') + '.png'
|
||||||
img_name = (line.sku or variant.default_code or 'variant') + '.jpg'
|
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}"
|
||||||
var_data['image'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': img_name,
|
'name': img_name,
|
||||||
@@ -250,8 +250,8 @@ class WooVariantPushWizard(models.TransientModel):
|
|||||||
# Build the public Odoo image URL
|
# Build the public Odoo image URL
|
||||||
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
odoo_base = inst.env['ir.config_parameter'].sudo().get_param('web.base.url', '')
|
||||||
if odoo_base:
|
if odoo_base:
|
||||||
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920"
|
img_name = (line.sku or variant.default_code or 'variant') + '.png'
|
||||||
img_name = (line.sku or variant.default_code or 'variant') + '.jpg'
|
img_url = f"{odoo_base}/web/image/product.product/{variant.id}/image_1920/{img_name}"
|
||||||
var_data['image'] = {
|
var_data['image'] = {
|
||||||
'src': img_url,
|
'src': img_url,
|
||||||
'name': img_name,
|
'name': img_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user