【问题标题】:Can´t add products to CodeIgniter Cart无法将产品添加到 CodeIgniter 购物车
【发布时间】: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


【解决方案1】:

正如 cmets 中所述,问题似乎是 price = 0 导致了问题。但是,作为noted here,这应该在几年前就已经解决了。

【讨论】:

  • 看起来很奇怪。如果我试图以 0 价格保存产品,它不起作用,但如果价格 > 0,它会起作用。所以......也许,他们再次创造了“错误”? :D
  • @JanKožušník,如果零作为字符串传递,"0" 是否重要?我在想 0 被解释为布尔错误。
  • @Sparky,有趣的想法,但不,如果我这样做:($product['price'] == 0 ? '0' : $product['price']) 它仍然不起作用
  • @JanKožušník,strval($product['price']) 呢?
  • 这是什么版本的 CodeIgniter?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-28
  • 2012-06-09
  • 1970-01-01
  • 1970-01-01
  • 2011-12-19
  • 2018-08-13
相关资源
最近更新 更多