Technical Steps to reset a shopping cart in Odoo 8 Website

Posted on 16 November, 2015

By default Odoo V8 doesn't provide the feature to clear the cart. Here I provide step by step guide to clear the shopping cart. These are the technical steps which will ensure the perfact execution of the purpose.

Step 1. Inherit template of cart and make one .xml file.

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

Step 2. Make .js file inside /startic/src/js folder to make click event of the link.

1
2
3
4
5
6
7
8
9
10
11
12
$(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;
     });
   });
});
                            

Step 3. Add controller inside .py file to manage request of clear cart.

1
2
3
4
5
6
7
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()              

That's it !!! It will add one functionality inside cart template for clear/remove all products from the selected cart.

This module available free of cost in our Shop. Download it ! Have fun !!

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customerswith our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions. We are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech 

Post Your Review

X

Your Review has been posted

0 Comment(s)