代码点火器不会将商品添加到购物车中


CodeIgniter not adding items into Cart

所以,我有这个CI代码,由于某种原因,它没有添加到购物车中,但信息端$data确实打印出来很好。有人知道它发生了什么吗?它曾经工作得很好,我已经有一段时间没有碰过这个功能了。我确实有一个 if 语句来检查参数是否已设置。

<?php
/* test data
$this->input->post('product_id') = 1
$this->input->post('name')       = 'ballons'
$this->input->post('qty')        = 10
$price                           = 9.99
$this->input->post('img')        = 'http://example.com/product_img.jpg'
$this->input->post('special_instructions') = 'long string explenation'
$this->input->post('options')    = array('color' => 'red')
*/
// set cart's info
$data = array(
'id'        => $this->input->post('product_id'),
'name'      => $this->input->post('name'),
'qty'       => $this->input->post('qty'),
'price'     => $price,
 'img'      => $this->input->post('img')
);
// check if special instructions are set
if($this->input->post('special_instructions'))
    $data['special_instructions'] = $this->input->post('special_instructions');
// check if options are available
if($this->input->post('options'))
    $data['options'] = array('type' => $this->input->post('options'));

// add data to cart
$this->cart->insert($data);
die(print_r($data).$this->cart->contents());
?>

我的猜测是你超过了分配给cookie的4K。这是要存储在购物车中的大量信息。我建议从购物车会话中删除其中一些字段,并在需要时从数据库中检索它们。