【发布时间】:2014-03-13 17:26:27
【问题描述】:
请问,您能帮我将产品添加到 CI 购物车吗?
我有这个添加购物车项目的功能:http://pastebin.com/QVTfa8WS
/**
* add product to the cart
*/
public function add_product_to_cart()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('qty', 'Quantity', 'required');
if ($this->form_validation->run() === FALSE) {
redirect($this->input->post('redirect_to'));
}
else {
$product = $this->products_model->get_product($this->input->post('product_id'));
$data = array(
'id' => $product['id'],
'qty' => $this->input->post('qty'),
'price' => $product['price'],
'name' => $product['title']
);
$row_id = $this->cart->insert($data);
redirect($this->input->post('redirect_to'));
}
}
看起来像这样 mi config.php 文件:http://pastebin.com/TiPZ8ta7
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
但是如果我调用函数来添加产品,它不会而且我无法找出错误在哪里。我拥有的会话的数据库表。
编辑: 问题出在 Cart.php 的第 197 行。就评论吧:)
【问题讨论】:
-
print_r($product) 长什么样子?
-
请将实际代码发布到您的 OP 中。将代码转储到 pastebin 链接是不可接受的。
-
没关系。如果我 print_r $data,我正在保存,那很好 - pastebin.com/y74HFN6K
-
哦,对不起 Sparky。我想,它更好。所以我不会再这样做了。
-
该链接中的价格为 0,对吗?
标签: codeigniter session cart