num_cart_items返回空

时间:2014-03-03 19:44:54

标签: paypal paypal-ipn

我正在使用IPN模拟器将数据发布到我的IPN处理程序。除此之外,其他一切都很好。

$num_cart_items = $_POST['num_cart_items'];

$tuotteet = array();
for($i = 1; $i <= $num_cart_items; $i++) {
    $tuotteet[] = array('nimi'=>$_POST['item_name' . $i], 'maara'=>$_POST['quantity' . $i]);
}
$products = implode(" ", array_map(function ($entry) { return $entry['maara'].'x '.$entry['nimi'].'<br />'; }, $tuotteet));

当我尝试将$ products保存到数据库时,我得到空值。我也尝试保存$ num_cart_items,并且显示为空。

1 个答案:

答案 0 :(得分:1)

你走了。这将加载$ cart_items,其中包含您可以轻松遍历的所有单个项目,或者直接序列化和保存。

// Cart Items
$num_cart_items = isset($_POST['num_cart_items']) ? $_POST['num_cart_items'] : '';

$i = 1;
$cart_items = array();   
while(isset($_POST['item_number' . $i]))   
{   
    $item_number = isset($_POST['item_number' . $i]) ? $_POST['item_number' . $i] : '';   
    $item_name = isset($_POST['item_name' . $i]) ? $_POST['item_name' . $i] : '';   
    $quantity = isset($_POST['quantity' . $i]) ? $_POST['quantity' . $i] : '';  
    $mc_gross = isset($_POST['mc_gross_' . $i]) ? $_POST['mc_gross_' . $i] : 0;
    $mc_handling = isset($_POST['mc_handling' . $i]) ? $_POST['mc_handling' . $i] : 0;
    $mc_shipping = isset($_POST['mc_shipping' . $i]) ? $_POST['mc_shipping' . $i] : 0;
    $custom = isset($_POST['custom' . $i]) ? $_POST['custom' . $i] : '';   
    $option_name1 = isset($_POST['option_name1_' . $i]) ? $_POST['option_name1_' . $i] : '';   
    $option_selection1 = isset($_POST['option_selection1_' . $i]) ? $_POST['option_selection1_' . $i] : '';   
    $option_name2 = isset($_POST['option_name2_' . $i]) ? $_POST['option_name2_' . $i] : '';   
    $option_selection2 = isset($_POST['option_selection2_' . $i]) ? $_POST['option_selection2_' . $i] : '';
    $option_name3 = isset($_POST['option_name3_' . $i]) ? $_POST['option_name3_' . $i] : '';   
    $option_selection3 = isset($_POST['option_selection3_' . $i]) ? $_POST['option_selection3_' . $i] : '';
    $option_name4 = isset($_POST['option_name4_' . $i]) ? $_POST['option_name4_' . $i] : '';   
    $option_selection4 = isset($_POST['option_selection4_' . $i]) ? $_POST['option_selection4_' . $i] : '';
    $option_name5 = isset($_POST['option_name5_' . $i]) ? $_POST['option_name5_' . $i] : '';   
    $option_selection5 = isset($_POST['option_selection5_' . $i]) ? $_POST['option_selection5_' . $i] : '';
    $option_name6 = isset($_POST['option_name6_' . $i]) ? $_POST['option_name6_' . $i] : '';   
    $option_selection6 = isset($_POST['option_selection6_' . $i]) ? $_POST['option_selection6_' . $i] : '';
    $option_name7 = isset($_POST['option_name7_' . $i]) ? $_POST['option_name7_' . $i] : '';   
    $option_selection7 = isset($_POST['option_selection7_' . $i]) ? $_POST['option_selection7_' . $i] : '';
    $option_name8 = isset($_POST['option_name8_' . $i]) ? $_POST['option_name8_' . $i] : '';   
    $option_selection8 = isset($_POST['option_selection8_' . $i]) ? $_POST['option_selection8_' . $i] : '';
    $option_name9 = isset($_POST['option_name9_' . $i]) ? $_POST['option_name9_' . $i] : '';   
    $option_selection9 = isset($_POST['option_selection9_' . $i]) ? $_POST['option_selection9_' . $i] : '';

    $btn_id = isset($_POST['btn_id' . $i]) ? $_POST['btn_id' . $i] : '';

    $current_item = array(   
                           'item_number' => $item_number,   
                           'item_name' => $item_name,   
                           'quantity' => $quantity, 
                           'mc_gross' => $mc_gross, 
                           'mc_handling' => $mc_handling, 
                           'mc_shipping' => $mc_shipping, 
                           'custom' => $custom,   
                           'option_name1' => $option_name1,   
                           'option_selection1' => $option_selection1,   
                           'option_name2' => $option_name2,   
                           'option_selection2' => $option_selection2, 
                           'option_name3' => $option_name3, 
                           'option_selection3' => $option_selection3, 
                           'option_name4' => $option_name4, 
                           'option_selection4' => $option_selection4, 
                           'option_name5' => $option_name5, 
                           'option_selection5' => $option_selection5, 
                           'option_name6' => $option_name6, 
                           'option_selection6' => $option_selection6, 
                           'option_name7' => $option_name7, 
                           'option_selection7' => $option_selection7, 
                           'option_name8' => $option_name8, 
                           'option_selection8' => $option_selection8, 
                           'option_name9' => $option_name9, 
                           'option_selection9' => $option_selection9, 
                           'btn_id' => $btn_id
                          );   

    array_push($cart_items, $current_item);   
    $i++;   
}