zencart商品页面显示购买记录

2012-06-20 14:50 来源:www.chinab4c.com 作者:zencart专家

   zencart商品页面购买记录这个功能是必须的。目前默认的zen cart商品页面他是不显示商品的购买记录的。为了让zen cart商品页面显示该商品的购买记录,我们特意开发了该程序,对zencart二次开发.

  1:includes/templates/template_default/templates/tpl_product_info_display.php增加以下代码

   require($template->get_template_dir('tpl_modules_buy_record.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_buy_record.php');

  2:新建includes/templates/template_default/templates/tpl_modules_buy_record.php

   <?php  include(DIR_WS_MODULES . "buy_recode.php");
  ?>

<div class="centerBoxWrapper" id="alsoPurchased">
<?php
 
  require($template->get_template_dir('tpl_buy_record.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_buy_record.php');
?>
</div>

 3:includes/templates/template_default/common/tpl_buy_record.php

<?php

  if ($title) {
  ?>
<?php echo $title; ?>

<table>
<tr><td>购买人</td><td>商品名</td><td>数量</td><td>时间</td></tr>
<?php

if (is_array($list_box_contents) > 0 ) {
 for($row=0;$row<sizeof($list_box_contents);$row++) {
   ?>
   <tr><td><? echo substr($list_box_contents[$row]['customers_name'],2)."***";?></td><td><? echo $list_box_contents[$row]['products_name'];?></td><td><? echo $list_box_contents[$row]['products_quantity'];?></td><td><? echo $list_box_contents[$row]['date_purchased'];?></td></tr>
   <?
?>
</table>
<br class="clearBoth" />
<?php
  }
}
  }
?> 
4:includes/modules/buy_recode.php

<?php

if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

if (isset($_GET['products_id'])) {

  $also_purchased_products = $db->Execute("select o.customers_name , o.date_purchased , op.products_quantity ,op.products_name from ".TABLE_ORDERS."  o , ".TABLE_ORDERS_PRODUCTS." op where o.orders_id = op.orders_id and op.products_id = '".$_GET['products_id']."' order by o.orders_id desc limit 10");
 
  $num_products_ordered = $also_purchased_products->RecordCount();


  $list_box_contents = array();
  $title = '';
//  
  // show only when 1 or more and equal to or greater than minimum set in admin
   while (!$also_purchased_products->EOF) {
 
      $list_box_contents[] = $also_purchased_products->fields;
      $also_purchased_products->MoveNext();
    }
  if ($also_purchased_products->RecordCount() > 0) {

    $title = '<h2 class="centerBoxHeading">购买记录</h2>';
   
  }

}
?>

来源:http://www.chinab4c.com