ecshop二次开发——为用户提供商品批注功能

原创 2013年11月26日 10:48:02

需求:

1. 每个登录的用户在购物过程中的商品列表页、商品详细页、购物车都可以对商品进行批注;

2. 要求1中的批注会显示在订单中每个商品项中;

3. 用户每次登陆之后清除上次的批注。


修改方法:

【1】增加两个表:
-- ----------------------------
-- Table structure for `order_comment`
-- ----------------------------
DROP TABLE IF EXISTS `order_comment`;
CREATE TABLE `order_comment` (
  `order_id` mediumint(8) NOT NULL,
  `goods_id` mediumint(8) NOT NULL,
  `goods_comment` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`order_id`,`goods_id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;


-- ----------------------------
-- Table structure for `goods_comment`
-- ----------------------------
DROP TABLE IF EXISTS `goods_comment`;
CREATE TABLE `goods_comment` (
  `goods_id` mediumint(8) NOT NULL,
  `user_id` mediumint(8) NOT NULL,
  `goods_comment` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`goods_id`,`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;


【2】themes\default\library\goods_list.lbi文件中:
<a href="javascript:;" id="compareLink" onClick="Compare.add({$goods.goods_id},'{$goods.goods_name|escape:"html"}','{$goods.type}')" class="f6">{$lang.compare}</a>
后边增加:
           <!--{if $smarty.session.user_id}-->
           {$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
           <br />
           <!--{/if}-->


【3】themes\default\user_transaction.dwt文件中:
<th width="23%" align="center" bgcolor="#ffffff">{$lang.goods_name}</th>
            <th width="29%" align="center" bgcolor="#ffffff">{$lang.goods_attr}</th>
后面增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->


在:
<td align="left" bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              {$goods.goods_comment}
               </td>
              <!--{/if}-->


【4】themes\default\goods.dwt文件中:
<li class="padd">
      <a href="javascript:addToCart({$goods.goods_id})"><img src="images/bnt_cat.gif" /></a>
      <a href="javascript:collect({$goods.goods_id})"><img src="images/bnt_colles.gif" /></a>
      <!-- {if $affiliate.on} -->
      <a href="user.php?act=affiliate&goodsid={$goods.goods_id}"><img src='images/bnt_recommend.gif'></a>
      <!-- {/if} -->
      </li>
后边增加:
<li>
      <!--{if $smarty.session.user_id}-->
      {$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
      <!--{/if}-->
      </li>


【5】themes\default\flow.dwt文件中:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
      <!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
              <th bgcolor="#ffffff">{$lang.goods_attr}</th>
              <!-- {/if} -->
后边增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->


在:
<!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
              <td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
<!--{/if}-->
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              <textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
               </td>
              <!-- {/if} -->


在:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
              <th bgcolor="#ffffff">{$lang.goods_attr}</th>
后边增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->


在:
<!-- {if $goods.is_shipping} -->(<span style="color:#FF0000">{$lang.free_goods}</span>)<!-- {/if} -->
              </td>
              <td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              <textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
               </td>
              <!--{/if}-->


【6】languages\zh_cn\admin\common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';


【7】languages\zh_cn\common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';


【8】js\common.js文件中增加:
/*
 * 将用户对商品的批注写到数据库中 
 */
function addGoodsComment(obj, goodsId)
{
    /* 保存原始的内容 */
    var orgComment = obj.value;


    /* 编辑区失去焦点的处理函数 */
    obj.onblur = function(e)
    {
        var newComment = obj.value;
 
        if (newComment != orgComment)
        {
            res = Ajax.call("./goods.php?is_ajax=1", "act=edit_goods_comment&val=" + encodeURIComponent(Utils.trim(newComment)).toJSONString() + "&id=" +goodsId, null, "POST", "JSON", false);


            if (res.message)
            {
                alert(res.message);
            }
        }  
    }
}


【9】includes\lib_order.php文件中:
$sql = "SELECT rec_id, goods_id, goods_name, goods_sn, market_price, goods_number, " .
            "goods_price, goods_attr, is_real, parent_id, is_gift, " .
            "goods_price * goods_number AS subtotal, extension_code " .
            "FROM " . $GLOBALS['ecs']->table('order_goods') .
            " WHERE order_id = '$order_id'";
改为:
$sql = "SELECT rec_id, order_goods.goods_id, goods_name, goods_sn, market_price, goods_number, " .
            "goods_price, goods_attr, is_real, parent_id, is_gift, " .
            "goods_price * goods_number AS subtotal, extension_code, oc.goods_comment " .
            "FROM " . $GLOBALS['ecs']->table('order_goods') . " " .
            "LEFT JOIN order_comment as oc ON oc.goods_id = order_goods.goods_id AND oc.order_id = '" . $order_id . "' ".
            "WHERE order_goods.order_id = '$order_id'";


将:
$sql = "SELECT rec_id, user_id, goods_id, goods_name, goods_sn, goods_number, " .
            "market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, is_shipping, " .
            "goods_price * goods_number AS subtotal " .
            "FROM " . $GLOBALS['ecs']->table('cart') .
            " WHERE session_id = '" . SESS_ID . "' " .
            "AND rec_type = '$type'";
改为:
$sql = "SELECT rec_id, cart.user_id, cart.goods_id, goods_name, goods_sn, goods_number, " .
            "market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, is_shipping, " .
            "goods_price * goods_number AS subtotal, gc.goods_comment " .
            "FROM " . $GLOBALS['ecs']->table('cart') . " " .
            "LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id ".
            "WHERE session_id = '" . SESS_ID . "' " .
            "AND rec_type = '$type'";


将:
/* 循环、统计 */
    $sql = "SELECT *, IF(parent_id, parent_id, goods_id) AS pid " .
            " FROM " . $GLOBALS['ecs']->table('cart') . " " .
            " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'" .
            " ORDER BY pid, parent_id";
改为:
/* 循环、统计 */
    $sql = "SELECT *, IF(parent_id, parent_id, cart.goods_id) AS pid, gc.goods_comment " .
            " FROM " . $GLOBALS['ecs']->table('cart') . " " .
            "LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id ".
            "WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'" .
            "ORDER BY pid, parent_id";


【10】includes\lib_goods.php文件中:
$sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, m.type_money AS bonus_money, ' .
                'IFNULL(AVG(r.comment_rank), 0) AS comment_rank, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price " .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('comment') . ' AS r '.
                'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('bonus_type') . ' AS m ' .
                "ON g.bonus_type_id = m.type_id AND m.send_start_date <= '$time' AND m.send_end_date >= '$time'" .
            " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
                    "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
            "WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " .
            "GROUP BY g.goods_id";
改为:
$sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, m.type_money AS bonus_money, ' .
                'IFNULL(AVG(r.comment_rank), 0) AS comment_rank, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price, gc.goods_comment " .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('comment') . ' AS r '.
                'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('bonus_type') . ' AS m ' .
                "ON g.bonus_type_id = m.type_id AND m.send_start_date <= '$time' AND m.send_end_date >= '$time'" .
            " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
                    "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
            "LEFT JOIN goods_comment as gc ON gc.goods_id = g.goods_id AND gc.user_id = '" . $_SESSION[user_id] . "' ".
            "WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " .
            "GROUP BY g.goods_id";


【11】includes\cls_template.php文件中:
注释掉:
if (file_put_contents($hash_dir . '/' . $cachename . '.php', '<?php exit;?>' . $data . $out, LOCK_EX) === false)
                        {
                            trigger_error('can\'t write:' . $hash_dir . '/' . $cachename . '.php');
                        }


【12】includes\cls_mysql.php文件中:
var $max_cache_time的值改为0。如下:
var $max_cache_time = 0; // 最大的缓存时间,以秒为单位


【13】data\order_print.html文件中:
<table width="100%" border="1" style="border-collapse:collapse;border-color:#000;">
    <tr align="center">
        <td bgcolor="#cccccc">{$lang.goods_name}  <!-- 商品名称 --></td>
        <td bgcolor="#cccccc">{$lang.goods_sn}    <!-- 商品货号 --></td>
        <td bgcolor="#cccccc">{$lang.goods_attr}  <!-- 商品属性 --></td>
        <td bgcolor="#cccccc">{$lang.goods_price} <!-- 商品单价 --></td>
        <td bgcolor="#cccccc">{$lang.goods_number}<!-- 商品数量 --></td>
        <td bgcolor="#cccccc">{$lang.subtotal}    <!-- 价格小计 --></td>
    </tr>
    <!-- {foreach from=$goods_list item=goods key=key} -->
    <tr>
        <td>&nbsp;{$goods.goods_name}<!-- 商品名称 -->
        {if $goods.is_gift}{if $goods.goods_price gt 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
        {if $goods.parent_id gt 0}{$lang.remark_fittings}{/if}
        </td>
        <td>&nbsp;{$goods.goods_sn} <!-- 商品货号 --></td>
        <td><!-- 商品属性 -->
        <!-- {foreach key=key from=$goods_attr[$key] item=attr} -->
        <!-- {if $attr.name} --> {$attr.name}:{$attr.value} <!-- {/if} -->
        <!-- {/foreach} -->
        </td>
        <td align="right">{$goods.formated_goods_price}&nbsp;<!-- 商品单价 --></td>
        <td align="right">{$goods.goods_number}&nbsp;<!-- 商品数量 --></td>
        <td align="right">{$goods.formated_subtotal}&nbsp;<!-- 商品金额小计 --></td>
    </tr>
    <!-- {/foreach} -->
    <tr>
        <!-- 发票抬头和发票内容 -->
        <td colspan="4">
        {if $order.inv_payee}
        {$lang.label_inv_payee}{$order.inv_payee}&nbsp;&nbsp;&nbsp;
        {$lang.label_inv_content}{$order.inv_content}
        {/if}
        </td>
        <!-- 商品总金额 -->
        <td colspan="2" align="right">{$lang.label_goods_amount}{$order.formated_goods_amount}</td>
    </tr>
</table>
改为:
<table width="100%" border="1" style="border-collapse:collapse;border-color:#000;">
    <tr align="center">
        <td bgcolor="#cccccc">{$lang.goods_name}  <!-- 商品名称 --></td>
        <td bgcolor="#cccccc">{$lang.goods_sn}    <!-- 商品货号 --></td>
        <td bgcolor="#cccccc">{$lang.goods_attr}  <!-- 商品属性 --></td>
<td bgcolor="#cccccc">{$lang.my_goods_comment} <!-- 个人批注 --></td>
        <td bgcolor="#cccccc">{$lang.goods_price} <!-- 商品单价 --></td>
        <td bgcolor="#cccccc">{$lang.goods_number}<!-- 商品数量 --></td>
        <td bgcolor="#cccccc">{$lang.subtotal}    <!-- 价格小计 --></td>
    </tr>
    <!-- {foreach from=$goods_list item=goods key=key} -->
    <tr>
        <td>&nbsp;{$goods.goods_name}<!-- 商品名称 -->
        {if $goods.is_gift}{if $goods.goods_price gt 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
        {if $goods.parent_id gt 0}{$lang.remark_fittings}{/if}
        </td>
        <td>&nbsp;{$goods.goods_sn} <!-- 商品货号 --></td>
        <td><!-- 商品属性 -->
        <!-- {foreach key=key from=$goods_attr[$key] item=attr} -->
        <!-- {if $attr.name} --> {$attr.name}:{$attr.value} <!-- {/if} -->
        <!-- {/foreach} -->
        </td>
<td align="right">{$goods.goods_comment}&nbsp;<!-- 个人批注 --></td>
        <td align="right">{$goods.formated_goods_price}&nbsp;<!-- 商品单价 --></td>
        <td align="right">{$goods.goods_number}&nbsp;<!-- 商品数量 --></td>
        <td align="right">{$goods.formated_subtotal}&nbsp;<!-- 商品金额小计 --></td>
    </tr>
    <!-- {/foreach} -->
    <tr>
        <!-- 发票抬头和发票内容 -->
        <td colspan="4">
        {if $order.inv_payee}
        {$lang.label_inv_payee}{$order.inv_payee}&nbsp;&nbsp;&nbsp;
        {$lang.label_inv_content}{$order.inv_content}
        {/if}
        </td>
        <!-- 商品总金额 -->
        <td colspan="2" align="right">{$lang.label_goods_amount}{$order.formated_goods_amount}</td>
    </tr>
</table>


【14】admin\templates\order_info.htm文件中:
<table width="100%" cellpadding="3" cellspacing="1">
  <tr>
    <th colspan="8" scope="col">{$lang.goods_info}<a href="order.php?act=edit&order_id={$order.order_id}&step=goods" class="special">{$lang.edit}</a></th>
    </tr>
  <tr>
    <td scope="col"><div align="center"><strong>{$lang.goods_name_brand}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_sn}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.product_sn}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_price}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_number}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_attr}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.storage}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.subtotal}</strong></div></td>
  </tr>
  {foreach from=$goods_list item=goods}
  <tr>
    <td>
    {if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
    <a href="../goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
    {if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
    {if $goods.parent_id > 0}{$lang.remark_fittings}{/if}</a>
    {elseif $goods.goods_id gt 0 && $goods.extension_code eq 'package_buy'}
    <a href="javascript:void(0)" onclick="setSuitShow({$goods.goods_id})">{$goods.goods_name}<span style="color:#FF0000;">{$lang.remark_package}</span></a>
    <div id="suit_{$goods.goods_id}" style="display:none">
        {foreach from=$goods.package_goods_list item=package_goods_list}
          <a href="../goods.php?id={$package_goods_list.goods_id}" target="_blank">{$package_goods_list.goods_name}</a><br />
        {/foreach}
    </div>
    {/if}
    </td>
    <td>{$goods.goods_sn}</td>
    <td>{$goods.product_sn}</td>
    <td><div align="right">{$goods.formated_goods_price}</div></td>
    <td><div align="right">{$goods.goods_number}
    </div></td>
    <td>{$goods.goods_attr|nl2br}</td>
    <td><div align="right">{$goods.storage}</div></td>
    <td><div align="right">{$goods.formated_subtotal}</div></td>
  </tr>
  {/foreach}
  <tr>
    <td></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>{if $order.total_weight}<div align="right"><strong>{$lang.label_total_weight}
    </strong></div>{/if}</td>
    <td>{if $order.total_weight}<div align="right">{$order.total_weight}
    </div>{/if}</td>
    <td>&nbsp;</td>
    <td><div align="right"><strong>{$lang.label_total}</strong></div></td>
    <td><div align="right">{$order.formated_goods_amount}</div></td>
  </tr>
</table>
改为:
<table width="100%" cellpadding="3" cellspacing="1">
  <tr>
    <th colspan="9" scope="col">{$lang.goods_info}<a href="order.php?act=edit&order_id={$order.order_id}&step=goods" class="special">{$lang.edit}</a></th>
    </tr>
  <tr>
    <td scope="col"><div align="center"><strong>{$lang.goods_name_brand}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_sn}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.product_sn}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_price}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_number}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_attr}</strong></div></td>
<td scope="col"><div align="center"><strong>{$lang.my_goods_comment}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.storage}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.subtotal}</strong></div></td>
  </tr>
  {foreach from=$goods_list item=goods}
  <tr>
    <td>
    {if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
    <a href="../goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
    {if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
    {if $goods.parent_id > 0}{$lang.remark_fittings}{/if}</a>
    {elseif $goods.goods_id gt 0 && $goods.extension_code eq 'package_buy'}
    <a href="javascript:void(0)" onclick="setSuitShow({$goods.goods_id})">{$goods.goods_name}<span style="color:#FF0000;">{$lang.remark_package}</span></a>
    <div id="suit_{$goods.goods_id}" style="display:none">
        {foreach from=$goods.package_goods_list item=package_goods_list}
          <a href="../goods.php?id={$package_goods_list.goods_id}" target="_blank">{$package_goods_list.goods_name}</a><br />
        {/foreach}
    </div>
    {/if}
    </td>
    <td>{$goods.goods_sn}</td>
    <td>{$goods.product_sn}</td>
    <td><div align="right">{$goods.formated_goods_price}</div></td>
    <td><div align="right">{$goods.goods_number}
    </div></td>
    <td>{$goods.goods_attr|nl2br}</td>
<td><div align="right">{$goods.goods_comment}</div></td>
    <td><div align="right">{$goods.storage}</div></td>
    <td><div align="right">{$goods.formated_subtotal}</div></td>
  </tr>
  {/foreach}
  <tr>
    <td></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>{if $order.total_weight}<div align="right"><strong>{$lang.label_total_weight}
    </strong></div>{/if}</td>
    <td>{if $order.total_weight}<div align="right">{$order.total_weight}
    </div>{/if}</td>
    <td>&nbsp;</td>
    <td><div align="right"><strong>{$lang.label_total}</strong></div></td>
    <td><div align="right">{$order.formated_goods_amount}</div></td>
  </tr>
</table>


【15】order_goods_info.htm文件改为:
<table width="100%" cellpadding="3" cellspacing="1">
  <tr>
    <td scope="col"><div align="center"><strong>{$lang.goods_name_brand}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_sn}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_price}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_number}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.goods_attr}</strong></div></td>
<td scope="col"><div align="center"><strong>{$lang.my_goods_comment}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.storage}</strong></div></td>
    <td scope="col"><div align="center"><strong>{$lang.subtotal}</strong></div></td>
  </tr>
  {foreach from=$goods_list item=goods}
  <tr>
    {if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
    <td><img src="{$goods.goods_thumb}" /><br /><a href="../goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
    {if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
    {if $goods.parent_id > 0}{$lang.remark_fittings}{/if}</a></td>
    {else}
    <td>{$goods.goods_name}{$lang.remark_package}</td>
    {/if}
    <td>{$goods.goods_sn}</td>
    <td><div align="right">{$goods.formated_goods_price}</div></td>
    <td><div align="right">{$goods.goods_number}
    </div></td>
    <td>{$goods.goods_attr|nl2br}</td>
<td><div align="right">{$goods.goods_comment}</div></td>
    <td><div align="right">{$goods.storage}</div></td>
    <td><div align="right">{$goods.formated_subtotal}</div></td>
  </tr>
  {/foreach}
</table>


【16】admin\order.php文件中:
$sql = "SELECT o.*, IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, g.suppliers_id, IFNULL(b.brand_name, '') AS brand_name, p.product_sn
            FROM " . $ecs->table('order_goods') . " AS o
                LEFT JOIN " . $ecs->table('products') . " AS p
                    ON p.product_id = o.product_id
                LEFT JOIN " . $ecs->table('goods') . " AS g
                    ON o.goods_id = g.goods_id
                LEFT JOIN " . $ecs->table('brand') . " AS b
                    ON g.brand_id = b.brand_id
            WHERE o.order_id = '$order[order_id]'";
改为:
$sql = "SELECT o.*, IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, g.suppliers_id, IFNULL(b.brand_name, '') AS brand_name, p.product_sn
    , oc.goods_comment FROM " . $ecs->table('order_goods') . " AS o
                LEFT JOIN " . $ecs->table('products') . " AS p
                    ON p.product_id = o.product_id
                LEFT JOIN " . $ecs->table('goods') . " AS g
                    ON o.goods_id = g.goods_id
                LEFT JOIN " . $ecs->table('brand') . " AS b
                    ON g.brand_id = b.brand_id " .
                "LEFT JOIN order_comment as oc ON oc.goods_id = o.goods_id AND oc.order_id = '" . $order[order_id] . "' ".
            "WHERE o.order_id = '$order[order_id]'";


把:
$sql = "SELECT o.*, g.goods_thumb, g.goods_number AS storage, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name " .
            "FROM " . $ecs->table('order_goods') . " AS o ".
            "LEFT JOIN " . $ecs->table('goods') . " AS g ON o.goods_id = g.goods_id " .
            "LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
            "WHERE o.order_id = '{$order_id}' ";
改为:
$sql = "SELECT o.*, g.goods_thumb, g.goods_number AS storage, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name, oc.goods_comment " .
            "FROM " . $ecs->table('order_goods') . " AS o ".
            "LEFT JOIN " . $ecs->table('goods') . " AS g ON o.goods_id = g.goods_id " .
            "LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
            "LEFT JOIN order_comment as oc ON oc.goods_id = o.goods_id AND oc.order_id = '" . $order_id . "' ".
            "WHERE o.order_id = '$order_id' ";


【17】user.php文件中:
if ($rt > 0)
    {
        update_user_info();
        recalculate_price();


        $ucdata = isset($user->ucdata)? $user->ucdata : '';
        show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
    }
改为:
if ($rt > 0)
    {
    //Delete the goods_comment when the user login
    $sql = "DELETE FROM goods_comment WHERE user_id = '". $_SESSION["user_id"] ."'";
    $GLOBALS['db']->query($sql);
   
        update_user_info();
        recalculate_price();


        $ucdata = isset($user->ucdata)? $user->ucdata : '';
        show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
    }


【18】index.php中注释掉:
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);


$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";


if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
    $Loaction = 'mobile/';


    if (!empty($Loaction))
    {
        ecs_header("Location: $Loaction\n");


        exit;
    }


}


【19】goods.php中增加函数:
/*------------------------------------------------------ */
//-- 修改商品批注
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit_goods_comment')
{
    include('includes/cls_json.php');
    $json   = new JSON;
    $res    = array('err_msg' => '', 'result' => '');

    $goods_id   = intval($_POST['id']);
    $_POST['val'] = json_str_iconv($_POST['val']);
    $goods_comment = $json->decode($_POST['val']);


    $sql = "DELETE FROM goods_comment WHERE goods_id = '". $goods_id. "' AND user_id = '". $_SESSION["user_id"] ."'";
    $GLOBALS['db']->query($sql);
    $sql = "INSERT INTO goods_comment (goods_id, user_id, goods_comment) VALUES ('". $goods_id."', '".$_SESSION["user_id"]."', '".$goods_comment."')";
    $GLOBALS['db']->query($sql);

    $res['result'] = $goods_comment;

    die($json->encode($res));
}


【20】flow.php文件中:
在:
/* 插入订单商品 */
    $sql = "INSERT INTO " . $ecs->table('order_goods') . "( " .
                "order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
                "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) ".
            " SELECT '$new_order_id', goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
                "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id".
            " FROM " .$ecs->table('cart') .
            " WHERE session_id = '".SESS_ID."' AND rec_type = '$flow_type'";
    $db->query($sql);
后边增加:
/* 插入订单商品批注 */
    $sql = "INSERT INTO order_comment (order_id, goods_id, goods_comment) ".
      "(SELECT '$new_order_id', cart.goods_id, gc.goods_comment ".
    "FROM cart LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id)";
    $db->query($sql);


【21】category.php文件中:
/* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_weight, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
                "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
            "WHERE $where $ext ORDER BY $sort $order";
改为:
/* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_weight, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img, gc.goods_comment ' .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
                "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
                "LEFT JOIN goods_comment as gc ON gc.goods_id = g.goods_id AND gc.user_id = '" . $_SESSION[user_id] . "' ".
            "WHERE $where $ext ORDER BY $sort $order";


在:
$arr[$row['goods_id']]['name']             = $row['goods_name'];
        $arr[$row['goods_id']]['goods_brief']      = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
        $arr[$row['goods_id']]['market_price']     = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price']       = price_format($row['shop_price']);
        $arr[$row['goods_id']]['type']             = $row['goods_type'];
        $arr[$row['goods_id']]['promote_price']    = ($promote_price > 0) ? price_format($promote_price) : '';
        $arr[$row['goods_id']]['goods_thumb']      = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img']        = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url']              = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
        $arr[$row['goods_id']]['goods_sn']         = $row['goods_sn'];
        $arr[$row['goods_id']]['goods_weight']     = $row['goods_weight'];
后边增加:
/* 获取批注 */
        $arr[$row['goods_id']]['goods_comment']    = $row['goods_comment'];


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

[OK]ecshop二次开发:商品分类添加图片显示功能

ecshop的分类添加分类图片的功能,下面归类一下: 1、最关键的就是在数据的category表里面加入category_img字段,用来保存咱们的图片地址,类型就是varchar就可以了。 2...
  • ximo
  • ximo
  • 2012年09月18日 10:21
  • 1929

ecshop二次开发--购物时为每件商品添加备注信息

目标: 用户在选购商品加入购物车前可以为商品添加备注信息加入购物车后可以在购物车查看备注信息店主在查看订单时可以看到用户为商品添加的备注信息用户在个人中心中可以看到商品的备注信息 目标一: ...
  • ximo
  • ximo
  • 2011年08月22日 10:44
  • 927

ecshop二次开发 之在商品分类页如何增加评论等级和评论数量

注:新手朋友修改时请尽量不要使用记事本进行编辑,最好使用dreamweaver、editplus等专业的代码编辑软件进行编辑 下面是解决办法: 1、 打开 category.php 文件,找到 ...
  • ximo
  • ximo
  • 2012年07月30日 23:24
  • 659

ECSHOP二次开发之给商品增加新字段

ECSHOP二次开发工作之如何给商品增加一个新字段,来录入一些新的内容。

ecshop二次开发 给商品添加自定义字段

ecshop二次开发 给商品添加自定义字段 说起自定义字段,我想很多的朋友像我一样会想起一些开源的CMS(比如Dedecms、Phpcms、帝国)等,他们是可以在后台直接添加自定义字段的。 ...

ecshop二次开发秒杀、限时折扣、清仓等功能

ecshop二次开发秒杀、限时折扣、清仓等功能  限时抢购,秒杀商品的二次开发 1,先在后台admin/templates 中找goods_info.h...

Ecshop实现后台二次开发后功能模块仍然可以分配权限

我们对ec后台进行二次开发在可以在左面菜单栏加入新的功能模块有关如何加入我在之前帖子有说过 今天我们要分析的是功能模块加了以后如何在管理员列表也可以实现管理权限分配的管理。     首先我们了解一下...

ECSHOP二次开发中关于文档后台菜单的功能说明

在ecshop二次开发中看到关于文档后台菜单时,常常会遇到不解,下面是关于如何实现文档后台菜单的功能说明,将对你在ecshop二次开发中会有所帮助。 Themes 模板目录 商品管理   商品列...

ecshop二次开发——将邮箱地址替换为手机号码

这里有以下要求: 1. 手机号码为必填项,且长度为11位 2. 注册时需要判断手机号码是否已经注册 3. 邮箱地址改为可选项 4. 注册页面的手机号码输入框和邮箱地址输入框交换位置...
  • donhao
  • donhao
  • 2013年11月21日 18:14
  • 3176

ERP小型集团化——重点功能及二次开发配置——查询

概述 在实施过程中要制作查询时,查询提供两种集团化配置方法,需要首先从以下角度分析,需要制作的查询属于什么类别,再选择相应的方式制作。 查询需要判断是集团查询还是子公司查询,载根据类型来配...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ecshop二次开发——为用户提供商品批注功能
举报原因:
原因补充:

(最多只允许输入30个字)