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()