我正在尝试调整产品评论“添加评论功能”(位于“产品”页面上)以在“产品列表”页面上工作,但该链接仅识别列表中的第一个产品。列表中的每个产品旁边都有一个铅笔图标链接,但它们都只链接到第一个产品。
任何人都可以让我知道为什么会这样,并指出我正确的方向来解决它。
以下是我的自定义挂钩中的代码:
include_once dirname(__FILE__).'/ProductComment.php';
include_once dirname(__FILE__).'/ProductCommentCriterion.php';
if(in_array($this->context->controller->php_self, array('product-list'))) $products = Product::getProducts((int) Tools::getValue('id_product'), $this->context->language->id);
{
$id_guest = (!$id_customer = (int) $this->context->cookie->id_customer) ? (int) $this->context->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int) (Tools::getValue('id_product')), (int) $this->context->cookie->id_customer, true, (int) $id_guest);
$average = ProductComment::getAverageGrade((int) Tools::getValue('id_product'));
$image = Product::getCover((int) Tools::getValue('id_product'));
$cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], 'medium_default');
$this->context->smarty->assign(array(
'id_product_comment_form' => (int) Tools::getValue('id_product'),
'product' => $products,
'secure_key' => $this->secure_key,
'logged' => $this->context->customer->isLogged(true),
'allow_guests' => (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'productcomment_cover' => (int) Tools::getValue('id_product').'-'.(int) $image['id_image'], // retro compat
'productcomment_cover_image' => $cover_image,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'criterions' => ProductCommentCriterion::getByProduct((int) Tools::getValue('id_product'), $this->context->language->id),
'action_url' => '',
'averageTotal' => round($average['grade']),
'ratings' => ProductComment::getRatings((int) Tools::getValue('id_product')),
'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'nbComments' => (int) (ProductComment::getCommentNumber((int) Tools::getValue('id_product'))),
));
return $this->display(__FILE__, '/mytemplate.tpl');
}
这是我模板中的代码:
<SCRIPT>
$(document).ready(function() {
if (!!$.prototype.fancybox)
$('.open-comment-form').fancybox({
'autoSize' : false,
'width': 800,
'height': auto,
'hideOnContentClick': false,
'title' : null,
});
});
</SCRIPT>
{if (!$too_early AND ($is_logged OR ($PRODUCT_COMMENTS_ALLOW_GUESTS == 0)))}
<p class="align_center">
<a class="open-comment-form" href="#new_comment_form" title="{l s='Write your review' mod='productcomments'}!"></a>
</p>
{/if}
我正在使用Prestashop版本1.6.1.14。谢谢aussiecomet