Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
10062 Lượt xem

Hello guys,

What is the trick to reset the cart? I would want a button in the cart to delete all lines in it.

Thanks to help..


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Pascal,

You can make your own custom module to manage reset the cart by following below steps...

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

<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">&lt;span class="fa fa-trash-o"/> Clear Cart&lt;/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.

$(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.

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.

I am sure that it is very useful for you.

Free App is out at Odoo Apps Store now. You can download  and use it.

Odoo Technical notes is published for this. You can view Technical Stpes to reset a shopping cart in Odoo 8 Website  and review it. 

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for all. Very nice from you. I'm testing. For the moment, I have the button but it doesn't work.

Tác giả

Ok, it works well now! 1000 thanks for your quick answer.

@Emipro,
Thanks for the post! Do you have any suggestions on how this could be done by order line only? The use case is I want to add an 'x' or trash can icon to the order lines in my own module for a quick cart dropdown in the nav/header (already built), and in the shopping cart order lines.

I'm just wondering if there is an easy way to delete order lines given the method shown above or an alternative.

@Luke I've did something similar. The view: https://github.com/Yenthe666/Dev/blob/master/aa_houbolak/templates.xml#L358 The JS: https://github.com/Yenthe666/Dev/blob/master/aa_houbolak/static/src/js/houbolak.js#L23-L32 This pretty much shows a delete icon and then deletes the specific line through XML-RPC. I hope this helps you :)

Câu trả lời hay nhất

Thanks a lot.

Really its very helpful for me as well as other also.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 21
3269
1
thg 3 15
4225
0
thg 3 15
5028
0
thg 3 15
3544
0
thg 3 15
3959