[英]how to echo all products in shopping cart to paypal
我只是在学习php的绳索,并且正在为uni项目构建一个电子商务站点,我已经完成了全部工作,并通过paypal设置了付款,这是我通过一些教程完成的。
当我转到贝宝时,我想显示; 订单摘要中购物车中每个商品的商品名称,价格和数量。
在其当前状态http://pastie.org/3127790 ,代码仅在paypal上的订单摘要中显示购物车中的顶部商品,我想我需要实现一个foreach循环来告诉代码回显所有行购物车,但是不确定到底要循环播放什么以及如何循环播放。
任何帮助将不胜感激!
预先感谢迈克尔
程式码片段
<?php
$sql = "SELECT * FROM podcasts WHERE id_podcasts IN (";
foreach ($_SESSION['cart'] as $id => $value){
$sql .= $id . ",";
}
$sql = substr($sql,0,-1).") ORDER BY name ASC";
$query = mysql_query($sql);
$total_price = 0;
if(!empty($query)){
while($row = mysql_fetch_array($query)){
$subtotal = $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];
$total_price += $subtotal;
?>
<?php
$ppname = $row['name'];
$_SESSION['cart'][$row['id_podcasts']]['name'] = $row['name'];
$ppquantity = $_SESSION['cart'][$row['id_podcasts']]['quantity'];
$ppprice= $row['price'];
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $_SESSION['cart'][$row['id_podcasts']]['quantity'];?></td>
<td><?php echo "£" . $row['price'];?></td>
<td><?php echo"£" . $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];?></td>
</tr>
<?php
} }
?>
<tr>
<td></td>
<td></td>
<td><span>Total Price:</td></span>
<td><span><?php echo"£" . $total_price;?></td></span>
</tr>
</table>
</div>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="payme_1321908135_biz@immbudden.com"> <!-- change to your paypal address -->
<input type="hidden" name="quantity" value="<?php echo $ppquantity;?>"> <!-- do not change, since you refer to it all via the database -->
<input type="hidden" name="item_name" value="<?php echo $ppname;?>">
<input type="hidden" name="amount" value="<?php echo $ppprice;?>"> <!-- change here -->
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="custom" value="<?php echo $_SESSION['emailaddress'];?>"> <!-- if you store their purchase in a database, reference the database number here -->
<input type="hidden" name="return" value="http://shop.residencyradio.com/success.php">
<span class="input_btn"><input type="submit" name="purchase" value="Purchase" ></span>
</form>
问题是如何分别为每个用户创建一个视图购物车,贝宝链接为我网站上的所有用户创建一个全局购物车
我只回答你的问题。 我不确定您所有代码的有效性。
我对您粘贴的一些代码进行了一些更改:
<?php
$output_paypal = ''; // container for output for paypal form
$total_items = 0;
if ( ! empty($query))
{
while ($row = mysql_fetch_array($query))
{
$subtotal = $_SESSION['cart'][$row['id_podcasts']]['quantity'] * $row['price'];
$total_price += $subtotal;
$ppname = htmlspecialchars($row['name']);
$_SESSION['cart'][$row['id_podcasts']]['name'] = $row['name']; // this assigment seems not useful
$ppquantity = $_SESSION['cart'][$row['id_podcasts']]['quantity'];
$ppprice = $row['price'];
$total_items ++;
$output_paypal .= <<<EOM
<input type="hidden" name="item_name_{$total_items}" value="$ppname">
<input type="hidden" name="quantity_{$total_items}" value="$ppquantity">
<input type="hidden" name="amount_{$total_items}" value="$ppprice">
EOM; // heredoc syntax (may not be any spaces or tabs before or after the semicolon.)
?>
<tr>
<td><?php echo $ppname; ?></td>
<td><?php echo $ppquantity; ?></td>
<td><?php echo "£" . $ppprice; ?></td>
<td><?php echo"£" . $ppquantity * $ppprice; ?></td>
</tr>
<?php
}
}
?>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="payme_1321908135_biz@immbudden.com">
<?php echo $output_paypal; ?>
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="custom" value="<?php echo $_SESSION['emailaddress']; ?>">
<input type="hidden" name="return" value="http://shop.residencyradio.com/success.php">
<span class="input_btn"><input type="submit" name="purchase" value="Purchase" ></span>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.