Skip to content
Snippets Groups Projects
Commit 45bd7a58 authored by Julien Castiaux's avatar Julien Castiaux
Browse files

[FIX] website_sale_comparison: concurrent add/delete


1) Add a 1st product to compare from the ecommerce /shop page.
2) Open the compare list pop up at the bottom.
3) Add a 2nd product to compare from the /shop page.
4) Remove the 1st product from the compare list before the rpc of the
2nd product is done.
5) Javascript error `self.product_data[res] is undefined`

The function `add_new_products` and `rm_from_comparelist` are
concurrent, they both modify the internal `comparelist_product_ids`
product list. The first one perform an RPC and delay the update once the
request is done, the second does the update immediately.

The solution has been to use a mutex to exclude the two functions.

opw-1974108

closes odoo/odoo#33302

Signed-off-by: default avatarQuentin Smetz (qsm) <qsm@odoo.com>
parent 187b77d7
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@ odoo.define('website_sale_comparison.comparison', function (require) {
require('web.dom_ready');
var ajax = require('web.ajax');
var concurrency = require('web.concurrency');
var core = require('web.core');
var _t = core._t;
var utils = require('web.utils');
......@@ -26,6 +27,7 @@ var ProductComparison = Widget.extend({
init: function(){
this.comparelist_product_ids = JSON.parse(utils.get_cookie('comparelist_product_ids') || '[]');
this.product_compare_limit = 4;
this.guard = new concurrency.Mutex();
},
start:function(){
var self = this;
......@@ -113,6 +115,9 @@ var ProductComparison = Widget.extend({
}
},
add_new_products:function(product_id){
this.guard.exec(this._add_new_products.bind(this, product_id));
},
_add_new_products: function (product_id) {
var self = this;
$('.o_product_feature_panel').show();
if (!_.contains(self.comparelist_product_ids, product_id)) {
......@@ -120,8 +125,9 @@ var ProductComparison = Widget.extend({
if(_.has(self.product_data, product_id)){
self.update_content([product_id], false);
} else {
self.load_products([product_id]).then(function(){
return self.load_products([product_id]).then(function () {
self.update_content([product_id], false);
self.update_cookie();
});
}
}
......@@ -139,6 +145,9 @@ var ProductComparison = Widget.extend({
this.refresh_panel();
},
rm_from_comparelist: function(e){
this.guard.exec(this._rm_from_comparelist.bind(this, e));
},
_rm_from_comparelist: function (e) {
this.comparelist_product_ids = _.without(this.comparelist_product_ids, $(e.currentTarget).data('product_product_id'));
$(e.currentTarget).parents('.o_product_row').remove();
this.update_cookie();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment