Welcome Guest, Not a member yet? Register   Sign In
Cart session data -- I'm not seeing it
#1

[eluser]jbibbings[/eluser]
I am trying to figure out how CI saves its cart session data to the database. I am expecting to see some information called 'cart_contents' in the user_data field. I have set up the ci_sessions table as outlined in the Session docs, and have the sessions saving to the DB.

I am using CI Version 2.0, PHP 5.2, MySQL 5.1.37


I have set up a test controller like so:

Quote:<?php

class Test extends CI_Controller{


function index(){

$this->output->enable_profiler(TRUE);
$this->load->library('cart');
$product_id = '65-232324-21';
$price = '50.00';
$name = 'Hello Yeah OK';
$add_qty = 1;

$add_data = array(
'id' => $product_id,
'qty' => $add_qty,
'price' => $price,
'name' => $name,
'foo' => 'bar',
'game' => 'on',
'choco' => 'yum'
);

// add the item to the cart
$this->cart->insert($add_data);

$this->load->view('test');


}


}


I have set up a view just to display the cart data like so:

Quote:<h1>Yeah whatever</h1>

&lt;?php foreach ($this->cart->contents() as $items): ?&gt;
<ul>
<li>&lt;?php echo $items['name']; ?&gt;</li>
<li>&lt;?php echo $items['id']; ?&gt;</li>
<li>&lt;?php echo $items['qty']; ?&gt;</li>
<li>&lt;?php echo $items['price']; ?&gt;</li>
</ul>

&lt;?php endforeach; ?&gt;


The items I have saved to the cart, are correctly displaying in the view. However, I do not see them in the ci_sessions table.


A typical entry in the user_data field looks like this:

Code:
a:2:{s:15:"flash:old:token";s:32:"302c1c0076988d68bd5382f9a016e3d2";s:15:"flash:new:token";s:32:"15ba88063f8cd4567c3b34306c584cbf";}

There is no cart_contents information here so I am unsure - where is CI storing all of this data? Am I crazy?
#2

[eluser]Eric Barnes[/eluser]
I just tried to duplicate this with the latest and didn't have any problems. Can you try downloading the tip from bitbucket?
https://bitbucket.org/ellislab/codeignit...839eaf.zip
#3

[eluser]jbibbings[/eluser]
Ok thanks, yeah.

It is working now. The cart_contents data is saved in the DB, and looks like normal.

I found this issue in a fork of the "Community Cart" project. It appears to use the core Cart.php library. It is really strange because I can use cart->insert() and cart->contents() to save and view the data, but I have no idea where this data is actually being stored...




Theme © iAndrew 2016 - Forum software by © MyBB