调用购物车信息

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

  1. /**
  2. * 调用购物车信息
  3. * 商品购物车增加商品信息 liangfang add
  4. * @accesspublic
  5. * @returnstring
  6. */
  7. function insert_cart_info()
  8. {
  9. $sql = 'SELECT g.goods_id,g.goods_name,g.goods_thumb,SUM(c.goods_number) AS number, SUM(goods_price * c.goods_number) AS amount' .
  10. ' FROM ' . $GLOBALS['ecs']->table('cart') .'AS c ,' .
  11. $GLOBALS['ecs']->table('goods') .'AS g ' .
  12. " WHEREc.goods_id=g.goods_id AND session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "' GROUP BY goods_id ";

  13. $res = $GLOBALS['db']->getAll($sql);
  14. if($res)
  15. {
  16. foreach($res as $k=>$v)
  17. {
  18. $cart[$k]='<dl>';
  19. $cart[$k].='<dt><img src="'.$v['goods_thumb'].'" width=36 height=36 ></dt>';
  20. $cart[$k].='<dd>';
  21. $cart[$k].='<h4><a href="goods.php?id='.$v['goods_id'].'" target="_blank" style="color:#000000; float:left;width:188px">'.sub_str($v['goods_name'],13).'</a></h4>';
  22. $cart[$k].='<h4>件数:<i>'.intval($v['number']).'</i> 价格:<i>¥'.$v['amount'].'</i></h4>';
  23. $cart[$k].='</dd>';
  24. $cart[$k].='</dl>';
  25. $total+=floatval($v['amount']);
  26. }
  27. $cart_html=implode("",$cart);
  28. $cart_html.='<div class="totalpirce">总计:¥'.$total.'</div>';
  29. $cart_html.='<div class="shopCarBtn"><a href="flow.php?step=checkout" style="display:block; width:80px; height:30px;"></a></div>';
  30. $cart_html.= '<div class="clear"></div>';

  31. }

  32. //$str = sprintf($GLOBALS['_LANG']['cart_info'], $number,$amount );//price_format($amount, false) 这个函数不能被调用,可能是没有包含进来,并且也没有用,因为sprintf 就已经可以格式化小数了 liangfang edit
  33. return empty($cart_html)?"购物车为空,请先添加商品到购物车<a href='index.php'>去选商品?</a>":$cart_html;//'<a href="flow.php" class="view_cart" title="' . $GLOBALS['_LANG']['view_cart'] . '">' . $str . '</a>';
  34. }
复制代码



回答:
具体是怎么操作的

调用这个insert函数