帝國CMS調(diào)用購物車商品數(shù)量和總價的方法
發(fā)布時間:2014-11-29 16:10:49 作者:佚名
我要評論
這篇文章主要為大家介紹了帝國CMS調(diào)用購物車商品數(shù)量和總價的方法,在采用帝國CMS進行商城系統(tǒng)開發(fā)中非常具有實用價值,需要的朋友可以參考下
本文實例講述了帝國CMS調(diào)用購物車商品數(shù)量和總價的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復制代碼
代碼如下:<?php
/**
* 根據(jù)Cookie值對購物車商品數(shù)量和總價格調(diào)用
*/
require("class/connect.php");
$totalProducts = 0; //購物車商品總數(shù)
$totalPrice = 0.0; //購物車商品總價
// |77,243|2!|77,237|3!
$cookieString = explode("!",$_COOKIE['zeuqcmybuycar']);
try{
//遍歷商品
for($i = 0; $i < count($cookieString)-1; $i++){
$priceAndNumber = explode("|",$cookieString[$i]);
$thisNum = $priceAndNumber[2]; //當前商品的數(shù)量
$thisId = explode(",",$priceAndNumber[1]);
$thisId = $thisId[1]; //當前商品的ID
$thisPrice = this_price($thisId); //當前商品價格
$totalPrice += $thisPrice * $thisNum; //購物車商品總價累加
$totalProducts += $thisNum; //購物車商品總數(shù)累加
}
echo "document.write(\"".displayResultJs($totalPrice,$totalProducts)."\")"; //顯示結(jié)果Js形式輸出
}catch (Exception $e){
echo $e->getMessage();
}
/**計算商品價格*/
function this_price($id){
$connect = connectDB();
$query = "select price from phome_ecms_news where id = ".$id;
if(!$connect){
throw new Exception("數(shù)據(jù)庫鏈接不成功,請檢查!");
}
if(!$result = $connect -> query($query)){
throw new Exception("查詢失敗!");
}
$row = $result -> fetch_assoc();
return $row['price'];
}
/**鏈接數(shù)據(jù)庫*/
function connectDB(){
global $phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_char;
$connect = new mysqli($phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname);
$connect -> query("set Names ".$phome_db_char);
return $connect;
}
/**顯示結(jié)果Js*/
function displayResultJs($totalPrice,$totalProducts){
return "<div class='car'>您的購物車中有 {$totalProducts} 件商品,總計金額 ¥{$totalPrice}元。
點擊查看 <a href='/e/ShopSys/buycar/'>結(jié)算>></a> </div>";
}
?>
/**
* 根據(jù)Cookie值對購物車商品數(shù)量和總價格調(diào)用
*/
require("class/connect.php");
$totalProducts = 0; //購物車商品總數(shù)
$totalPrice = 0.0; //購物車商品總價
// |77,243|2!|77,237|3!
$cookieString = explode("!",$_COOKIE['zeuqcmybuycar']);
try{
//遍歷商品
for($i = 0; $i < count($cookieString)-1; $i++){
$priceAndNumber = explode("|",$cookieString[$i]);
$thisNum = $priceAndNumber[2]; //當前商品的數(shù)量
$thisId = explode(",",$priceAndNumber[1]);
$thisId = $thisId[1]; //當前商品的ID
$thisPrice = this_price($thisId); //當前商品價格
$totalPrice += $thisPrice * $thisNum; //購物車商品總價累加
$totalProducts += $thisNum; //購物車商品總數(shù)累加
}
echo "document.write(\"".displayResultJs($totalPrice,$totalProducts)."\")"; //顯示結(jié)果Js形式輸出
}catch (Exception $e){
echo $e->getMessage();
}
/**計算商品價格*/
function this_price($id){
$connect = connectDB();
$query = "select price from phome_ecms_news where id = ".$id;
if(!$connect){
throw new Exception("數(shù)據(jù)庫鏈接不成功,請檢查!");
}
if(!$result = $connect -> query($query)){
throw new Exception("查詢失敗!");
}
$row = $result -> fetch_assoc();
return $row['price'];
}
/**鏈接數(shù)據(jù)庫*/
function connectDB(){
global $phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_char;
$connect = new mysqli($phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname);
$connect -> query("set Names ".$phome_db_char);
return $connect;
}
/**顯示結(jié)果Js*/
function displayResultJs($totalPrice,$totalProducts){
return "<div class='car'>您的購物車中有 {$totalProducts} 件商品,總計金額 ¥{$totalPrice}元。
點擊查看 <a href='/e/ShopSys/buycar/'>結(jié)算>></a> </div>";
}
?>
希望本文所述對大家的帝國CMS建站有所幫助。
相關(guān)文章
- 這篇文章主要為大家介紹了帝國ECMS實現(xiàn)AJAX無刷新加入購物車的方法,對于開發(fā)商城系統(tǒng)的朋友很有借鑒參考價值!需要的朋友可以參考下2014-07-10
- 這篇文章主要為大家介紹了帝國CMS加入購物車購買數(shù)量的方法,是采用帝國CMS進行商城系統(tǒng)開發(fā)時比較實用的技巧,需要的朋友可以參考下2014-11-29
織夢Dedecms5.7整站調(diào)用購物車訂單數(shù)量簡單解決辦法
在賣織夢Dedecms5.7 GBK/UTF-8 財付通接口插件模塊的時候,網(wǎng)友向我咨詢一個織夢Dedecms5.7整站調(diào)用購物車訂單數(shù)量的問題,我查了一下手冊,沒找到相關(guān)知識2013-03-09帝國cms調(diào)用會員排行的序號的實現(xiàn)代碼
帝國cms調(diào)用會員排行的序號的實現(xiàn)代碼,需要的朋友可以參考下2012-08-20帝國cms 搜索關(guān)鍵字調(diào)用標簽(showsearch)使用說明
本文將詳細介紹帝國cms 搜索關(guān)鍵字調(diào)用標簽(showsearch)使用說明,需要了解的朋友可以參考下2012-12-12帝國cms列表頁list.var調(diào)用tags的實現(xiàn)代碼(記得要選列表頁)
列表頁list.var調(diào)用tags,很多朋友都想實現(xiàn)這個功能,本文搜集整理了一些實用的代碼貼出來與大家一起分享,希望可以幫助到你解決問題,感興趣的你可以參考下2013-02-27- 這篇文章主要為大家介紹了讓帝國CMS留言板支持調(diào)用標簽的方法,需要的朋友可以參考下2014-07-03
- 這篇文章主要為大家介紹了帝國CMS在反饋信息頁面調(diào)用萬能標簽的方法,需要的朋友可以參考下2014-07-03
- 這篇文章主要為大家介紹了帝國CMS7.0萬能標簽SQL調(diào)用注意事項,對于用慣了之前6.6版本的用戶尤其需要注意,需要的朋友可以參考下2014-07-03
帝國CMS實現(xiàn)內(nèi)容頁調(diào)用當前會員信息及文章信息的方法
這篇文章主要為大家介紹了帝國CMS實現(xiàn)內(nèi)容頁調(diào)用當前會員信息及文章信息的方法,對于進行會員系統(tǒng)的開發(fā)來說很有借鑒價值!需要的朋友可以參考下2014-07-09

