Jump to content

carts table design for e-commerce


sKunKbad
Go to solution Solved by Barand,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.