Skip to content
Permalink
Browse files

[FIX] website_sale: fix concurrent update on cart

shop page link and popover use the same route which make a write on db
to recompute coupon lines. Can lead to concurent updates if unlucky on
timing.

task-2070507
  • Loading branch information...
fja-odoo authored and qsm-odoo committed Sep 19, 2019
1 parent 19e841b commit e7f9fd9cdaba71f0fd541e4cb2304cd70d186fbc
Showing with 17 additions and 2 deletions.
  1. +17 −2 addons/website_sale/static/src/js/website_sale.js
@@ -7,6 +7,7 @@ odoo.define('website_sale.cart', function (require) {

var shopping_cart_link = $('ul#top_menu li a[href$="/shop/cart"]');
var shopping_cart_link_counter;
var popoverRpc = null;
shopping_cart_link.popover({
trigger: 'manual',
animation: true,
@@ -24,7 +25,7 @@ odoo.define('website_sale.cart', function (require) {
shopping_cart_link_counter = setTimeout(function(){
if($(self).is(':hover') && !$(".mycart-popover:visible").length)
{
$.get("/shop/cart", {'type': 'popover'})
popoverRpc = $.get("/shop/cart", {'type': 'popover'})
.then(function (data) {
$(self).data("bs.popover").options.content = data;
$(self).popover("show");
@@ -33,7 +34,7 @@ odoo.define('website_sale.cart', function (require) {
});
});
}
}, 100);
}, 300);
}).on("mouseleave", function () {
var self = this;
setTimeout(function () {
@@ -43,6 +44,20 @@ odoo.define('website_sale.cart', function (require) {
}
}
}, 1000);
}).on('click', function (ev) {
// When clicking on the cart link, prevent any popover to show up (by
// clearing the related setTimeout) and, if a popover rpc is ongoing,
// wait for it to be completed before going to the link's href. Indeed,
// going to that page may perform the same computation the popover rpc
// is already doing.
clearTimeout(shopping_cart_link_counter);
if (popoverRpc && popoverRpc.state() === 'pending') {
ev.preventDefault();
var href = ev.currentTarget.href;
popoverRpc.then(function () {
window.location.href = href;
});
}
});
});

0 comments on commit e7f9fd9

Please sign in to comment.
You can’t perform that action at this time.