sKunKbad Posted January 4, 2014 Share Posted January 4, 2014 I'm using the current version of MySQL. I'm working on the planning stages for a proprietary e-commerce section of my website, and would like cart (basket) data to be stored in the database. The site visitor would be given a cookie that would reference the cart_id. I was thinking to serialize the cart data in a text field. Before I put too much time into this approach, I'd like to ask for input from phpfreaks members. Here is the carts table: CREATE TABLE IF NOT EXISTS `carts` ( `cart_id` varchar(40) NOT NULL COMMENT 'matches identifier in cookie', `user_id` int(10) unsigned DEFAULT NULL, `cart_data` text NOT NULL COMMENT 'serialized data', `created_at` datetime DEFAULT CURRENT_TIMESTAMP, `modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`cart_id`), FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; You will probably see that the user_id column is set to NULL by default. The idea would be that a site visitor may not be logged in while shopping, but the user_id could be applied once they do log in. I guess my main concern would be the serialization of the cart data. This would usually just include a simple array of product IDs, quantities, options, etc. Quote Link to comment https://forums.phpfreaks.com/topic/285079-carts-table-design-for-e-commerce/ Share on other sites More sharing options...
Solution Barand Posted January 4, 2014 Solution Share Posted January 4, 2014 I'm referring you to the answer I just gave to another member http://forums.phpfreaks.com/topic/285078-how-to-manage-databases-with-groups-of-somewhat-related-items/?do=findComment&comment=1463798 Quote Link to comment https://forums.phpfreaks.com/topic/285079-carts-table-design-for-e-commerce/#findComment-1463800 Share on other sites More sharing options...
sKunKbad Posted January 4, 2014 Author Share Posted January 4, 2014 Barand, thanks for the link. I watched the first 8 videos, and having never heard of such things, found it very interesting. I only stopped watching because I had to go to bed, but plan on watching the rest of the videos today. Quote Link to comment https://forums.phpfreaks.com/topic/285079-carts-table-design-for-e-commerce/#findComment-1463840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.