Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
2727 Widoki

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()
Awatar
Odrzuć
Autor Najlepsza odpowiedź

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)

Awatar
Odrzuć
Najlepsza odpowiedź

Hi, you can check this:

https://youtu.be/zqFuvqnC3zs

Hope it helps

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
kwi 24
1473
1
mar 23
3087
0
kwi 17
2597
0
mar 15
3651
2
kwi 25
2856