跳至內容
選單
此問題已被標幟
3 回覆
2741 瀏覽次數

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()
頭像
捨棄
作者 最佳答案

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)

頭像
捨棄
最佳答案

Hi, you can check this:

https://youtu.be/zqFuvqnC3zs

Hope it helps

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
4月 24
1478
1
3月 23
3092
0
4月 17
2604
0
3月 15
3652
2
4月 25
2859