codeigniter CodeIgniter Shopping Cart Basic Elements of CI Shopping Cart


As we can add multiple elements in Cart array and then add it to cart session, but there are 4 basic elements which Cart class requires to add data successfully in cart session.

  1. id (string)
  2. qty (number)
  3. price (number, decimal)
  4. name (String)

And if you want to add more options regarding product then you can use 5th element which is "options". you can set array of options in this element.

It will look like this :

$cartItem = array(
    'id'      => 'MOTOG5',
    'qty'     => 5,
    'price'   => 100.99,
    'name'    => 'Motorola Moto G5 - 16 GB',
    'options' => array(
                    'ram' => '3GB',
                    'Color' => 'Fine Gold'