CodeIgniter Forums

Full Version: Cart session data -- I'm not seeing it
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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:


class Test extends CI_Controller{

function index(){

$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




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;
<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>

&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:


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

El Forum

[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?

El Forum

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...