From b1bb4a0c94c0e7a0f88bc26c0f9517df99089b6a Mon Sep 17 00:00:00 2001 From: chrisai-dev Date: Tue, 23 Apr 2024 14:25:29 +0200 Subject: [PATCH 1/4] Overwriting productListingComments.js with the correct product selector --- .../views/js/productListingComments.js | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 modules/productcomments/views/js/productListingComments.js diff --git a/modules/productcomments/views/js/productListingComments.js b/modules/productcomments/views/js/productListingComments.js new file mode 100644 index 000000000..8d34ca2f4 --- /dev/null +++ b/modules/productcomments/views/js/productListingComments.js @@ -0,0 +1,151 @@ +/** + * 2007-2019 PrestaShop SA and Contributors + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@prestashop.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + * versions in the future. If you wish to customize PrestaShop for your + * needs please refer to http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2019 PrestaShop SA and Contributors + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + + +$(document).ready(function() { + productListingComments.init(); + productListingComments.load(); +}); + + +var productListingComments = (function () { + + var data = { + productIDs: [], + commentsLoadingInProgress: false, + ajaxIDsLimit: 50, + ajaxUrl: '' + } + + var DOMStrings = { + productListReviewsContainer: '.product-list-reviews', + productListReviewsNumberOfComments: '.comments-nb', + productListReviewsStarsContainer: '.grade-stars', + productContainer: '.product-miniature__infos__bottom' + }; + + var DOMClasses = { + inProgress: 'reviews-loading', + reviewsLoaded: 'reviews-loaded', + hasReviews: 'has-reviews' + }; + + function setEvents() { + prestashop.on('updateProductList', function() { + addProductsIDs(); + }); + } + + + function setAjaxUrl() { + if (data.ajaxUrl !== '') + return; + + var url = $(DOMStrings.productListReviewsContainer).first().data('url'); + data.ajaxUrl = url; + } + + function getNewProductsReviewsElements() { + var $productListReviews = $(DOMStrings.productContainer) + .not('.' + DOMClasses.reviewsLoaded + ', .' + DOMClasses.inProgress) + .addClass(DOMClasses.inProgress) + .find(DOMStrings.productListReviewsContainer); + + return $productListReviews; + } + + function addProductsIDs() { + + var $productsList = getNewProductsReviewsElements(), + seenIds = {}; + + $productsList.each(function () { + var id = $(this).data('id'); + seenIds[id] = true; + }); + + + var IDsArray = Object.keys(seenIds).filter(e => e !== 'undefined'); + var prevDataIDs = data.productIDs.splice(0); + data.productIDs = prevDataIDs.concat(IDsArray); + + if (!data.commentsLoadingInProgress) { + loadProductsData(); + } + } + + function loadProductsData() { + if (data.productIDs.length === 0) + return; + + data.commentsLoadingInProgress = true; + + var dataIDsCopy = data.productIDs.slice(0); + selectedProductIDs = dataIDsCopy.splice(0, data.ajaxIDsLimit); + + + $.get(data.ajaxUrl, { id_products: selectedProductIDs }, function (jsonData) { + if (jsonData) { + $.each(jsonData.products, function(i, elem) { + var productData = elem; + var $productsReviewsContainer = $('.product-list-reviews[data-id="' + productData.id_product + '"]'); + + $productsReviewsContainer.each(function () { + var $self = $(this); + + if (productData.comments_nb > 0) { + $self.find(DOMStrings.productListReviewsStarsContainer).rating({ grade: productData.average_grade, starWidth: 16 }); + $self.find(DOMStrings.productListReviewsNumberOfComments).text('(' + productData.comments_nb + ')'); + $self.closest(DOMStrings.productContainer).addClass(DOMClasses.hasReviews); + $self.css('visibility', 'visible'); + } + + $self.closest(DOMStrings.productContainer).addClass(DOMClasses.reviewsLoaded); + $self.closest(DOMStrings.productContainer).removeClass(DOMClasses.inProgress); + + }); + data.productIDs.shift(); + }); + + data.commentsLoadingInProgress = false; + if (data.productIDs.length > 0) { + loadProductsData(); + } + + } + }); + } + + + return { + load: function () { + addProductsIDs(); + }, + init: function () { + setAjaxUrl(); + setEvents(); + } + } +})(); From 0459cfd786d58078573239b38610b4fbc028b1c7 Mon Sep 17 00:00:00 2001 From: chrisai-dev Date: Wed, 24 Apr 2024 18:21:43 +0200 Subject: [PATCH 2/4] adding missing hook configuration to the theme.yml file --- config/theme.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/theme.yml b/config/theme.yml index ffa938e62..59440ded4 100644 --- a/config/theme.yml +++ b/config/theme.yml @@ -100,6 +100,9 @@ global_settings: - ps_searchbar displayProductAdditionalInfo: - ps_sharebuttons + - productcomments + displayProductListReviews: + - productcomments displayOrderConfirmation2: - ps_featuredproducts displayCrossSellingShoppingCart: From cebd520e930ffd6ffa731f33ed5da94bfbbad2bd Mon Sep 17 00:00:00 2001 From: chrisai-dev Date: Fri, 26 Apr 2024 15:41:59 +0200 Subject: [PATCH 3/4] adding missing hook configuration to the theme.yml file --- config/theme.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/theme.yml b/config/theme.yml index 59440ded4..04cf6d96b 100644 --- a/config/theme.yml +++ b/config/theme.yml @@ -87,6 +87,8 @@ global_settings: - ps_customeraccountlinks - ps_contactinfo - blockwishlist + displayFooterProduct: + - productcomments displayLeftColumn: - ps_categorytree - ps_facetedsearch From f555513d5c3edb8cc74094338a2f8f82faee68a2 Mon Sep 17 00:00:00 2001 From: chrisai-dev <49228974+chrisai-dev@users.noreply.github.com> Date: Wed, 22 May 2024 10:10:32 +0200 Subject: [PATCH 4/4] overwriting the .js is no longer needer as it was fixed in the module itself --- .../views/js/productListingComments.js | 151 ------------------ 1 file changed, 151 deletions(-) delete mode 100644 modules/productcomments/views/js/productListingComments.js diff --git a/modules/productcomments/views/js/productListingComments.js b/modules/productcomments/views/js/productListingComments.js deleted file mode 100644 index 8d34ca2f4..000000000 --- a/modules/productcomments/views/js/productListingComments.js +++ /dev/null @@ -1,151 +0,0 @@ -/** - * 2007-2019 PrestaShop SA and Contributors - * - * NOTICE OF LICENSE - * - * This source file is subject to the Academic Free License (AFL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/afl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@prestashop.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade PrestaShop to newer - * versions in the future. If you wish to customize PrestaShop for your - * needs please refer to http://www.prestashop.com for more information. - * - * @author PrestaShop SA - * @copyright 2007-2019 PrestaShop SA and Contributors - * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) - * International Registered Trademark & Property of PrestaShop SA - */ - - -$(document).ready(function() { - productListingComments.init(); - productListingComments.load(); -}); - - -var productListingComments = (function () { - - var data = { - productIDs: [], - commentsLoadingInProgress: false, - ajaxIDsLimit: 50, - ajaxUrl: '' - } - - var DOMStrings = { - productListReviewsContainer: '.product-list-reviews', - productListReviewsNumberOfComments: '.comments-nb', - productListReviewsStarsContainer: '.grade-stars', - productContainer: '.product-miniature__infos__bottom' - }; - - var DOMClasses = { - inProgress: 'reviews-loading', - reviewsLoaded: 'reviews-loaded', - hasReviews: 'has-reviews' - }; - - function setEvents() { - prestashop.on('updateProductList', function() { - addProductsIDs(); - }); - } - - - function setAjaxUrl() { - if (data.ajaxUrl !== '') - return; - - var url = $(DOMStrings.productListReviewsContainer).first().data('url'); - data.ajaxUrl = url; - } - - function getNewProductsReviewsElements() { - var $productListReviews = $(DOMStrings.productContainer) - .not('.' + DOMClasses.reviewsLoaded + ', .' + DOMClasses.inProgress) - .addClass(DOMClasses.inProgress) - .find(DOMStrings.productListReviewsContainer); - - return $productListReviews; - } - - function addProductsIDs() { - - var $productsList = getNewProductsReviewsElements(), - seenIds = {}; - - $productsList.each(function () { - var id = $(this).data('id'); - seenIds[id] = true; - }); - - - var IDsArray = Object.keys(seenIds).filter(e => e !== 'undefined'); - var prevDataIDs = data.productIDs.splice(0); - data.productIDs = prevDataIDs.concat(IDsArray); - - if (!data.commentsLoadingInProgress) { - loadProductsData(); - } - } - - function loadProductsData() { - if (data.productIDs.length === 0) - return; - - data.commentsLoadingInProgress = true; - - var dataIDsCopy = data.productIDs.slice(0); - selectedProductIDs = dataIDsCopy.splice(0, data.ajaxIDsLimit); - - - $.get(data.ajaxUrl, { id_products: selectedProductIDs }, function (jsonData) { - if (jsonData) { - $.each(jsonData.products, function(i, elem) { - var productData = elem; - var $productsReviewsContainer = $('.product-list-reviews[data-id="' + productData.id_product + '"]'); - - $productsReviewsContainer.each(function () { - var $self = $(this); - - if (productData.comments_nb > 0) { - $self.find(DOMStrings.productListReviewsStarsContainer).rating({ grade: productData.average_grade, starWidth: 16 }); - $self.find(DOMStrings.productListReviewsNumberOfComments).text('(' + productData.comments_nb + ')'); - $self.closest(DOMStrings.productContainer).addClass(DOMClasses.hasReviews); - $self.css('visibility', 'visible'); - } - - $self.closest(DOMStrings.productContainer).addClass(DOMClasses.reviewsLoaded); - $self.closest(DOMStrings.productContainer).removeClass(DOMClasses.inProgress); - - }); - data.productIDs.shift(); - }); - - data.commentsLoadingInProgress = false; - if (data.productIDs.length > 0) { - loadProductsData(); - } - - } - }); - } - - - return { - load: function () { - addProductsIDs(); - }, - init: function () { - setAjaxUrl(); - setEvents(); - } - } -})();