ecshop加入购物车效果(各个页面)

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



2008 年 客户曾提成 改善 这个功能 要求用层来实现,当时实在太菜,今天我终于做了修改


下来我把我的做法贴出来 网友们做参考 有不对的地方多多指正。

1、后台网店设置 购物车确定提示选择为

2、打开js/common.js104行 就是case '1'替换之前的 if (confirm(result.message)) location.href = cart_url;为
  1. opencartDiv(result.shop_price,result.goods_name,result.goods_thumb,result.goods_brief,result.goods_id,result.goods_price,result.goods_number);
复制代码

3、复制
  1. function opencartDiv(price,name,pic,goods_brief,goods_id,total,number)
  2. {
  3. var _id = "speDiv";
  4. var m = "mask";

  5. if (docEle(_id)) document.removeChild(docEle(_id));
  6. if (docEle(m)) document.removeChild(docEle(m));
  7. //计算上卷元素值
  8. var scrollPos;
  9. if (typeof window.pageYOffset != 'undefined')
  10. {
  11. scrollPos = window.pageYOffset;
  12. }
  13. else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
  14. {
  15. scrollPos = document.documentElement.scrollTop;
  16. }
  17. else if (typeof document.body != 'undefined')
  18. {
  19. scrollPos = document.body.scrollTop;
  20. }

  21. var i = 0;
  22. var sel_obj = document.getElementsByTagName('select');
  23. while (sel_obj[i])
  24. {
  25. sel_obj[i].style.visibility = "hidden";
  26. i++;
  27. }

  28. // 新激活图层
  29. var newDiv = document.createElement("div");
  30. newDiv.id = _id;
  31. newDiv.style.position = "absolute";
  32. newDiv.style.zIndex = "10000";
  33. newDiv.style.width = "500px";
  34. newDiv.style.height = "270px";
  35. newDiv.style.top = (parseInt(scrollPos + 200)) + "px";
  36. newDiv.style.left = (parseInt(document.body.offsetWidth) - 400) / 2 + "px"; // 屏幕居中
  37. newDiv.style.background = "#fff";
  38. newDiv.style.border = "5px solid #37911C";
  39. var html = '';

  40. //生成层内内容
  41. html = '<div style="font-size:14;background:#8cc67b;width:480px;height:40px;line-height:40px;padding:0 10px;font-size:14px; "><span style="float:left; font-weight:bold">产品购买</span><a href=\'javascript:cancel_div()\' style="float:right;padding:0 26px 0 0;background:url(themes/popocai/images/ico_closebig.gif) right center no-repeat;cursor:pointer;" >关闭</a></div><div class="cartpopDiv"><div class="toptitle"><a href="goods.php?id='+goods_id+'" class="pic"><img src='+pic+' width="100" height="100"/></a><p><font style="font-weight:bold">'+name+'</font><font style="color:#ff6701">'+price+'</font><br>'+goods_brief+'</p></div>';

  42. html += '<div class="coninfo">';
  43. html +='<table cellpadding="0" height="30"><tr><td align="center" >购物车共有<font style="color:#ff6701;"><strong>'+number+'</strong></font>种商品:合计:<font style="color:#ff6701;"><strong>'+total+'</strong></font></td></tr>';
  44. html += '</table>';
  45. html +='</div>';


  46. html +="<div style='float:left;width:450px;text-align:center;padding:15px 0 0;'><a href='index.php'><img src='themes/popocai/images/goon_ico.gif'></a><a href='flow.php'><img src='themes/popocai/images/jsico.gif'></a></div>";
  47. html +='</div></div>';
  48. newDiv.innerHTML = html;
  49. document.body.appendChild(newDiv);
  50. // mask图层
  51. var newMask = document.createElement("div");
  52. newMask.id = m;
  53. newMask.style.position = "absolute";
  54. newMask.style.zIndex = "9999";
  55. newMask.style.width = document.body.scrollWidth + "px";
  56. newMask.style.height = document.body.scrollHeight + "px";
  57. newMask.style.top = "0px";
  58. newMask.style.left = "0px";
  59. newMask.style.background = "#FFF";
  60. newMask.style.filter = "alpha(opacity=30)";
  61. newMask.style.opacity = "0.40";
  62. document.body.appendChild(newMask);

  63. }
复制代码

到这个common.js里大家看了会觉的这个函数很熟悉 这就是这个文件里的 我只是拿出来修改了一下 ,当然我们可以自己重新写弹出层 比如用jquery
4、打开flow.php181行左右加入
  1. $rows = $GLOBALS['db']->getRow("select goods_brief,shop_price,goods_name,goods_thumb from ".$GLOBALS['ecs']->table('goods')." where goods_id=".$goods->goods_id);
  2. $result['shop_price'] = price_format($rows['shop_price']);
  3. $result['goods_name'] = $rows['goods_name'];
  4. $result['goods_thumb'] = $rows['goods_thumb'];
  5. $result['goods_brief'] = $rows['goods_brief'];
  6. $result['goods_id'] = $goods->goods_id;
  7. $sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' .
  8. ' FROM ' . $GLOBALS['ecs']->table('cart') .
  9. " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
  10. $rowss = $GLOBALS['db']->GetRow($sql);
  11. $result['goods_price'] = price_format($rowss['amount']);
  12. $result['goods_number'] = $rowss['number'];
复制代码
就是加入购物车成功的判断里面


5、我把我们做的样式和图片也贴出来 不是很漂亮了


  1. /* 购物车弹出效果*/
  2. .cartpopDiv{
  3. width:450px;
  4. padding:0 25px;
  5. float:left;
  6. }
  7. .toptitle{
  8. width:450px;
  9. float:left;
  10. padding:16px 0;
  11. background:url(../images/cartpop_bg.gif) left bottom repeat-x;
  12. }
  13. .toptitle a.pic{
  14. float:left;
  15. width:100px;
  16. height:100px;
  17. overflow:hidden;
  18. }
  19. .toptitle p{
  20. float:right;
  21. width:350px;
  22. font-size:14px;
  23. line-height:20px;
  24. height:58px;
  25. overflow:hidden;
  26. }
  27. .coninfo{
  28. float:left;
  29. width:450px;
  30. padding:4px 0 6px;
  31. background:url(../images/cartpop_bg.gif) left bottom repeat-x;
  32. font-size:14px;
  33. }
  34. .coninfo table{
  35. float:left;
  36. width:100%;
  37. border:none;
  38. color:#a00;
  39. }
  40. .coninfo table td.left{
  41. width:82px;
  42. text-align:right;
  43. font-weight:bold;
  44. }
  45. .coninfo table td.left span,
  46. .toptitle p a{color:#333}
  47. .coninfo table td .gray{color:#999}
  48. .coninfo table td strong{color:#f00}
  49. .coninfo table td font{font-size:18px}
复制代码


以上就是我的实现方法

回答:
好东西支持~~

齐老湿威武 齐老湿**




哈哈我现在知道你是谁了。

齐老师 不错


出现这样的



flow.php 里边的代码没有加对位置,模板不一样行数也不一样

加在这一行代码的上面

$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;

好东西啊!谢谢分享

不错的代码!

很强大很需要

唯一不足的是,点击继续购物,转跳到网站首页了。不是停留在当前页面

不错,支持

顶一个,好看的购物车,好心的楼主



是啊,谁能帮忙改下呢。。。。。