You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. # Copyright 2021 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import http
  4. from odoo.http import request
  5. from odoo.addons.website_sale.controllers.main import WebsiteSale
  6. from odoo.addons.website_coupon.controllers.main import WebsiteCoupon
  7. class WebsiteCoupon(WebsiteCoupon):
  8. @http.route(['/shop/cart'], type='http', auth="public", website=True, sitemap=False)
  9. def cart(self, access_token=None, revive='', **post):
  10. res = super(WebsiteCoupon, self).cart(access_token, revive, **post)
  11. order = request.website.sale_get_order()
  12. res.qcontext['no_pass_payment'] = False
  13. if order.amount_total <= request.website.amount_limit:
  14. res.qcontext['no_pass_payment'] = True
  15. res.qcontext['amount_limit'] = request.website.amount_limit
  16. return res
  17. class WebsiteSale(WebsiteSale):
  18. @http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True, csrf=False)
  19. def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
  20. res = super(WebsiteSale, self).cart_update_json(product_id, line_id, add_qty, set_qty, display)
  21. return res
  22. @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, csrf=False)
  23. def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
  24. res = super(WebsiteSale, self).cart_update(product_id, add_qty, set_qty, **kw)
  25. return res
  26. # """This route is called when adding a product to cart (no options)."""
  27. # sale_order = request.website.sale_get_order(force_create=True)
  28. # if sale_order.state != 'draft':
  29. # request.session['sale_order_id'] = None
  30. # sale_order = request.website.sale_get_order(force_create=True)
  31. #
  32. # product_custom_attribute_values = None
  33. # if kw.get('product_custom_attribute_values'):
  34. # product_custom_attribute_values = json.loads(kw.get('product_custom_attribute_values'))
  35. #
  36. # no_variant_attribute_values = None
  37. # if kw.get('no_variant_attribute_values'):
  38. # no_variant_attribute_values = json.loads(kw.get('no_variant_attribute_values'))
  39. #
  40. # sale_order._cart_update(
  41. # product_id=int(product_id),
  42. # add_qty=add_qty,
  43. # set_qty=set_qty,
  44. # product_custom_attribute_values=product_custom_attribute_values,
  45. # no_variant_attribute_values=no_variant_attribute_values
  46. # )
  47. # return request.redirect("/shop/cart")