|
在自定义模块中重置购物车,主要分三步:
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模块。
|
|