0

Hi I'd like to make a button visible/invisible from inside a website Controller.

@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True)
def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
    if test > 0:
        button_visible = True
    else:
        button_visible = False

Any ideas how I can achieve this?

Jesse
  • 727
  • 13
  • 44

2 Answers2

1

It shouldn't be very hard.

First, you need to think where the button will be located. For example, if it is product page in the shop, you would have to inherit id website_sale.product.

Secondly, insert a script or simply use a conditional statement available in the framework (t-if). For example, if you want to hide the button if user is not logged in then you would use <t t-if="uid is None"> (if user id is non - user is not logged in).

Those principles are working on all versions of Odoo. I have made a module that changes the button if the user is not signed: https://apps.odoo.com/apps/modules/9.0/hide_price_shop/

Have fun

Piotr Cierkosz
  • 322
  • 1
  • 11
0

yes return the boolean as json and on templates just check whether its true. for eg:

<button t-if="object.button_visible" .. />
Hilar AK
  • 1,655
  • 13
  • 25
  • This only works when loading the page, I'd like to update the condition based on the total price in the website cart. This total price is updated by Ajax, so I guess I need to look there – Jesse Jun 07 '18 at 11:14