我已经建立了一个使用 PayPal 的购物车。如果用户购买了两种产品,则阵列将被发送到 IPN。我不确定如何使用分隔符来创建新的产品信息变量。例如,这是用户购买的:
数组如下所示:
35 *-* 1 *-* XS *-* BO-CB005B Mountain Bke Entry Level, 33 *-* 1 *-* XS *-* B014 Mountian Bike,
发送给用户的电子邮件仅显示第一个逗号后的最后一个产品。我想显示所有订购的产品,而不是最后一个。
如何显示所有数组而不是最后一个?
这是购物车中将数组发送到 IPN 的代码:
$product_id_array .= "$item_id *-* " .$each_item['quantity']." *-* " . $each_item['size'] . " *-* ". $product_name . ", ";
这是 IPN 脚本中的代码
$product_id_string = $_POST['custom'];
$product_id_string = rtrim($product_id_string, ","); // remove last comma
// Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount
$id_str_array = explode(",", $product_id_string); // Uses Comma(,) as delimiter(break point)
$fullAmount = 0;
foreach ($id_str_array as $key => $value) {
$id_quantity_pair = explode("*-*", $value); // Uses Hyphen(-) as delimiter to separate product ID from its quantity
$product_id = $id_quantity_pair[0]; // Get the product ID
$product_quantity = $id_quantity_pair[1]; // Get the quantity
$product_size = $id_quantity_pair[2];
$product_name = $id_quantity_pair[3];
$productInfo = "ID: <strong>$product_id</strong> <br />Name: <strong>$product_name</strong><br />Quantity: <strong>$product_quantity</strong><br />Size: <strong>$product_size</strong>";
$sql = mysql_query("SELECT price FROM productList WHERE id='$product_id' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$product_price = $row["price"];
}
$product_price = $product_price * $product_quantity;
$fullAmount = $fullAmount + $product_price;
}
'custom' 是发送到 paypal 的隐藏值:
<input type="hidden" name="custom" value="'.$product_id_array.'">