How about you create a permanent table "cart" and just track them via Session ID? Start a session when they enter your site. Add that session ID to the cart table, then when they make purchases, just add them to the table (either as multiple rows, or just comma separated item IDs, or as a serialized array or something). Then, if they happen to log in, you can add their UserID to the table with their session ID. Then if they want to "store" that you can copy all rows to a more "stored carts" table.
Here would be my basic layout:
users
ID_CART int(11) NOT NULL AUTO_INCREMENT
ID_SESS SMALLTEXT NOT NULL
ID_USER int(11) NULL
item int(11) NOT NULL
temp_cart
ID_CART int(11) NOT NULL
ID_ITEM int(11) NOT NULL
saved_cart
ID_USER int(11) NOT NULL
items varchar(255) NOT NULL
Basically, when you visit the site, the "users" table is automatically populated with a session ID and a corresponding "cart ID". This cart ID is what links the user to items in the cart. Then when they save their cart items, all items in the temp_cart table are serialized into an array (or imploded on a comma) and put into the "saved_cart" table. Then later on (since they'll have to create an account, the user ID will link saved carts.
The temporary table will automatically be dropped once the connection is severed. Some say a work is to create a temporary table, then another and merge the two [See the User Notes]. You might try using a persistent connection to see if that helps. Just make sure you explicitly close it later in your application.