콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
3396 화면

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

아바타
취소
관련 게시물 답글 화면 활동
1
6월 25
2245
2
6월 25
578
1
3월 23
3811
0
4월 17
2961
0
3월 15
4020