【发布时间】: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