Odoo中文网|Odoo实施培训

标题: 在Odoo 8.0的website中重置购物车 [打印本页]

作者: 洪七    时间: 2015-11-8 16:14
标题: 在Odoo 8.0的website中重置购物车
在自定义模块中重置购物车,主要分三步:
1. 新建XML文件,继承cart模板
  1. <template id="clear_cart_button" inherit_id="website_sale.cart" customize_show="True" name="Clear Cart Button">
  2.   <xpath expr="//a[@href='/shop/checkout']" position="before">
  3.     <a href="" id="clear_cart_button" class="btn btn-default mb32"><span class="fa fa-trash-o"/> Clear Cart</a>  
  4.   </xpath>
  5. </template>
  6. <!-- This template is use to add .js file inside webiste. -->
  7. <template id="assets_frontend" inherit_id="website.assets_frontend" name="Shop">
  8. <xpath expr="." position="inside">
  9.     <script type="text/javascript" src="/website_sale_clear_cart/static/src/js/website_sale_clear_cart.js"></script>  
  10. </xpath>
  11. </template>
复制代码
2. 新建js文件,处理click事件
  1. $(document).ready(function () {
  2. $('.oe_website_sale').each(function () {
  3.     var oe_website_sale = this;
  4.     $(oe_website_sale).on("click", ".oe_cart #clear_cart_button", function () {
  5.         openerp.jsonRpc("/shop/clear_cart", "call", {}).then(function(){
  6.             location.reload();
  7.         });
  8.         return false;
  9.     });
  10. });
  11. });
复制代码
3.新建py文件,处理重置请求
  1. class pos_website_sale(http.Controller):
  2.     @http.route(['/shop/clear_cart'], type='json', auth="public", website=True)
  3.     def clear_cart(self):
  4.         order = request.website.sale_get_order()
  5.         if order:
  6.             for line in order.website_order_line:
  7.                 line.unlink()
复制代码
也可在Odoo Apps中下载website_vacuum_cart模块。





欢迎光临 Odoo中文网|Odoo实施培训 (http://www.chinaodoo.net/) Powered by Discuz! X3.2