1

On Product Page I want to display the reviews related to product. Right now they are displayed on click function. This are the functions through which reviews are displayed.

 define([
'jquery'
 ], function ($) {
'use strict';

function processReviews(url, fromPages) {
    $.ajax({
        url: url,
        cache: true,
        dataType: 'html',
        showLoader: false,
        loaderContext: $('.product.data.items')
    }).done(function (data) {
        $('#product-review-container').html(data);
        $('[data-role="product-review"] .pages a').each(function (index, element) {
            $(element).click(function (event) { //eslint-disable-line max-nested-callbacks
                processReviews($(element).attr('href'), true);
                event.preventDefault();
            });
        });
    }).complete(function () {
        if (fromPages == true) { //eslint-disable-line eqeqeq
            $('html, body').animate({
                scrollTop: $('#reviews').offset().top - 50
            }, 300);
        }
    });
}

return function (config) {
    var reviewTab = $(config.reviewsTabSelector),
        requiredReviewTabRole = 'tab';

    if (reviewTab.attr('role') === requiredReviewTabRole && reviewTab.hasClass('opened')) {
        processReviews(config.productReviewUrl);
    } else {
        reviewTab.one('beforeOpen', function () {
            processReviews(config.productReviewUrl);
        });
    }

    $(function () {
        $('.product-info-main .reviews-actions a').click(function (event) {
            var anchor;

            event.preventDefault();
            anchor = $(this).attr('href').replace(/^.*?(#|$)/, '');
            $('.product.data.items [data-role="content"]').each(function (index) { //eslint-disable-line
                if (this.id == 'reviews') { //eslint-disable-line eqeqeq
                    $('.product.data.items').tabs('activate', index);
                    $('html, body').animate({
                        scrollTop: $('#' + anchor).offset().top - 120
                    }, 300);
                }
            });
        });
        
    });
};

});

1
  • What is this file name and location ? Are you getting this "dsads" in alert ? Jun 17, 2021 at 10:12

1 Answer 1

1

We can force the code to trigger the click by adding this code

$("document").ready(function() {
    $(".product-info-main .reviews-actions a").trigger('click');
});

And also you may remove the animate to scrollbar

   $('html, body').animate({
                        scrollTop: $('#' + anchor).offset().top - 120
                    }, 300);
2
  • tried but not working
    – Asssd
    Jun 17, 2021 at 11:59
  • My solution was not just copy paste, please tell me what error you getting in your console. May be you need setTimeout please check this link - stackoverflow.com/questions/2060019/… Jun 17, 2021 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.