Store Values of Cart in Database before checkout

i am developing a e-commerce project in Codeigniter. I want that any user can add products in cart but when he want to checkout he has to logged in the website after that he can checkout. But when i tried this after user login the cart data is lost. How can i store the data before the checkout so that data in the cart not lost.