This question has been flagged

I created two radio inputs on the `/shop/product/<product>` page.

When the user clicks the `Add to cart` button, the value of the selected radio is passed to the controller, to the function `cart_update`.

There, I can check which radio input was checked, then put some value in the `request.context` dictionnary for example.

However, in the model functions called by the original `cart_update`  function, the context (`self.env.context`) does not show my value.

So, how can I notify model functions such as `_cart_find_product_line`, without redefining completly the controller function `cart_update`, which is a very bad practice ?

Avatar
Discard
Author

food for thought: I think self.env.context holds the server context, and request.context holds the client context. Can the solution be sessions ? But can the server access the session of the current user asking the method ? That's silly I think...

Author

It should, but the call to this method is in the middle of the sale_order._cart_update function. I choose to override a smaller function (website_sale.cart_update) and make use of the **kwargs argument.

Author

I'll accept your answer if you convert it.

Best Answer

Hi, if you use this -> self.env['models.mymodel'].with_context(param=value)._cart_find_product_line(vals) // it doesn't work ?

Avatar
Discard