Monday, October 7, 2013

codeigniter shopping cart items example

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home extends HO_Controller {

    public function index() {
        $this->load->library('cart');
        $items = $this->cart->contents();
        if (!isset($items) || empty($items)) {

            $data = array(
                'id' => 2546,
                'qty' => 1,
                'price' => 39.95,
                'name' => 'T-Shirt',
                'options' => array('Size' => 'L', 'Color' => 'Red')
            );
            $this->cart->insert($data);
        } else {
            foreach ($items as $data) {
                echo $data['name'].'->'.$data['price'];
            }
        }
    }

}

?>

No comments: