From 418a8bcf33345da5d79d7ecff46e796ecd1934a6 Mon Sep 17 00:00:00 2001 From: Gorash Date: Tue, 7 Jun 2022 09:59:45 +0000 Subject: [PATCH] [IMP] website_sale_wishlist: quantity in js sessionStorage The session value is updated each time the user modifies the wishlist. The number is also updated when the user go on the wishlist page or if the value is different from that of the HTML content (if the user does undo in his history). opw-2737985 closes odoo/odoo#92962 Signed-off-by: Vincent Schippefilt (vsc) --- .../static/src/js/website_sale_wishlist.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js index e441f18e6c4..359de4e3d70 100644 --- a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js +++ b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js @@ -24,7 +24,7 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, */ init: function (parent) { this._super.apply(this, arguments); - this.wishlistProductIDs = []; + this.wishlistProductIDs = JSON.parse(sessionStorage.getItem('website_sale_wishlist_product_ids') || '[]'); }, /** * Gets the current wishlist items. @@ -35,13 +35,16 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, willStart: function () { var self = this; var def = this._super.apply(this, arguments); + var wishDef; + if (this.wishlistProductIDs.length != +$('#top_menu .my_wish_quantity').text()) { + wishDef = $.get('/shop/wishlist', { + count: 1, + }).then(function (res) { + self.wishlistProductIDs = JSON.parse(res); + sessionStorage.setItem('website_sale_wishlist_product_ids', res); + }); - var wishDef = $.get('/shop/wishlist', { - count: 1, - }).then(function (res) { - self.wishlistProductIDs = JSON.parse(res); - }); - + } return Promise.all([def, wishDef]); }, /** @@ -107,6 +110,7 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, }).then(function () { var $navButton = $('header .o_wsale_my_wish').first(); self.wishlistProductIDs.push(productId); + sessionStorage.setItem('website_sale_wishlist_product_ids', JSON.stringify(self.wishlistProductIDs)); self._updateWishlistView(); wSaleUtils.animateClone($navButton, $el.closest('form'), 25, 40); }).guardedCatch(function () { @@ -143,6 +147,7 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, }); this.wishlistProductIDs = _.without(this.wishlistProductIDs, product); + sessionStorage.setItem('website_sale_wishlist_product_ids', JSON.stringify(this.wishlistProductIDs)); if (this.wishlistProductIDs.length === 0) { if (deferred_redirect) { deferred_redirect.then(function () {