I am working on an e-commerce website in Odoo, and I want to add functionality to display multiple images for each product. Currently, Odoo allows adding a single image by default. I would like to extend this feature to support multiple images per product.
Here is what I aim to achieve:
Add a field to store multiple images in the product model.
Implement this functionality using a separate custom module.
I am working on an e-commerce website in Odoo, and I want to add functionality to display multiple images for each product. Currently, Odoo allows adding a single image by default. I would like to extend this feature to support multiple images per product.
Here is what I aim to achieve:
Add a field to store multiple images in the product model.
Implement this functionality using a separate custom module.
Share Improve this question asked Nov 20, 2024 at 10:40 Karthick1211Karthick1211 314 bronze badges2 Answers
Reset to default 1You don't need a custom module to store additional images for a product. Odoo provides the Extra Media option for this purpose. Open a product, navigate to the Sales tab, and under it, you'll find the Add Media option. Here, you can add multiple media files, including images and videos. These will also be displayed on the eCommerce platform by default.
Note: This option is available only if the eCommerce module is installed.
If you are not using the eCommerce module and still need to add extra images for products, here's an example of how you can inherit the product model and add a field for storing extra images:
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
extra_image_ids = fields.One2many(
'product.image',
'product_tmpl_id',
string="Extra Images",
help="Additional images for the product."
)
class ProductImage(models.Model):
_name = 'product.image'
_description = 'Product Image'
name = fields.Char(string="Image Name")
image = fields.Image(string="Image")
product_tmpl_id = fields.Many2one(
'product.template',
string="Product Template",
ondelete='cascade'
)
I am actually busy with the exact same thing. What I realised is that you can add extra media to an image on the product tab. The debug mode hinted me to the data model <product.image>. I think <product.image> can be used to store multiple images and to then relate it to the <product.template.id> or <product.product.id>. Have not tried it yet myself (will do in the next weeks I guess) but if it works, then there is actually no need to add a new field to store multiple images per product. Just use the <product.image> model to store the image.