By default Codeigniter shopping cart class uses its built-in session functions. Session class in CI can be configured to use cookie or database, which means the shopping cart will EITHER use database or cookie to store session variables.
However for my site I want to implement this: when the user is not logged in, the cart uses cookie data; when the user is logged in, the cart uses data stored in database. This means the cart class should be able to switch between cookie and database.
How can I achieve that while not making changes to the built-in cart class? If that’s not possible I may have to rewrite the cart class which takes some work.
There are two methods possible.
Inherit your inbuilt card class and override the product_insert, product_update and product_delete methods. This is cleaner and provides you with better customizability. The feature you need is pretty trivial and you can do it with something like this.
override all the crud methods like this and you can achieve what you want.
http://codeigniter.com/forums/viewthread/212926/P10/#1006680
it has some features that you need but still you will have to tweak it to suite your requirements exactly