让zen cart商品评论显示在商品详情页面

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

操作步骤如下:

1,从\includes\modules\pages \product_reviews\product_reviews page,这里复制以下代码至\includes\modules\pages\product_info\header.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,从这里\includes\templates \YOUR_TEMPLATE_NAME\templates\tpl_product_reviews_default.php复制以下以下代码至: \includes\templates\CUSTOM\templates\tpl_product_info_display.php

<!– bof product reviews–>
<div id=”reviewsDefault”>
<h3 id=”productReviewsDefaultHeading”><?php echo $products_name . $products_model; ?> Reviews</h3>
<?php
  if ($reviews_split->number_of_rows > 0) {
    if ((PREV_NEXT_BAR_LOCATION == ‘1′) || (PREV_NEXT_BAR_LOCATION == ‘3′)) {
?>

<div id=”productReviewsDefaultListingTopNumber”><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></div>

<div id=”productReviewsDefaultListingTopLinks”><?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><?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><?php echo sprintf(TEXT_REVIEW_DATE_ADDED, zen_date_short($reviews['dateAdded'])); ?>&nbsp;<?php echo sprintf(TEXT_REVIEW_BY, zen_output_string_protected($reviews['customersName'])); ?></div>

<div><?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><?php echo zen_break_string(zen_output_string_protected(stripslashes($reviews['reviewsText'])), 60, ‘-<br />’) . ((strlen($reviews['reviewsText']) >= 300) ? ‘…’ : ”); ?> </div>

<br />
<?php
    }
?>
<?php
  } else {
?>
<hr />
<div id=”productReviewsDefaultNoReviews”><?php echo TEXT_NO_REVIEWS . (REVIEWS_APPROVAL == ‘1′ ? ‘<br />’ . TEXT_APPROVAL_REQUIRED: ”); ?></div>
<br />
<?php
  }

  if (($reviews_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == ‘2′) || (PREV_NEXT_BAR_LOCATION == ‘3′))) {
?>
<hr />
<div id=”productReviewsDefaultListingBottomNumber”><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></div>
<div id=”productReviewsDefaultListingBottomLinks”><?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
  }
?>

 <div><?php echo ‘<a href=”‘ . zen_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, zen_get_all_get_params(array(‘reviews_id’))) . ‘”>’ . zen_image_button(BUTTON_IMAGE_WRITE_REVIEW, BUTTON_WRITE_REVIEW_ALT) . ‘</a>’; ?><br /><div style=”font-style: italic; color: green”>for <?php echo $products_name . $products_model; ?></div></div>

</div>
<!– eof product reviews–>

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,完成。

你可能感兴趣的:(ca)