* http, http_routing, website, website_sale_comparison At an crawling engine/SEO level, having trailing slashes or not in URLs doesn't change anything. Still, whichever solution is chosen, it should be done consistantly: either all URLs have trailing slashes, or none of them have it. See https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash " Be consistent with the preferred version. Use it in your internal links. If you have a Sitemap, include the preferred version (and don't include the duplicate URL). " opw-2505818 opw-2513575 Community: https://github.com/odoo/odoo/pull/71065 Enterprise: https://github.com/odoo/enterprise/pull/18615
40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
|
import json
|
|
|
|
|
|
class WebsiteSaleProductComparison(WebsiteSale):
|
|
|
|
@http.route('/shop/compare', type='http', auth="public", website=True, sitemap=False)
|
|
def product_compare(self, **post):
|
|
values = {}
|
|
product_ids = [int(i) for i in post.get('products', '').split(',') if i.isdigit()]
|
|
if not product_ids:
|
|
return request.redirect("/shop")
|
|
# use search to check read access on each record/ids
|
|
products = request.env['product.product'].search([('id', 'in', product_ids)])
|
|
values['products'] = products.with_context(display_default_code=False)
|
|
return request.render("website_sale_comparison.product_compare", values)
|
|
|
|
@http.route(['/shop/get_product_data'], type='json', auth="public", website=True)
|
|
def get_product_data(self, product_ids, cookies=None):
|
|
ret = {}
|
|
pricelist_context, pricelist = self._get_pricelist_context()
|
|
prods = request.env['product.product'].with_context(pricelist_context, display_default_code=False).search([('id', 'in', product_ids)])
|
|
|
|
if cookies is not None:
|
|
ret['cookies'] = json.dumps(request.env['product.product'].search([('id', 'in', list(set(product_ids + cookies)))]).ids)
|
|
|
|
prods.mapped('name')
|
|
for prod in prods:
|
|
ret[prod.id] = {
|
|
'render': request.env['ir.ui.view']._render_template(
|
|
"website_sale_comparison.product_product",
|
|
{'product': prod, 'website': request.website}
|
|
),
|
|
'product': dict(id=prod.id, name=prod.name, display_name=prod.display_name),
|
|
}
|
|
return ret
|