青青草国产精品欧美成人|国产色在线|亚洲欧洲日产韩国无码|japanese厨房乱xxx|91精品国产福利尤物

PHP購物車源代碼分享,如何作商城購物車
作者:admin | 時間:2018-07-17 17:20:41

對于商城類網站,購物車是不可少的功能,方便用戶批量購買產品,巔云建站系統也增加了購物車模塊,當然在開發原理與普通網站的購物車是一樣的:

功能如下:

1、任意產品詳情頁可直接購買或加入購物車

加入購物車

2、可清空購物車。冊除單個產品。

3、收銀臺結算。填寫收貨地址默認調用會員信息。

4、在線支付結算定單,批量修改產品定單信息和財務信息。當然巔云是多用戶系統,還得批量計算各等級會員扣費及價格。

填寫收貨信息功能購物車在線支付

購物車代碼:


1、前臺下單源碼:


<?session_start();require_once("../common/init.php");?><table width="255"  border="0" cellspacing="0" cellpadding="0"><tr><td width="130" rowspan="6"><div align="center"><?php        if(trim($info['tupian']==""))     {       echo "暫無圖片";     }     else     {?><img src="<?php echo $info['tupian'];?>" width="130" height="100" border="0"><?php  }?></div></td>  <td width="20" height="16"> </td>  <td width="113"><font color="EF9C3E">【<?php echo $info['mingcheng'];?>】</font></td> </tr> <tr>  <td height="16"> </td>  <td><font color="910800">【市場價:<?php echo $info['shichangjia'];?>】</font></td> </tr> <tr>  <td height="16"> </td>  <td><font color="DD4679">【會員價:<?php echo $info['huiyuanjia'];?>】</font></td> </tr> <tr>  <td height="16"> </td>  <td>【<a href="lookinfo.php?IDProduct=<?php echo $info['IDProduct'];?>">查看信息</a>】</td> </tr> <tr>  <td height="16"> </td>  <td>【<a href="addgouwuche.php?IDProduct=167">放入購物車</a>】</td> </tr> <tr>  <td height="16"> </td>  <td><font color="13589B">【剩余數量:      <?php        if(($info['shuliang']-$info['cishu'])>0)      {         echo ($info['shuliang']-$info['cishu']);      }      else      {         echo "已售完";      }      ?>】</font></td> </tr> </table>

2、加入購物車代碼



<?session_start();require_once("../common/init.php");require_once("../user/security.inc.php");$web=get_web();  $IDProduct=strval($_GET['IDProduct']);$sql="select * from  products where IDProduct='".$IDProduct."' and  user='$web'";   $info=$db->getdata($sql);if(($info['shuliang']-$info['cishu'])<=0) {    echo "<script>alert('該商品已經售完!');history.back();</script>";   exit;  }  $array=explode("@",$_SESSION['producelist']);  for($i=0;$i<count($array)-1;$i++)    {  if($array[$i]==$IDProduct)   {      echo "<script>alert('該商品已經在您的購物車中!');history.back();</script>";    header("location:gouwu1.php");   exit;   } }  $_SESSION['producelist']=$_SESSION['producelist'].$IDProduct."@";  $_SESSION['quatity']=$_SESSION['quatity']."1@";  header("location:gouwu1.php");?>


<?session_start();require_once("../common/init.php");require_once("../user/security.inc.php");$web=get_web();?><!DOCTYPE HTML><html><head><style>body,button,input,select,textarea{line-height:150%;font-family:'微軟雅黑';font-size:14px; }body{background:#fff}select {height:32px}.red {color:#f00 !important}a{text-decoration:none;color:#3366ff}.csstable {border:1px solid #ccc;margin-bottom:10px;line-height:220%;border-right:1px solid #eee;border-bottom:1px solid #eee;}.csstable td{border-bottom:1px solid #ccc;border-right:1px solid #ccc;padding:6px 5px 3px 5px;}.csstable1 {border:01px solid #ccc;margin-bottom:10px;line-height:220%;border-right:1px solid #eee;border-bottom:1px solid #eee;}.csstable1 td{border-bottom:0px solid #ccc;border-right:0px solid #ccc;padding:3px 5px 3px 5px;}input{border:1px solid #aaa;background:#fff;height:30px;text-align:center}.buttoncss{background:#c00;color:#fff;border:0;padding:3px 30px}</style></head><body><div class="part1  pad bgf yahei" style="padding:0px 20px">	<h3 class="font26" style="padding-bottom:10px;border-bottom:0px solid #ccc;"><span class="l title"></span><span class="r more"></span></h3>	<div class="bx-c">		<div class="content">      <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="csstable">        <form name="form1" method="post" action="gouwu1.php">              <?php     $_SESSION["total"];     if($_GET['qk']=="yes")     {        $_SESSION['producelist']="";     $_SESSION['quatity']="";       }      $arraygwc=explode("@",$_SESSION['producelist']);      $s=0;      for($i=0;$i<count($arraygwc);$i++)      {          $s+=intval($arraygwc[$i]);      }     if($s==0 )       {       echo "<tr>";   echo" <td height='25' colspan='6' bgcolor='#FFFFFF' align='center'>您的購物車為空!</td>";   echo"</tr>";    }     else      {     ?><tr style="font-weight:bold">  <td width="125" height="25" bgcolor="#FFFFFF"><div align="center">商品名稱</div></td>  <td width="52" bgcolor="#FFFFFF"><div align="center">數量</div></td>  <td width="64" bgcolor="#FFFFFF"><div align="center">市場價</div></td>  <td width="64" bgcolor="#FFFFFF"><div align="center">會員價</div></td>  <td width="51" bgcolor="#FFFFFF"><div align="center">折扣</div></td>  <td width="66" bgcolor="#FFFFFF"><div align="center">小計</div></td>  <td width="71" bgcolor="#FFFFFF"><div align="center">操作</div></td></tr><?php/** * 購物車 商品數量管理*/$total=0;$array=explode("@",$_SESSION['producelist']);$arrayquatity=explode("@",$_SESSION['quatity']);//var_dump($array);     while(list($name,$value)=each($_POST))        {          for($i=0;$i<count($array)-1;$i++)          {             if(($array[$i])==$name)                {                  $arrayquatity[$i]=$value;                    }            }             }    $_SESSION['quatity']=implode("@",$arrayquatity);    for($i=0;$i<count($array)-1;$i++)     {         $id=$array[$i];       $num=$arrayquatity[$i];      if($id!="")       {      $sql="select * from  products where IDProduct='".$id."' and  user='$web'";  	    $info=$db->getdata($sql);$pics = json_decode($info['pics'], true);   if (isset($pics)) {                                        foreach ($pics as $key=>$v) {																				$product_pic=$pics[0];																				}}$PInfo=PInfo($id);$Price=$PInfo['iPrice'];       $total1=$num*$Price;       $total+=$total1;       $_SESSION["total"]=$total;   ?><tr>  <td height="25" width='150' bgcolor="#FFFFFF"><div align="center"><?php if ($product_pic==""){?><img src="/skin/default/../skin/v7red//skin/moban0_idc/resources/no_pic.png" style="width:60px;height:40px;" /> <?php }else{?><img src="<?=$product_pic?>" style="width:60px;height:40px;" /><?php }?><br><?php echo $info['ProductName'];?></div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center">      <input type="text" name="<?php echo $info['IDProduct'];?>" size="2" class="inputcss" value=<?php echo $num;?>>  </div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $PInfo['oPrice'];?>元</div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $PInfo['iPrice'];?>元</div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo @(ceil(($PInfo['iPrice']/$PInfo['oPrice'])*100))."%";?></div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $PInfo['iPrice']*$num."元";?></div></td>  <td height="25" bgcolor="#FFFFFF"><div align="center"><a href="removegwc.php?IDProduct=<?php echo $info['IDProduct']?>">移除</a></div></td></tr><?php                   }     }?><tr>  <td height="35" colspan="8" bgcolor="#FFFFFF"><div align="right">      <table width="500" height="25" border="0" align="center" cellpadding="0" cellspacing="0" style="border:0" class="csstable1">        <tr>          <td width="125"><div align="center"> <input type="submit" value="更改商品數量" class="buttoncss">          </div></td>          <td width="125"><div align="center"><a href="gouwu2.php">去收銀臺</a></div></td>          <td width="125"><div align="center"><a href="gouwu1.php?qk=yes">清空購物車</a></div></td>          <td width="195"><div align="left" style="color:red;font-size:24px">總計:<?php echo $total;?></div></td>        </tr>      </table> <?php    }   ?>	</div>	</div>	<div class="bx-b"><div class="bx-b2"></div></div></div></div></body></html>

3、清空購物車單個商品


<?session_start();require_once("../common/init.php");$web=get_web();if($_SESSION['User_S']=="")  {    echo "<script>alert('請先登錄,后購物!');history.back();</script>"; exit;  }   $IDProduct=$_GET['IDProduct'];$array=explode("@",$_SESSION['producelist']);$arrayquatity=explode("@",$_SESSION['quatity']);//var_dump($array);           for($i=0;$i<count($array)-1;$i++)          {             if(($array[$i])==$IDProduct)                {                                    unset($arrayquatity[$i]);				   unset($array[$i]);                 }            }             $_SESSION['quatity']=implode("@",$arrayquatity);    $_SESSION['producelist']=implode("@",$array);   die("<script>history.back()</script>");   ?>

4、填寫收貨信息。

<?session_start();require_once("../common/init.php");require_once("../user/security.inc.php");$web=get_web();$sql="select * from users where UserName='".$_SESSION['User_S']."' and user='$web'";  $uinfo=$db->getdata($sql);?><!DOCTYPE HTML><html><head><style>a{text-decoration:none;color:#3399ff}body{background:#fff}select {height:32px}.red {color:#f00 !important}body,button,input,select,textarea{line-height:150%;font-family:'微軟雅黑';font-size:14px; }.csstable {border:1px solid #ccc;margin-bottom:10px;line-height:220%;border-right:1px solid #eee;border-bottom:1px solid #eee;}.csstable td{border-bottom:1px solid #ccc;border-right:1px solid #ccc;padding:6px 5px 3px 5px;}.csstable .bar{font-weight:bold;background:url(images/bar.png);}.csstable .s{background:#eee;}input{border:1px solid #aaa;background:#fff;height:30px;}.buttoncss{background:#c00;color:#fff;border:0;padding:0px 30px;height:30px;}.buttoncss1{background:#ccc;color:#fff;border:0;padding:0px 10px;height:30px;width:40px;}</style></head><body><div class="part1  pad bgf yahei" style="padding:0px 20px">	<h3 class="font26" style="padding-bottom:2px;border-bottom:0px solid #ccc;"><span class="l title">  收貨人信息</span><span class="r more"></span></h3>	<div class="bx-c">		<div class="content">      <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="csstable">              <script language="javascript">/** * 購物車 收貨人信息 * Edit www.jb51.net*/function chkinput(form)    {      if(form.name.value=="")       {      alert("請輸入收貨人姓名!");      form.name.select();      return(false);    }    if(form.dz.value=="")       {      alert("請輸入收貨人地址!");      form.dz.select();      return(false);    }    if(form.yb.value=="")       {      alert("請輸入收貨人郵編!");      form.yb.select();      return(false);    }    if(form.tel.value=="")       {      alert("請輸入收貨人聯系電話!");      form.tel.select();      return(false);    }    if(form.email.value=="")       {      alert("請輸入收貨人E-mail地址!");      form.email.select();      return(false);    }    if(form.email.value.indexOf("@")<0)     {        alert("收貨人E-mail地址格式輸入錯誤!");        form.email.select();        return(false);     }    return(true);         }           </script>     <form name="form1" method="post" action="savedd.php" onSubmit="return chkinput(this)">      <tr> <td width="100" height="25" bgcolor="#FFFFFF"><div align="center">收貨人姓名:</div></td> <td width="183" bgcolor="#FFFFFF"><div align="left"><input type="text" name="Contact_GB" size="25" value="<?=$uinfo['Contact_GB']?>" class="inputcss" ></div></td> <td width="86" bgcolor="#FFFFFF"><div align="center">性別:</div></td> <td width="176" bgcolor="#FFFFFF"><div align="left"> <select name="sex">  <option selected value="男">男</option>  <option value="女">女</option> </select> </div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">詳細地址:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input name="dz" type="text" name="Addr_GB" value="<?=$uinfo['Province_GB']?><?=$uinfo['City_GB']?><?=$uinfo['Addr_GB']?>" class="inputcss" id="dz"  size="25"> </div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">郵政編碼:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="PostCode" size="25" value="<?=$uinfo['PostCode']?>" class="inputcss" ></div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">聯系電話:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="Tel" size="25" class="inputcss" value="<?=$uinfo['Tel']?>"></div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">電子郵箱:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="Email" size="25" class="inputcss"  value="<?=$uinfo['Email']?>" ></div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">送貨方式:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"> <select name="shff" id="shff">  <option selected value="虛擬發貨">虛擬發貨</option>  <option  value="普通平郵">普通平郵</option>  <option value="特快專遞">特快專遞</option>  <option value="送貨上門">送貨上門</option>   <option value="E-mail">E-mail</option>      </select></div></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center">支付方式:</div></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"> <select name="zfff" id="zfff">   <option selected value="網上支付">網上支付</option>  <option  value="銀行匯款">銀行匯款</option> </select> </div></td> </tr> <tr> <td height="100" bgcolor="#FFFFFF"><div align="center">簡單留言:</div></td> <td height="100" colspan="3" bgcolor="#FFFFFF"><div align="left"> <textarea name="ly" cols="60" rows="4" class="inputcss" style="background-color:#fff;border:1px solid #ccc " ></textarea></div></td> </tr> <tr style=""> <td height="45" colspan="4" bgcolor="#FFFFFF"><div align="center"><input type="submit"  value="提交訂單" class="button yahei bg4 buttoncss"> <a href="gouwu1.php" > [Back]</a> </div></td> </tr>   </form>           </tr></table>	</div>	</div>	<div class="bx-b"><div class="bx-b2"></div></div></div></div></body></html><!--<?php if($_GET['dingdanhao']!="")  {  $dd=$_GET['dingdanhao'];        $array=explode("@",$_SESSION['producelist']);  $sum=count($array)*20+260;    echo" <script language='javascript'>"; echo" window.open('showdd.php?dd='+'".$dd."','newframe','top=150,left=200,width=600,height=".$sum.",menubar=no,toolbar=no,location=no,scrollbars=no,status=no ')"; echo "</script>";  }?>-->

4、確認定單,并寫入數據庫,定單表和產品購買表雙記錄修改。


<?php
session_start();
require_once("../common/init.php");
require_once("../user/security.inc.php");
$web=get_web();
$sqls="select * from users where UserName='$_SESSION[User_S]' and user='$web'";
$info=$db->getdata($sqls);
$fIDProd=$_SESSION['producelist'];


$Num=$_SESSION['quatity'];


 $arrayNum=explode("@",$_SESSION['quatity']);
      $Num=0;
      for($i=0;$i<count($arrayNum);$i++)
      {
          $Num+=intval($arrayNum[$i]);
      }






$Contact_GB=$_POST['Contact_GB'];
$sex=$_POST['sex'];
$Addr_GB=$_POST['Addr_GB'];
$PostCode=$_POST['PostCode'];
$Tel=$_POST['Tel'];
$Email=$_POST['Email'];
$wuliu=$_POST['shff'];
$payment=$_POST['zfff'];
if(trim($_POST['ly'])=="")
{
$About="";
}
else
{
 $About=$_POST['ly'];
}
$UserName=$_SESSION['User_S'];
$dtCreate=date("Y-m-j H:i:s");
 //$dtExpiry=DATE_ADD(now(),INTERVAL $iYear YEAR)//SQL代碼
$iStatus=0;
$Amount=$_SESSION["total"];
$array=explode("@",$_SESSION['producelist']);
$arrayquatity=explode("@",$_SESSION['quatity']);
//var_dump($array);
     $IDHost=array();
          for($i=0;$i<count($array)-1;$i++)
          {
             


$sql="insert into host set UserName='$_SESSION[User_S]',fIDProd='{$array[$i]}',user='$web',Num={$arrayquatity[$i]},".
     
"dtCreate=now(),iStatus='0',dtExpiry=DATE_ADD(now(),INTERVAL $arrayquatity[$i] YEAR)";
$db->query($sql);
$IDHost[$i]=$db->insert_id();
          
                 
            }   

   $IDHosts=implode("|",$IDHost);


$IDProduct=implode("|",explode("@",$_SESSION['producelist']));
 $IDProduct=substr( $IDProduct, 0, -1); 






$oOrder = Order::AddOrderPL($IDProduct,$IDHosts,0,$About,1,$Num,"",1,$Amount,$Contact_GB,$sex,$Addr_GB,$PostCode,$Tel,$Email,$wuliu,$payment);
$display=($_CFG[PayOnline]==1)?"":"none";


$OrderID=$oOrder['OrderID'];
header("location:/user/onlinepay.php?Amount={$Amount}&OrderID=$OrderID");      
?>
5、后臺定單管理。


文章內容