帝国CMS二次开发调用购物车商品数量和总价
作者:
雨祺 发表于:
浏览:
59次 字数:
1377 原创
级别:
站长2021-06-12 01:06:541017992
总稿:
69
篇,
月稿:
0
篇
帝国CMS二次开发调用购物车商品数量和总价
- <?php
-
-
-
- require("class/connect.php");
-
- $totalProducts = 0;
- $totalPrice = 0.0;
-
-
- $cookieString = explode("!",$_COOKIE['zeuqcmybuycar']);
-
- try{
-
- for($i = 0; $i < count($cookieString)-1; $i++){
- $priceAndNumber = explode("|",$cookieString[$i]);
- $thisNum = $priceAndNumber[2];
- $thisId = explode(",",$priceAndNumber[1]);
- $thisId = $thisId[1];
- $thisPrice = this_price($thisId);
-
- $totalPrice += $thisPrice * $thisNum;
- $totalProducts += $thisNum;
- }
-
- echo "document.write("".displayResultJs($totalPrice,$totalProducts)."")";
-
- }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("数据库链接不成功,请检查!");
- }
- if(!$result = $connect -> query($query)){
- throw new Exception("查询失败!");
- }
- $row = $result -> fetch_assoc();
-
- return $row['price'];
- }
-
-
- 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;
- }
-
-
- function displayResultJs($totalPrice,$totalProducts){
- return "<div class='car'>您的购物车中有 {$totalProducts} 件商品,总计金额 ¥{$totalPrice}元。<br />点击查看 <a href='/e/ShopSys/buycar/'>结算>></a> </div>";
- }
- ?>
【审核人:站长】
-
-
技术文摘
-
查看更多技术文摘