> Zencart中文手册 > 让zen cart商品评论显示在商品详情页面

注意:有些标点字符要换成英文格式,否则会错。希望有需要的人能顺利解决在zen cart商品页面显示评论的功能。

操作步骤如下:

1,从includesmodulespages product_reviewsproduct_reviews page,这里复制以下代码至includesmodulespagesproduct_infoheader.PHP中(注意要放在PHP代码里面.)

$review_status = ” AND r.status = 1″;

$reviews_query_raw = “SELECT r.reviews_id, left(rd.reviews_text, 300) as reviews_text, r.reviews_rating, r.date_added, r.customers_name

FROM ” . TABLE_REVIEWS . ” r, ” . TABLE_REVIEWS_DESCRIPTION . ” rd

WHERE r.products_id = :productsID

AND r.reviews_id = rd.reviews_id

AND rd.languages_id = :languagesID ” . $review_status . ”

ORDER BY r.reviews_id desc”;

$reviews_query_raw = $db->bindVars($reviews_query_raw, ‘:productsID’, $_GET['products_id'], ‘integer’);

$reviews_query_raw = $db->bindVars($reviews_query_raw, ‘:languagesID’, $_session['languages_id'], ‘integer’);

$reviews_split = new splitPageResults($reviews_query_raw, MAX_DISPLAY_NEW_REVIEWS);

$reviews = $db->Execute($reviews_split->sql_query);

$reviewsArray = array();

while (!$reviews->EOF) {

$reviewsArray[] = array(‘id’=>$reviews->fields['reviews_id'],

‘customersName’=>$reviews->fields['customers_name'],

‘dateAdded’=>$reviews->fields['date_added'],

‘reviewsText’=>$reviews->fields['reviews_text'],

‘reviewsRating’=>$reviews->fields['reviews_rating']);

$reviews->MoveNext();

}

2,从这里includestemplates YOUR_TEMPLATE_NAMEtemplatestpl_product_reviews_default.php复制以下以下代码至: includestemplatesCUSTOMtemplatestpl_product_info_display.php

Reviews

if ($reviews_split->number_of_rows > 0) {

if ((PREV_NEXT_BAR_LOCATION == ‘1′) || (PREV_NEXT_BAR_LOCATION == ‘3′)) {

?>

display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?>

display_links(MAX_DISPLAY_PAGE_LINKS, zen_get_all_get_params(array(‘page’, ‘info’, ‘main_page’))); ?>

}

foreach ($reviewsArray as $reviews) {

?>

’ . zen_image_button(BUTTON_IMAGE_READ_REVIEWS , BUTTON_READ_REVIEWS_ALT) . ‘’; ?>

–>

’) . ((strlen($reviews['reviewsText']) >= 300) ? ‘…’ : ”); ?>

}

?>

} else {

?>

’ . TEXT_APPROVAL_REQUIRED: ”); ?>

}

if (($reviews_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == ‘2′) || (PREV_NEXT_BAR_LOCATION == ‘3′))) {

?>

display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?>

display_links(MAX_DISPLAY_PAGE_LINKS, zen_get_all_get_params(array(‘page’, ‘info’, ‘main_page’))); ?>

}

?>

’ . zen_image_button(BUTTON_IMAGE_WRITE_REVIEW, BUTTON_WRITE_REVIEW_ALT) . ‘’; ?>

for

3,大功完成80%,TEXT_OF_5_STARS这样显示不太好,所以最后让我们来完善语言项,找到语言文件includes/languages/english/product_info.php的结尾处加入代码:

//bof product reviews

define('TEXT_OF_5_STARS', '%s of 5 Stars');

//eof product reviews

4,完成。

上一篇: