Jump to content

carts table design for e-commerce


sKunKbad

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.