Skip to Content
Menu
This question has been flagged
3 Replies
2592 Views

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()
Avatar
Discard
Author Best Answer

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)

Avatar
Discard
Best Answer

Hi, you can check this:

https://youtu.be/zqFuvqnC3zs

Hope it helps

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 24
1338
1
Mar 23
2918
0
Apr 17
2495
0
Mar 15
3552
2
Apr 25
2771