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. Link to comment https://forums.phpfreaks.com/topic/285079-carts-table-design-for-e-commerce/ Share on other sites More sharing options...
Barand Posted January 4, 2014 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 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. 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
Archived
This topic is now archived and is closed to further replies.