百度
360搜索
搜狗搜索

帝国CMS调用购物车商品数量和总价的方法详细介绍

这篇文章主要为大家介绍了帝国CMS调用购物车商品数量和总价的方法,在采用帝国CMS进行商城系统开发中非常具有实用价值,需要的朋友可以参考下

本文实例讲述了帝国调用购物车商品数量和总价的方法。分享给大家供大家参考。具体实现方法如下:

代码如下: <?

/**

* 根据Cookie值对购物车商品数量和总价格调用

*/

require("class/connect.php");

$totalProducts = 0; //购物车商品总数

$totalPrice
= 0.0; //购物车商品总价

// |77,243|2!|77,237|3!

$cookieString = explode("!",$_COOKIE['zeuqcmybuycar']);

try{

//遍历商品

for($i = 0; $i < count($coo sQdRwVgjMgkieString)-1; $i++){

$priceAndNumber = explode("|",$cookieString[$i]);

$thisNum = $priceAndNumber[2]; //当前商品的数量

$thisId = explode(",",$priceAndNumber[1]);

$thisId = $thisId[1]; //当前商品的ID

$thisPrice = this_price($thisId); //当前商品价格

$totalPrice += $thisPrice * $thisNum; //购物车商品总价累加

$totalProducts += $thisNum; //购物车商品总数累加

}

echo "document.write(\"".displayResult($totalPrice,$totalProducts)."\")"; //显示结果Js形式输出

}ca
tch (Exception $e){

echo $e->getMessage();

}

/**计算商品价格*/

function this_price($id){

$connect = connectDB();

$query = "select price from phome__news where id = ".$id;

if(!$connect){

throw new Exception("链接不成功,请检查!");

}

if(!$result = $connect -> query($query)){

throw new Exception("查询失败!");

}

$row = $result -> fetch_assoc();

sQdRwVgjMg return $row['price'];

}

/**链接数据库*/

function connectDB(){

global $phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_char;

$connect = new i($phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname);

$connect -> query("set Names ".$phome_db_char);

return $connect;

}

/**显示结果Js*/

function displayResultJs($totalPrice,$totalProducts){

return "<div class='car'>您的购物车中有 {$totalProducts} 件商品,总计金额 ¥{$tot alPrice}元。

点击查看 <a href='/e/ShopSys/buycar/'>结算&gt;&gt;</a> </div>";

}

?>

希望本文所述对大家的建站有所帮助。

本文标题: 帝国CMS调用购物车商品数量和总价的方法 ,

网站数据信息

"帝国CMS调用购物车商品数量和总价的方法"浏览人数已经达到36次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:帝国CMS调用购物车商品数量和总价的方法的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!