Odoo中文网|Odoo实施培训

 找回密码
 立即注册
搜索
热搜: Odoo OpenERP 实施
查看: 5819|回复: 0

在Odoo 8.0的website中重置购物车

[复制链接]

6

主题

20

帖子

62

积分

版主

Rank: 7Rank: 7Rank: 7

积分
62
发表于 2015-11-8 16:14:50 | 显示全部楼层 |阅读模式
在自定义模块中重置购物车,主要分三步:
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模块。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|技术支持|开发手册|Odoo中文网-远鼎旗下odoo培训网站 ( 苏ICP备15039516号 )

GMT+8, 2024-3-29 03:25 , Processed in 0.011533 second(s), 9 queries , Xcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表