如何在每个新客户的会话中清除购物车

问题描述 投票:0回答:1

在 odoo 16 中,我的客户想知道为什么他们仍然可以获得几天前放弃的购物车的内容。

如何在每次新登录时重置购物车内容?

我们可以在设置中设置这个参数 revive="FALSE" 吗?

#addons module website_sale>controllers/main.py:

class WebsiteSale(http.Controller):
#...
#...

    @http.route(['/shop/cart'], type='http', auth="public", website=True, sitemap=False)
    def cart(self, access_token=None, revive='', **post):
        """
        Main cart management + abandoned cart revival
        access_token: Abandoned cart SO access token
        revive: Revival method when abandoned cart. Can be 'merge' or 'squash'
        """

...或者是否有必要在每次登录时调用这个现有函数?

#addons module website_sale>controllers/main.py:


class WebsiteSale(http.Controller):
#...
#...
@http.route(['/shop/cart/clear'], type='json', auth="public", website=True)
    def clear_cart(self):
        order = request.website.sale_get_order()
        for line in order.order_line:
            line.unlink()
authentication session cart odoo-16
1个回答
0
投票

我是这样解决的:

class SaleOrder(models.Model):
    _inherit = "sale.order"

    def _reset_cart(self):
        """ reset cart content if sol older than one hour  """
        order = request.website.sale_get_order()
        dt_last_hour = datetime.today() - timedelta(hours=1)
        for line in order.order_line.filtered(lambda rec: rec.create_date<dt_last_hour):
            line.unlink()

    def _cart_update(self, product_id=None, line_id=None, add_qty=0, set_qty=0, **kwargs):
        """ hook cart_update to reset cart content if sol older than one hour  """
        
        self.sudo()._reset_cart()
        res_super = super(SaleOrder, self)._cart_update(product_id, line_id, add_qty, set_qty, **kwargs)
        
        return res_super
© www.soinside.com 2019 - 2024. All rights reserved.