Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
3507 Vizualizări

I am trying to add a simple logic that updates a custom field value in Odoo website's cart page (/shop/cart). So I am trying to override/add this logic to the controller:


value = request.session.get('some_value')
if value:
for line in order.order_line:
line.write({
'some_value_field': value
})
How can I add that into the controller? I tried this:

from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo import api, fields, http, SUPERUSER_ID, tools, _, models
from odoo.http import request
class Custom(WebsiteSale):

@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True, csrf=False)
def cart_update_json(
self, product_id, line_id=None, add_qty=None, set_qty=None, display=True,
product_custom_attribute_values=None, no_variant_attribute_values=None, **kw
):
value = request.session.get('some_value')
if value:
for line in order.order_line:
line.write({
'some_value_field': value
})

return super(Custom, self).cart_update_json()
Imagine profil
Abandonează
Autor Cel mai bun răspuns

Hi Cybrosys Technologies,

I tried your code, but I dont quite understand part of your code:

           response.update({
'product_name': product.name,
'product_id': int(product_id),

})

What is the usage of this part of the code? I cannot comment under your answer because I dont have enough karma (nice system odoo)

Imagine profil
Abandonează
Cel mai bun răspuns

Hi, you can check this:

https://youtu.be/zqFuvqnC3zs

Hope it helps

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Try like below

from odoo.addons.website_sale.controllers.main import WebsiteSale

class WebsiteSaleController(WebsiteSale):

@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True, csrf=False)
def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True, **kw):
response = super(WebsiteSaleController, self).cart_update_json(product_id, line_id=line_id, add_qty=add_qty,
set_qty=set_qty, display=display, **kw)

if response:
product = request.env['product.product'].browse(int(product_id))
response.update({
'product_name': product.name,
'product_id': int(product_id),

})
return response

Regards

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
aug. 25
2341
2
iun. 25
670
1
mar. 23
3915
0
apr. 17
3042
0
mar. 15
4089