codeigniter插入数据的购物车问题

codeigniter插入数据的购物车问题

问题描述:

i am new to code-igniter. here i am using shopping cart for product checkout. when i am add product to cart it's working for first three products, after adding any product consider as fourth product. if any product add to cart after three products it will replace the existing fourth product. but only first three product display on cart, and the fourth one not display and also i cant add more than four products on cart, i am using jquery ajax for cart update

jquery ajax code

$('.addcart').click(function(){
    var proid=$(this).attr('id');           
    $.post('<?php echo base_url()?>productajax',{typ:'addtocart',proid:proid},function(data){           

    })
    return false;
})

product add to cart code



 $proid=$this->input->post('proid');
                    $this->db->where('pro_id',$proid);
                    $data=$this->db->get('product')->result();
                    foreach ($data as $pro)
                    {
                        $proname=$pro->pro_name;
                        $price=$pro->s1price;

                        $proimg=$pro->image_name;
                        $nwt=$pro->case_netweight;
                        $gwt=$pro->case_grossweight;
                        $cbm=$pro->cbm;
                    }

                    $propriceinr =round($price + round(($price * $this->session->userdata('user_margin'))/100,2));          

                    $dat = array(
                   'id'      => $proid,
                   'qty'     => 1,
                   'price'   => $propriceinr,
                   'name'    => $proname,
                   'options' => array('cbm' => $cbm, 'nwt' => $nwt,'gwt'=>$gwt,'image' => $proimg ,'price'=>$price,)
                );              
                    $this->cart->insert($dat);

config.php

$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']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;

i don't know the product cart why not update after insert three product. give me a guidance for this issue anyone. thanks advance

Please set

$config['sess_use_database'] = FALSE;

to $config['sess_use_database'] = TRUE; in your config.php.

Right now your products details are being saved in cookie which has the maximum limit of 4kb.
By enabling $config['sess_use_database'] = TRUE;.

This feature lets you insert your information in database table i.e:

$config['sess_table_name'] = 'ci_sessions';.

Hope that will work for you

If you dont have ci_sessions table here is the query for that:

 CREATE TABLE `ci_sessions` (
 `session_id` varchar(40) NOT NULL DEFAULT '0',
 `ip_address` varchar(16) NOT NULL DEFAULT '0',
 `user_agent` varchar(50) NOT NULL,
 `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Try to disable csrf protection in application/config/config.php

$config['csrf_protection']  = FALSE;

Then, if ajax call start working, enable it again and add ci_csrf_token variable to ajax call.