[eluser]WanWizard[/eluser]
I've quickly converted the Cart class to a Multicart class.
It is compatible with CI's Cart class, you can slot it in without code modifications by loading it like this:
Code:
$this->load->library('Multicart', array(), 'cart');
It adds a new method create() which allows you to create new named carts. All other methods ( except format_number() ) have an optional extra parameter to pass the name of the cart. To provide backward compatibility, it creates a cart named 'default' when you load the library, which all method calls will use if you don't pass a cart name.
Example:
Code:
$this->load->library('Multicart', array(), 'cart');
$this->cart->create('cart1');
$data1 = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
)
);
$this->cart->insert($data1, 'cart1');
print_r($this->cart->contents('cart1'));
$this->cart->destroy('cart1');
$this->cart->create('cart2');
$data2 = array(
array(
'id' => 'sku_567ZYX',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
)
);
$this->cart->insert($data2, 'cart2');
print_r($this->cart->contents('cart2'));
// shows the 'default' cart, so no contents
print_r($this->cart->contents());
// what's in session storage right now?
print_r($this->CI->session->userdata('cart_contents'));