Welcome Guest, Not a member yet? Register   Sign In
Cart contents is not working
#1

[eluser]sridhar2do[/eluser]
Hi,

I'm trying to create a cart, but its not working.

cart.php (Controller)

Code:
class Cart extends CI_Controller{
function addnew(){
  $data = array(
               'id'      => 'sku_123ABC',
               'qty'     => 1,
               'price'   => 39.95,
               'name'    => 'T-Shirt'
            );

  $this->cart->insert($data);
  echo 'Cart Added Sucessfully.....';
}

function show(){
  $cart = $this->cart->contents();

  print_r($cart);
}
}

When i call show() it gives empty array()
how to check weather the cart library is added or not
do i need to add session

autoload.php
Code:
$autoload['libraries'] = array('cart', 'database', 'session');

Using CodeIgniter 2.1.3 latest version
help me out
#2

[eluser]sridhar2do[/eluser]
Sorry guys, its my mistake.

i have changed

$config['sess_use_database'] = TRUE;

to

$config['sess_use_database'] = FALSE;

now its working fine.
#3

[eluser]RogerMore[/eluser]
Hey,

Your last post states that you changed sess_use_database to:

Code:
$config[‘sess_use_database’] = FALSE;

When sessions aren't stored in the database, they are stored in cookies. That won't have to be a problem if you only store a couple of things in your session. The problem is that a cookie can only hold around 4096 bytes of data (give or take, that's browser specific). So if you are storing some data aside from data for login reason like a lot of cart data, your session memory is going to run out very quickly.

My recommendation is that you get the sessions to use the database to store data in stead of the cookies, to ensure that your customers won't have the problem that they can't add products to the cart after the cookie limit is reached.

To use the sessions in the database, set the sess_use_database back to TRUE like so:

Code:
$config[‘sess_use_database’] = TRUE;

and make sure you create a sessions table in the database for the sessions storage:

Code:
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);

And last but not least, edit your database config file to match you database settings.

If you can use CI to access your database and your ci_sessions table is created, you're ready!

Greetings,

Roger




Theme © iAndrew 2016 - Forum software by © MyBB