This question has been flagged
3514 Views

UPDATE: Issue was with __openerp__.py, the following line was missing:

import controllers

(stupid mistake)

 

I'd like to display all the images attached to a product (as attachments) on the product page (website shop).

I've extended the website_sale class in the main.py controller of the website_sale addon:

class website_sale_attachment(website_sale):

    @http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
    def product(self, product, category='', search='', **kwargs):

        response = super(website_sale_attachment, self).product(product, category='', search='', **kwargs)

        attachment_obj = request.env['ir.attachment']
        images = attachment_obj.sudo().search([('res_model', '=', 'product.template'), ('res_id', '=', product.id)])

        response.qcontext.update({'images': images,})
        return response

 

I've inserted the following in the website_sale.product template to check whether the new variable "images" is present in the context:

<p><t t-esc="len(images)"/></p>

But I get the following error:

"object of type 'NoneType' has no len()" while evaluating 'len(images)'

It is as if the new key value is not visible from the template.

I've pretty much followed the example in the website_sale_digital addon (master version):

https://github.com/odoo/odoo/blob/master/addons/website_sale_digital/controllers/main.py

I've restarted the server and rebooted it as well but nothing seems to help. Do you have any idea why this is not working? Thanks.

 

Avatar
Discard