帝國(guó)ECMS實(shí)現(xiàn)AJAX無(wú)刷新加入購(gòu)物車的方法
帝國(guó)ECMS實(shí)現(xiàn)AJAX無(wú)刷新加入購(gòu)物車的方法主要步驟如下:
一、修改商城內(nèi)容模板,頭部加入如下代碼:
<script type="text/javascript" src="[!--news.url--]skin/default/js/addBuyCar.js"></script>
<script type="text/javascript">
var newsurl='<?=$public_r[newsurl]?>';
</script>
二、修改商城內(nèi)容模板,加入購(gòu)物車部分修改成如下代碼:
三、至于jquery文件,兼容1.3和1.4版本,自行下載。文件addBuyCar.js源代碼如下:
$.ajax({
type: "post",
url: newsurl+"e/template/ShopSys/addBuyCar.php",
data:"classid="+classid+"&id="+id,
dataType: "json",
success: function (json) {
alert(json.msg);
}
})
}
四、加入處理程序e/template/ShopSys/addBuyCar.php,其源代碼如下:
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../data/dbcache/class.php");
require("../../class/ShopSysFun.php");
$link=db_connect();
$empire=new mysqlquery();</p> <p>//$_POST
$classid=(int)$_POST['classid'];
$id=(int)$_POST['id'];</p> <p>//add function
function json_AddBuycar($classid,$id){
global $class_r,$empire,$dbtbpre,$public_r;
$classid=(int)$classid;
$id=(int)$id;
if(empty($classid)||empty($id)||empty($class_r[$classid][tbname]))
{
return json_encode(array('msgid'=>1,'msg'=>'此商品不存在'));
}
//驗(yàn)證產(chǎn)品是否存在
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid' and id='$id' limit 1");
if(!$num)
{
return json_encode(array('msgid'=>1,'msg'=>'此商品不存在'));
}
$record="!";
$field="|";
$productid=$classid.",".$id;
$buycar=getcvar('mybuycar');
//重復(fù)
if(strstr($buycar,"|".$productid."|"))
{
$pr=explode("|".$productid."|",$buycar);
$pr1=explode("!",$pr[1]);
$oldbuycar="|".$productid."|".$pr1[0]."!";
//數(shù)量
$pr1[0]=ReturnBuycarProductNum($pr1[0]);
if(empty($pr1[0]))
{
$pr1[0]=1;
}
$newnum=$pr1[0]+1;
$newbuycar="|".$productid."|".$newnum."!";
$buycar=str_replace($oldbuycar,$newbuycar,$buycar);
}
else
{
//只存放一個(gè)
if($public_r['buycarnum']==1)
{
$buycar='';
}
$buycar.="|".$productid."|1!";
}
$re=SetBuycar($buycar);
if($re)
{
return json_encode(array('msgid'=>2,'msg'=>'商品加入購(gòu)物車成功'));
}
}
echo json_AddBuycar($classid,$id);
db_close();
$empire=null;
?>
至此,問(wèn)題搞定!
相關(guān)文章
帝國(guó)CMS實(shí)現(xiàn)搜索結(jié)果顯示頁(yè)關(guān)鍵字高亮的方法
這篇文章主要為大家介紹了帝國(guó)CMS實(shí)現(xiàn)搜索結(jié)果顯示頁(yè)關(guān)鍵字高亮的方法,需要的朋友可以參考下2014-07-10帝國(guó)CMS實(shí)現(xiàn)用戶自定義標(biāo)簽函數(shù)輸出圖片集大小圖的方法
這篇文章主要為大家介紹了帝國(guó)CMS實(shí)現(xiàn)用戶自定義標(biāo)簽函數(shù)輸出圖片集大小圖的方法,需要的朋友可以參考下2014-07-10帝國(guó)cms自定義字段實(shí)現(xiàn)價(jià)格區(qū)域范圍篩選的方法
這篇文章主要為大家介紹了帝國(guó)cms自定義字段實(shí)現(xiàn)價(jià)格區(qū)域范圍篩選的方法,需要的朋友可以參考下2014-07-10帝國(guó)cms實(shí)現(xiàn)會(huì)員注冊(cè)之后根據(jù)所在會(huì)員組轉(zhuǎn)向的方法
這篇文章主要為大家介紹了帝國(guó)cms實(shí)現(xiàn)會(huì)員注冊(cè)之后根據(jù)所在會(huì)員組轉(zhuǎn)向的方法,對(duì)于開(kāi)發(fā)會(huì)員系統(tǒng)來(lái)說(shuō)非常有借鑒價(jià)值,需要的朋友可以參考下2014-07-10帝國(guó)CMS實(shí)現(xiàn)內(nèi)容頁(yè)調(diào)用當(dāng)前會(huì)員信息及文章信息的方法
這篇文章主要為大家介紹了帝國(guó)CMS實(shí)現(xiàn)內(nèi)容頁(yè)調(diào)用當(dāng)前會(huì)員信息及文章信息的方法,對(duì)于進(jìn)行會(huì)員系統(tǒng)的開(kāi)發(fā)來(lái)說(shuō)很有借鑒價(jià)值!需要的朋友可以參考下2014-07-09帝國(guó)CMS實(shí)現(xiàn)提交評(píng)論后自動(dòng)重新生成內(nèi)容頁(yè)的方法
這篇文章主要為大家介紹了帝國(guó)CMS實(shí)現(xiàn)提交評(píng)論后自動(dòng)重新生成內(nèi)容頁(yè)的方法,需要的朋友可以參考下2014-07-09帝國(guó)CMS實(shí)現(xiàn)循環(huán)調(diào)用子欄目的方法
這篇文章主要為大家介紹了帝國(guó)CMS實(shí)現(xiàn)循環(huán)調(diào)用子欄目的方法,對(duì)于模板的開(kāi)發(fā)與制作很有借鑒價(jià)值,需要的朋友可以參考下2014-07-09帝國(guó)CMS簡(jiǎn)單實(shí)現(xiàn)國(guó)-省-市聯(lián)動(dòng)菜單的方法
這篇文章主要為大家介紹了帝國(guó)CMS簡(jiǎn)單實(shí)現(xiàn)國(guó)-省-市聯(lián)動(dòng)菜單的方法,需要的朋友可以參考下2014-07-09- 這篇文章主要為大家介紹了帝國(guó)CMS功能解密之字段處理函數(shù),對(duì)于帝國(guó)CMS的二次來(lái)說(shuō)非常重要,需要的朋友可以參考下2014-07-09
帝國(guó)CMS 7.0商城系統(tǒng)常見(jiàn)問(wèn)題與技巧教程
這篇文章主要為大家介紹了帝國(guó)CMS 7.0商城系統(tǒng)常見(jiàn)問(wèn)題與技巧,需要的朋友可以參考下2014-07-08

