第一步:在调用页面的模板增加如下代码:
<div id="basketItemsWrap">
</div>
<div style="height:30px;" id="shopbt">
<ul id='shopcart_bottom'><li><a href='/shop/payment.asp' ><img src='/shop/images/hesuan.gif'/></a></li><li><a href='/shop/shoppingcart.asp' ><img src='/shop/images/chakangouwuche.gif'/></a></li></ul>
</div>
注意:代码和JS是严格匹配的,修改代码标识后记得修改JS。
页面顶端增加JS如下:
<script>
$(document).ready(function(){
$.ajax({
type:'POST',
url:'/Plus/Ajaxs.asp',
data:{pram:"show",Action:"addcart1"}, //初始化购物车内容
success:function(theResponse){
if($("#productID_").length<=0 && theResponse!=""){ //初始化购物车。
$("#basketItemsWrap").html(theResponse);
}
}
});
$("#basketItemsWrap .pjian").live("click", function(event) {
var PidSplitter=(this.id).split("_");
var Pid=PidSplitter[1];
$("#notificationsLoader").html('<img src="/images/loading.gif">');
$.ajax({
type:'POST',
url:'/plus/Ajaxs.asp',
data:{pid:Pid,Action:"addcart1",Pact:"jian"},
success:function(theResponse){
$("#basketItemsWrap table").remove();
$("#basketItemsWrap").html(theResponse);
$("#notificationsLoader").empty();
}
})
});
$("#basketItemsWrap .pdel").live("click", function(event) {
var PidSplitter=(this.id).split("_");
var Pid=PidSplitter[1];
$("#notificationsLoader").html('<img src="/images/loading.gif">');
$.ajax({
type:'POST',
url:'/plus/Ajaxs.asp',
data:{pid:Pid,Action:"addcart1",Pact:"del"},
success:function(theResponse){
$("#basketItemsWrap table").remove();
$("#basketItemsWrap").html(theResponse);
$("#notificationsLoader").empty();
}
})
});
$("#basketItemsWrap .pjia").live("click", function(event) {
var PidSplitter=(this.id).split("_");
var Pid=PidSplitter[1];
$("#notificationsLoader").html('<img src="/images/loading.gif">');
$.ajax({
type:'POST',
url:'/plus/Ajaxs.asp',
data:{pid:Pid,Action:"addcart1"},
success:function(theResponse){
$("#basketItemsWrap table").remove();
$("#basketItemsWrap").html(theResponse);
$("#notificationsLoader").empty();
}
})
});
$(".addcart").click(function(){
var ProductIdValSplitter=(this.id).split("_");
var ProductIdVal=ProductIdValSplitter[1];
$("#notificationsLoader").html('<img src="/images/loading.gif">');
$.ajax({
type:'POST',
url:'/Plus/Ajaxs.asp',
data:{pid:ProductIdVal,Action:"addcart1"},
success: function(theResponse){
if (theResponse=='error'){
$("#notificationsLoader").empty();
alert('对不起,您没有登录!');
}else if (theResponse=='error1'){
$("#notificationsLoader").empty();
alert('对不起,您所在的用户级别不能购买本商品!');
}else if (theResponse=='error2'){
$("#notificationsLoader").empty();
alert('对不起,网站不允许游客订餐,请注册会员!');
}else{
$("#basketItemsWrap table").remove();
$("#basketItemsWrap").html(theResponse);
$("#notificationsLoader").empty();
}
}
});
});
});
</script>
第二步:修改AJAx后台文件/plus/ajaxs.asp,增加红色代码
Case "relativeDoc" relativeDoc
Case "getModelType" getModelType
Case "addCart" addShoppingCart
Case "GetPackagePro" GetPackagePro
Case "GetSupplyContact" GetSupplyContact
Case "HitsGuangGao" HitsGuangGao
Case "GetClubBoardOption" GetClubBoardOption
Case "getclubboard" GetClubboard
Case "GetClubPushModel" GetClubPushModel
Case "getclubboardcategory" getclubboardcategory
Case "getonlinelist" getonlinelist
Case "addcart1" addcart
修改函数
Function GetUserID()
If KS.IsNul(KS.C("UserName")) Then
If Not KS.IsNul(KS.C("CartID")) Then
GetUserID=KS.C("CartID")
Else
Response.Cookies(KS.SiteSn)("CartID")=KS.MakeRandom(15)
GetUserID=KS.C("CartID")
End If
Else
GetUserID=KS.C("UserName")
End If
End Function
添加两个函数
sub showcart()
Set RS=Server.CreateObject("ADODB.RECORDSET")
RS.Open "Select i.id,i.title,i.GroupPrice,i.Price_Member,i.Price,c.attr,c.amount from KS_Product i Inner Join KS_ShoppingCart c on i.id=c.proid where c.flag=0 and c.username='" & GetUserID & "' and i.verific=1 order by i.id desc",conn,1,1
if rs.recordcount=0 then ks.die "":response.End()
str="<table border='1' cellspacing='0' cellpadding='0' style='border-collapse:collapse;' align='center' ><tr><th><font color=brown>菜名</font></th><th width='65'>数量</th><th width='50'>价格</th></tr>"
n=1
Do While Not RS.Eof
IF KS.C("UserName")<>"" Then
If RS("GroupPrice")=0 Then
RealPrice=RS("Price_Member")
Else
Dim RSP:Set RSP=Conn.Execute("Select Price From KS_ProPrice Where GroupID=(select groupid from ks_user where username='" & KS.C("UserName") & "') And ProID=" & RS("ID"))
If RSP.Eof Then
RealPrice=RS("Price_Member")
Else
RealPrice=RSP(0)
End If
RSP.Close:Set RSP=Nothing
End If
Else
RealPrice=RS("Price")
End If
str=str&"<tr id='productID_"&rs("id")&"'><td><font color=brown>" & rs(1) & "</font></td><td width='65'><img src='/images/-.png' class='pjian' id=""productjian_"&rs("id")&""" style='cursor:hand;' /> "&rs("amount")&" <img src='/images/+.jpg' class='pjia' id='productjia_"&rs("id")&"' style='cursor:hand;'/> <a href='#' onclick='return false;' class='pdel' id='proddel_"&rs("id")&"'><font color=red>删</font></a></td><td width='50'>¥" & RealPrice*rs("amount") & "</td></tr>"
n=n+1
RS.MoveNext
Loop
rs.close:set rs=nothing
str=str&"</table>"
ks.die str
end sub
Sub addcart()
Dim Prodid:Prodid=KS.ChkClng(request("pid"))
Dim ProductList:ProductList=Session("ProductList")
Dim Num:Num=KS.ChkClng(request("num"))
Dim Attr:Attr=KS.DelSQL(UnEscape(Request("AttributeCart")))
if Num=0 then Num=1
Dim Pram:Pram=ks.s("pram")
Dim pact:pact=ks.s("pact")
if Pram="show" then
call showcart()
response.End()
end if
if pact="jian" then
Dim RSA:Set RSA=Server.CreateObject("ADODB.RECORDSET")
rsA.open "select * from KS_ShoppingCart where flag=0 and attr='" & attr & "' and username='" & GetUserID & "' And proid=" & Prodid,conn,1,3
if not (rsa.eof and rsa.bof) then
if rsa("amount")>1 then
rsa("amount")=rsa("amount")-1
else
rsa.delete
end if
rsa.update
end if
rsa.close
set rsa=nothing
call showcart()
response.End()
end if
if pact="del" then
conn.execute(" delete from KS_ShoppingCart where flag=0 and attr='" & attr & "' and username='" & GetUserID & "' And proid=" & Prodid)
call showcart()
response.End()
end if
if Prodid=0 then KS.Die ""
SqlStr = "select * from KS_Config"
Set RS = KS.InitialObject("ADODB.recordset")
RS.Open SqlStr, Conn, 1, 3
Dim Setting:Setting=Split(RS("Setting")&"^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^^%^","^%^")
RS.Close:Set RS=Nothing
Set KSUser=New UserCls
LoginTF=KSUser.UserLoginChecked
if LoginTF=false and Setting(63)=0 then
ks.die "error2"
end if
Set RS=Server.CreateObject("ADODB.RECORDSET")
RS.Open "select top 1 arrGroupID From KS_Product Where id=" & Prodid,conn,1,1
If RS.Eof And RS.Bof Then
RS.Close : Set RS=Nothing
ks.die "该商品不存在!"
End If
arrGroupID=RS(0)
If Not KS.IsNul(arrGroupID) Then
Set KSUser=New UserCls
LoginTF=KSUser.UserLoginChecked
if logintf=fasle then
ks.die "error"
RS.Close:Set RS=Nothing
end if
If KS.FoundInArr(arrGroupID,KSUser.GetUserInfo("GroupID"),",")=false Then
RS.Close:Set RS=Nothing
ks.die "error1"
End If
End If
RS.Close '购买验证完毕
Set RSA=Server.CreateObject("ADODB.RECORDSET")
rsA.open "select * from KS_ShoppingCart where flag=0 and attr='" & attr & "' and username='" & GetUserID & "' And proid=" & Prodid,conn,1,3
if rsa.recordcount=0 then
rsa.addnew
rsa("flag")=0
rsa("proid")=Prodid
rsa("username")=GetUserID
rsa("attr")=attr
rsa("adddate")=now
rsa("amount")=Num
rsa.update
else
rsa("amount")=rsa("amount")+1
rsa.update
end if
rsa.close
set rsa=nothing
call showcart()
end sub
第三步:修改调用标签
增加订购按钮
<a href="{@linkurl}" id="featuredProduct_{@id}" class="addcart"><img src="/images/buy.jpg" /></a>
不想修改的下载修改好的文件即可
[replyview]
[/replyview]