Simple shopping cart jQuery plugin using local storage.
Include script after the jQuery library (unless you are packaging scripts somehow else):
<script src="/path/to/jquery.shoppingcart.js"></script>
Add item:
$.shoppingcart('add',{
'id': 123,
'image': 'path/to/image.png',
'name': 'ProductName',
'code': 'Product123',
'url': 'catalog/clothes/product/123',
'attributes': ['S', 'Black'],
'price': 30,
'count': 1
});
Only id & price are required!
Edit item:
$.shoppingcart('edit',{
'id': 123,
'image': 'path/to/newImage.png',
'name': 'ProductNewName',
'code': 'ProductNew123',
'url': 'catalog/clothes/product/123',
'attributes': ['M', 'White'],
'price': 60,
'count': 2
});
Only id is required!
Remove item:
$.shoppingcart('remove', {'id': 123});
Clear cart:
$.shoppingcart('clear');
Get items count:
// Returns integer
$.shoppingcart('getCount');
Get total cart price:
// Returns float
$.shoppingcart('getPrice');
Get item by id:
// Returns object { 'id', 'image', 'name', 'code', 'url', 'attributes', 'price', 'count' }
$.shoppingcart('getById', id);
Get all cart items:
// Returns ARRAY of object { 'id', 'image', 'name', 'code', 'url', 'attributes', 'price', 'count' }
$.shoppingcart('getAll');