升级到 1.8 后"add your review"产品视图页面中的链接不起作用



我最近从magento 1.5升级到1.8,升级"add your review"链接后返回类似/review/product/list/id/250/#review-form的URL。这个URL显示了一个2列右侧模板,其中我的页面是2列左侧设计。。。。在升级之前,我使用以下方法在产品视图页面上显示评论。

在关闭catalog.xml中的"catalog_product_view"句柄之前,我添加了以下代码。

<block type="review/product_view_list" name="product.info.product_additional_data" as="product_review" template="review/product/view/list.phtml">
<block type="review/form" name="product.review.form" as="review_form"/>
</block> 

然后在目录/产品下的view.phtml中添加一个调用

<?php echo $this->getChildHtml('product_review') ?> 

在1.5版本中一切都很好,当点击"添加您的评论"链接时,它会返回类似www.mystore/product URL|#review-form的URl(这与1.8版本不同),因此显示屏只会跳转到同一页面上ID"评论表单"定义的页面位置,而不是1.8版本那样的新URl。。

我已经检查了"add your review"链接是由函数"getReviewsSummaryHtml"生成的,该函数没有从1.5更改为1.8。review.xml从1.5到1.8也没有任何变化。所以我迷路了。

我的1.5版本是由其他开发人员创建的,在使用上述方法在产品页面上显示评论之前,可能需要在其他地方做一些事情。。。。为什么相同的函数getReviewsSummaryHtml返回不同的URL,代码从1.5到1.8看起来是一样的?

我找到了答案。在我的1.5主题下,有一个模板/review/helper/summary.phtml,它最终被getReviewSummaryHtml函数调用,并覆盖其基本文件。带有以下代码的

<p class="rating-links">
<a href="#customer-reviews"><?php echo $this->__('%d Review(s)', $this->getReviewsCount()) ?></a>
<span class="separator">|</span>
<a href="#review-form"><?php echo $this->__('Add Your Review') ?></a>
</p>

它将直接ID分配给相应的链接并跳转到产品视图页面上的评论部分,而不是在基本设计中加载评论/产品/列表页面。升级后,我没有将summary.phtml文件复制到我的主题中。。。。希望这能帮助那些使用上述方法在产品视图页面上显示评论的人。。。

我在Magento2上遇到了类似的问题,在我的情况下,自定义选项卡的名称不同,必须覆盖文件

vendor/magento/module-review/frontend/web/js/process-reviews.js

$(function () {
$('.product-info-main .reviews-actions a').click(function (event) {
var acnchor;
event.preventDefault();
acnchor = $(this).attr('href').replace(/^.*?(#|$)/, '');
$('.product.data.items [data-role="content"]').each(function (index) { //eslint-disable-line
if (this.id == 'smarttabs.reviews.tab') {
$('.product.data.items').tabs('activate', index);
$('html, body').animate({
scrollTop: $('#' + acnchor).offset().top - 50
}, 300);
}
});
});
});

也许它会帮助某人:)

最新更新