【问题标题】:CodeIgniter not adding items into CartCodeIgniter 未将商品添加到购物车
【发布时间】:2013-11-15 18:22:29
【问题描述】:

所以,我有这个 CI 代码,由于某种原因,它没有添加到购物车中,但 info 端 $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());
?>

【问题讨论】:

  • 您有可以粘贴的购物车对象的插入功能吗?
  • 有什么错误吗?向我们展示购物车->插入
  • 没有错误或任何东西,只是没有添加数据。我知道购物车可以工作,我有另一个手动添加数据的功能,并且可以正常工作,但是这个 1,它都是自动的,它没有:(。我快疯了 >.

标签: php codeigniter shopping-cart


【解决方案1】:

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

【讨论】:

  • 我尝试删除信息并只保留要求,它仍然没有添加项目,但我的其他功能有效>。
猜你喜欢
  • 1970-01-01
  • 2016-12-19
  • 2020-01-14
  • 1970-01-01
  • 2015-03-28
  • 2015-03-31
  • 2018-04-10
相关资源
最近更新 更多