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