教你如何在结算中心页面显示出商品图片

2016-07-07 15:01 来源:www.chinab4c.com 作者:ecshop专家

前几天帮一个客户做购物流程页面时要求显示商品图,EC系统默认在购物车页面是可以显示商品图片的,但是点结算后到结算中心页面你会发现只有商品名称,没有商品图
如果我们在EC的购物流程相关文件对它的系统函数跟踪一下就会发现checkout步骤时根本没有从数据库中调出缩略图,下面把方法与大家共享,希望能给大家一点帮助
步骤1:打开订单函数库文件lib_order.php 位于includes目录下
搜索
  1. /**
  2. * 取得购物车商品
  3. * @paramint$type类型:默认普通商品
  4. * @returnarray购物车商品数组
  5. */
复制代码

大概在852行左右,函数原来是
  1. function cart_goods($type = CART_GENERAL_GOODS)
  2. {
  3. $sql = "SELECT rec_id, user_id, goods_id, goods_name, goods_sn, goods_number, " .
  4. "market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, is_shipping, " .
  5. "goods_price * goods_number AS subtotal " .
  6. "FROM " . $GLOBALS['ecs']->table('cart') .
  7. " WHERE session_id = '" . SESS_ID . "' " .
  8. "AND rec_type = '$type'";

  9. $arr = $GLOBALS['db']->getAll($sql);

  10. /* 格式化价格及礼包商品 */
  11. foreach ($arr as $key => $value)
  12. {
  13. $arr[$key]['formated_market_price'] = price_format($value['market_price'], false);
  14. $arr[$key]['formated_goods_price']= price_format($value['goods_price'], false);
  15. $arr[$key]['formated_subtotal']= price_format($value['subtotal'], false);

  16. if ($value['extension_code'] == 'package_buy')
  17. {
  18. $arr[$key]['package_goods_list'] = get_package_goods($value['goods_id']);
  19. }
  20. }

  21. return $arr;
  22. }
复制代码


将它替换为
  1. function cart_goods($type = CART_GENERAL_GOODS)
  2. {
  3. $sql = "SELECT c.rec_id, c.user_id, c.goods_id, c.goods_name, g.goods_thumb,c.goods_sn, c.goods_number, " .
  4. "c.market_price, c.goods_price, c.goods_attr, c.is_real, c.extension_code, c.parent_id, c.is_gift, c.is_shipping, " .
  5. "c.goods_price * c.goods_number AS subtotal " .
  6. "FROM " . $GLOBALS['ecs']->table('cart') . ' AS c ' .
  7. ' LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = c.goods_id ' .
  8. " WHERE session_id = '" . SESS_ID . "' " .
  9. "AND rec_type = '$type'";

  10. $arr = $GLOBALS['db']->getAll($sql);

  11. /* 格式化价格及礼包商品 */
  12. foreach ($arr as $key => $value)
  13. {
  14. $arr[$key]['formated_market_price'] = price_format($value['market_price'], false);
  15. $arr[$key]['formated_goods_price']= price_format($value['goods_price'], false);
  16. $arr[$key]['formated_subtotal']= price_format($value['subtotal'], false);
  17. $arr[$key]['goods_thumb']= get_image_path($value['goods_id'], $value['goods_thumb'], true);
  18. if ($value['extension_code'] == 'package_buy')
  19. {
  20. $arr[$key]['package_goods_list'] = get_package_goods($value['goods_id']);
  21. }
  22. }

  23. return $arr;
  24. }
复制代码

修改的作用是把cart表和goods表相连,取出goods_thumb缩略图,然后用get_image_path函数调出缩略图的地址
步骤2:
下面打开flow.dwt 搜索
  1. <!-- {if $step eq "checkout"} 开始订单确认界面 --
复制代码

在这个下面找到
  1. <!-- {foreach from=$goods_list item=goods} -->
  2. <tr>
  3. <td bgcolor="#ffffff">
  4. <!-- {if $goods.goods_id gt 0 && $goods.extension_code eq 'package_buy'} -->
复制代码

在它的下面加入
  1. <img src="{$goods.goods_thumb}" border="0" title="{$goods.goods_name|escape:html}" />
复制代码

这个就是调出商品的缩略图了,OK,完工!

PS:如果大家想改下缩略图的大小,可以用以下代码,width是宽度,height是高度,可以自己调
  1. <img src="{$goods.goods_thumb}" border="0" title="{$goods.goods_name|escape:html}" width="50px" height="50px"/>
复制代码

回答:
支持一下~~

成功,谢谢分享