你现在的位置:首页 > PHP网站建设知识库 > ZenCart > 正文

zencart商品评论显示在商品详情页面

zencart里,操作步骤如下: 

A. 从\includes\modules\pages\product_reviews\product_reviews page,这里复制以下代码至\includes\modules\pages\product_info\header_php.php中(注意要放在PHP代 码里面) 

$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(); 

B. 从这里\includes\templates\YOUR_TEMPLATE_NAME\templates \tpl_product_reviews_default.php复制以下以下代码至:\includes\templates\CUSTOM \templates\tpl_product_info_display.php 

<!--bof Reviews button and count--> 
 
<!-- 
<h1 id="productReviewsDefaultHeading"><?php echo $products_name . $products_model; ?></h1> 
 
<h2 id="productReviewsDefaultPrice" class=""><?php echo $products_price; ?></h2> 
--> 
<br class="clearBoth" /> 
<h1><?php echo $products_name ."的所有评论";?></h1> 
<?php 
  if ($reviews_split->number_of_rows > 0) { 
    if ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3')) { 
?> 
 
<div id="productReviewsDefaultListingTopNumber" class="navSplitPagesResult"><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></div> 
 
<div id="productReviewsDefaultListingTopLinks" class="navSplitPagesLinks"><?php echo TEXT_RESULT_PAGE . ' ' . $reviews_split->display_links(MAX_DISPLAY_PAGE_LINKS, zen_get_all_get_params(array('page', 'info', 'main_page'))); ?></div> 
 
<?php 
    } 
    foreach ($reviewsArray as $reviews) { 
?> 
<hr /> 
<!-- 
<div class="buttonRow forward"><?php echo '<a href="' . zen_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . (int)$_GET['products_id'] . '&reviews_id=' . $reviews['id']) . '">' . zen_image_button(BUTTON_IMAGE_READ_REVIEWS , BUTTON_READ_REVIEWS_ALT) . '</a>'; ?></div> 
--> 
<div class="productReviewsDefaultReviewer bold"><?php echo sprintf(TEXT_REVIEW_DATE_ADDED, zen_date_short($reviews['dateAdded'])); ?> <?php echo sprintf(TEXT_REVIEW_BY, zen_output_string_protected($reviews['customersName'])); ?></div> 
 
<div class="rating"><?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $reviews['reviewsRating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews['reviewsRating'])), sprintf(TEXT_OF_5_STARS, $reviews['reviewsRating']); ?></div> 
 
<div class="productReviewsDefaultProductMainContent content"><?php echo zen_break_string(zen_output_string_protected(stripslashes($reviews['reviewsText'])), 60, '-<br />') . ((strlen($reviews['reviewsText']) >= 100) ? '...' : ''); ?></div> 
 
 
<br class="clearBoth" /> 
<?php 
    } 
?> 
<?php 
  } else { 
?> 
<hr /> 
<div id="productReviewsDefaultNoReviews" class="content"><?php echo TEXT_NO_REVIEWS . (REVIEWS_APPROVAL == '1' ? '<br />' . TEXT_APPROVAL_REQUIRED: ''); ?></div> 
<br class="clearBoth" /> 
<?php 
  } 
 
  if (($reviews_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) { 
?> 
<hr /> 
<div id="productReviewsDefaultListingBottomNumber" class="navSplitPagesResult"><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></div> 
<div id="productReviewsDefaultListingBottomLinks" class="navSplitPagesLinks"><?php echo TEXT_RESULT_PAGE . ' ' . $reviews_split->display_links(MAX_DISPLAY_PAGE_LINKS, zen_get_all_get_params(array('page', 'info', 'main_page'))); ?></div> 
 
<?php 
  } 
?> 
<?php 
 
  if ($flag_show_product_info_reviews == 1) { 
    // if more than 0 reviews, then show reviews button; otherwise, show the "write review" button 
    if ($reviews->fields['count'] > 0 ) { ?> 
<div id="productReviewLink" class="buttonRow back"> 
    <?php echo '<a href="' . zen_href_link(FILENAME_PRODUCT_REVIEWS, zen_get_all_get_params()) . '">' . zen_image_button(BUTTON_IMAGE_REVIEWS, BUTTON_REVIEWS_ALT) . '</a>'; ?> 
    </div> 
<br class="clearBoth" /> 
<p class="reviewCount"><?php echo ($flag_show_product_info_reviews_count == 1 ? TEXT_CURRENT_REVIEWS . ' ' . $reviews->fields['count'] : ''); ?></p> 
<?php } else { ?> 
<div id="productReviewLink" class="buttonRow back"><?php echo '<a href="' . zen_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, zen_get_all_get_params(array())) . '">' . zen_image_button(BUTTON_IMAGE_WRITE_REVIEW, BUTTON_WRITE_REVIEW_ALT) . '</a>'; ?></div> 
<br class="clearBoth" /> 
<?php 
  } 

?> 
<!--eof Reviews button and count --> 

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. 大功告成,刷新看看效果吧。