步骤重新梳理了一下:
支持原创,感谢分享!
效果图:
下载 (32.53 KB)
2012-8-14 14:51
第一步: 在/thmes/你的 模板/library/
新建一个库 文件: cart_info.lbi
代码:
暂无商品
复制代码
文件下载: cart_info.rar (715 Bytes)
下载次数: 542
2012-8-14 14:52
第二步打开: includes/lib_insert.php
大约102行
- function insert_cart_info() {
复制代码
一直到:
/**
* 调用指定的广告位的广告
复制代码
之间的代码全部替换为:
/**
* 调用购物车信息
*
* @access public
* @return string
*/
function insert_cart_info()
{
$sql = 'SELECT
c.*,g.goods_name,g.goods_thumb,g.goods_id,c.goods_number,c.goods_price' .' FROM ' . $GLOBALS['ecs']->table('cart') ." AS c ".
" LEFT JOIN
".$GLOBALS['ecs']->table('goods')." AS g ON g.goods_id=c.goods_id "." WHERE session_id = '" . SESS_ID . "' AND rec_type = '" .
CART_GENERAL_GOODS . "'";$row = $GLOBALS['db']->GetAll($sql);
$arr = array();
foreach($row AS $k=>$v)
{
$arr[$k]['goods_thumb'] =get_image_path($v['goods_id'], $v['goods_thumb'],
true);$arr[$k]['short_name'] = $GLOBALS['_CFG']['goods_name_length']
> 0 ?sub_str($v['goods_name'],
$GLOBALS['_CFG']['goods_name_length']) : $v['goods_name'];$arr[$k]['url'] =
build_uri('goods', array('gid' => $v['goods_id']), $v['goods_name']);$arr[$k]['goods_number'] =
$v['goods_number'];$arr[$k]['goods_name'] =
$v['goods_name'];$arr[$k]['goods_price'] =
price_format($v['goods_price']);$arr[$k]['rec_id'] = $v['rec_id'];
}
$sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price *
goods_number) AS amount' .' FROM ' . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' AND rec_type = '" .
CART_GENERAL_GOODS . "'";$row = $GLOBALS['db']->GetRow($sql);
if ($row)
{
$number = intval($row['number']);
$amount = floatval($row['amount']);
}
else
{
$number = 0;
$amount = 0;
}
$GLOBALS['smarty']->assign('str',sprintf($GLOBALS['_LANG']['cart_info'],
$number, price_format($amount, false)));$GLOBALS['smarty']->assign('goods',$arr);
$GLOBALS['smarty']->assign('goods_number',$number);
$GLOBALS['smarty']->assign('order_amount',$amount);
$output = $GLOBALS['smarty']->fetch('library/cart_info.lbi');
return $output;
}
复制代码
第三步:
打开js/common.js
最后面添加:
// 自定义购物车删除
function deleteCartGoods(rec_id)
{
Ajax.call('delete_cart_goods.php', 'id='+rec_id, deleteCartGoodsResp**e,
'POST', 'JSON');}
/**
* 接收删除后返回的信息
*/
function deleteCartGoodsResp**e(res)
{
if (res.error)
{
alert(res.err_msg);
}
else
{
document.getElementById('ECS_CARTINFO').innerHTML = res.content;
}
}
复制代码
其中的星号**替换为o+n+s 中间的+号去掉,这三个字母是被屏蔽的.
第四步: 打开
thmes/你的模板/style.css
最后添加:
/*购物车*/
.cart{ position:absolute; z-index:9px; right:0px; _right:-5px; top:4px;
width:190px; padding-right:5px; height:26px; line-height:26px;}
.cart a.js{ text-indent:-999px; overflow:hidden; display:inline-block;
height:26px; float:right; width:38px;}.cart_sp { display:block; float:left; height:26px; line-height:26px;
width:150px;}.cart_sp .right {_width:70px; padding-right:10px; text-align:right;}
.cart_sp .left {_width:70px;text-indent:30px;}
.cart_box { display:none;}
.on .cart_box { display:block; background:#fff; border:1px solid #ddd;
width:300px; margin:5px 0 0 -106px; _margin:5px -8px 0 0;}.ie6left {_float:left;}
.ptt {background:url(images/suning.png) no-repeat 0 -80px;}
.onp .ptt {text-indent:30px; }
.on .ptt,.onp .ptt {_float:right; _width:195px; background-position:0px
-80px;}.divt {_width:300px;}
.cart_box li { height:auto; text-indent:0px; padding:8px; color:#777;
border-bottom:1px dashed #dedede; _height:48px;}.cart_box li.nobk { background:#fafafa;}
.cart_box li p.sgoodc { width:163px; overflow:hidden;}
.cart_box li p.sgoodc span,.cart_box li p.sgoodt span,.cart_box li p
a.del{ display:block; height:18px; line-height:18px; overflow:hidden;}.cart_box li p.sgoodt { width:65px; float:right; text-align:right;
overflow:hidden; color:#ff6600;}.cart_box li p a.name { color:#333; text-decoration:none; height:22px;
overflow:hidden;}.cart_box li p a:hover.name,.zllcart a:hover.right {
text-decoration:underline;}.cart_box li p a.del { color:#777; text-decoration:none; margin-top:5px;
}.cart_box li p a:hover.del { color:#333;
text-decoration:line-through;}.cart_box li.zllcart { padding:0 8px; border-bottom:0;_height:24px;}
.zllcart em,.zllcart a.right {
color:#ff6600;text-decoration:none;}
复制代码
第五步,在根 目录
新建一个delete_cart_goods.php文件,
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once('includes/cls_json.php');
$result = array('error' => 0, 'message' => '', 'content' => '',
'goods_id' => '');$json = new JSON;
if($_POST['id'])
{
$sql = 'DELETE FROM '.$GLOBALS['ecs']->table('cart')." WHERE
rec_id=".$_POST['id'];$GLOBALS['db']->query($sql);
}
$sql = 'SELECT
c.*,g.goods_name,g.goods_thumb,g.goods_id,c.goods_number,c.goods_price' .' FROM ' . $GLOBALS['ecs']->table('cart') ." AS
c "." LEFT JOIN ".$GLOBALS['ecs']->table('goods')."
AS g ON g.goods_id=c.goods_id "." WHERE session_id = '" . SESS_ID . "' AND rec_type
= '" . CART_GENERAL_GOODS . "'";$row = $GLOBALS['db']->GetAll($sql);
$arr = array();
foreach($row AS $k=>$v)
{
$arr[$k]['goods_thumb'] =get_image_path($v['goods_id'],
$v['goods_thumb'], true);$arr[$k]['short_name'] =
$GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($v['goods_name'], $GLOBALS['_CFG']['goods_name_length']) :
$v['goods_name'];
$arr[$k]['url'] = build_uri('goods', array('gid'
=> $v['goods_id']), $v['goods_name']);$arr[$k]['goods_number'] = $v['goods_number'];
$arr[$k]['goods_name'] = $v['goods_name'];
$arr[$k]['goods_price'] =
price_format($v['goods_price']);$arr[$k]['rec_id'] = $v['rec_id'];
}
$sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number)
AS amount' .' FROM ' . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' AND rec_type
= '" . CART_GENERAL_GOODS . "'";$row = $GLOBALS['db']->GetRow($sql);
if ($row)
{
$number = intval($row['number']);
$amount = floatval($row['amount']);
}
else
{
$number = 0;
$amount = 0;
}
$GLOBALS['smarty']->assign('str',sprintf($GLOBALS['_LANG']['cart_info'],
$number, price_format($amount, false)));$GLOBALS['smarty']->assign('goods',$arr);
$GLOBALS['smarty']->assign('goods_number',$number);
$GLOBALS['smarty']->assign('order_amount',$amount);
$result['content'] =
$GLOBALS['smarty']->fetch('library/cart_info.lbi');die($json->encode($result));
?>
复制代码
文件下载: delete_cart_goods.rar (940 Bytes)
下载次数: 418
2012-8-14
14:54
使用下面的代码即可全站调用购物车:
{insert_scripts files='transport.js'}
{insert name='cart_info'}
复制代码
点赞收藏