From 84f8c9fb71260c3676f5760fcb4a0828ecb06b7f Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Fri, 7 Feb 2020 11:03:28 +0530 Subject: [PATCH] Issue #2328 --- .../shop/products/list/recently-viewed.blade.php | 4 ---- .../Resources/views/shop/products/view.blade.php | 14 +++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/recently-viewed.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/recently-viewed.blade.php index 0e637fc68..b938c2369 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/recently-viewed.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/recently-viewed.blade.php @@ -73,10 +73,6 @@ var slugs = JSON.parse(storedRecentlyViewed); var updatedSlugs = {}; - if (slugs.length > 3) { - slugs = slugs.slice(Math.max(slugs.length - 3, 1)); - } - slugs = slugs.reverse(); slugs.forEach(slug => { diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php index 7dfc61562..3fbd717ae 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php @@ -178,10 +178,22 @@ if (existingViewed.indexOf(currentProductId) == -1) { existingViewed.push(currentProductId); - if (existingViewed.length > 4) + if (existingViewed.length > 3) existingViewed = existingViewed.slice(Math.max(existingViewed.length - 4, 1)); window.localStorage.setItem('recentlyViewed', JSON.stringify(existingViewed)); + } else { + var uniqueNames = []; + + $.each(existingViewed, function(i, el){ + if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el); + }); + + uniqueNames.push(currentProductId); + + uniqueNames.splice(uniqueNames.indexOf(currentProductId), 1); + + window.localStorage.setItem('recentlyViewed', JSON.stringify(uniqueNames)); } },