【发布时间】:2015-11-30 15:51:31
【问题描述】:
我创建了我的购物车,非常适合添加多个商品。然后,这将遍历每个项目并显示图像、名称、数量和总价。
我添加了一个 paypal 按钮并试图让它工作,但我不确定为什么它没有收到任何东西。我总是收到“检测到错误,购物车中没有任何内容”。
我还打印出我的变量以确保它们是正确的,但看起来它仍然没有在表单中被选中。
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="business@gmail.com">
for ($i = 0; $i < count($cart); $i++) {
$s += $cart[$i]->price * $cart[$i]->quantity;
$ppName = $cart[$i]->name;
$ppAmount = $cart[$i]->price * $cart[$i]->quantity;
$ppQuantity = $cart[$i]->quantity;
// Inside of for each loop
?>
<input type="hidden" name="item_name_<?php echo $x; ?>" value="<?php echo $ppName; ?>">
<input type="hidden" name="amount_<?php echo $x; ?>" value="<?php echo $ppAmount; ?>">
<input type="hidden" name="quantity_<?php echo $x; ?>" value="<?php echo $ppQuantity; ?>">
<tr>
<td class="col-md-2"><img class="img-responsive" img src= '<?php echo $cart[$i]->image_name; ?>' alt="Oops, Image cannot be found!" height="150" width="150"/></td>
<td class="col-md-4">Name: <?php echo $cart[$i]->name; ?><br><br> <?php echo $cart[$i]->description; ?></td>
<td class="col-md-4"> <a href="checkout.php?index=<?php echo $index; ?>" onclick="return confirm('Are you sure?')"><span class="glyphicon glyphicon-minus"></a></span> Qty <?php echo $cart[$i]->quantity; ?> <span class="glyphicon glyphicon-plus"></span></td>
<td><?php echo $cart[$i]->price * $cart[$i]->quantity; ?></td>
</tr>
<br>
<?php
$index++;
$x = $i + 1;
?>
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="hosted_button_id" value="2R2BAJEWK3LRU">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
如有任何反馈,我将不胜感激。 非常感谢。
【问题讨论】:
标签: php paypal shopping-cart