versatilewt wrote:Mark,
Thanks for the reply. My only issue with that is storing unnecessary data.
The address of a previous order is NOT unnecessary.
I'm trying to keep the database size down, and I could see repeat customers having their address stored over and over. I haven't had much experience with this, so I'm not sure if it's much of an issue.
Keeping the database size down is a pointless thing to do in this context. You absolutely NEED to store this information per order. There is absolutely no way it can be allowed to change- it's just wrong.
Likewise, product names, prices etc, need to be stored on the order with the SKUs so that if they subsequently change (or are deleted etc), you can see what the customer really bought.
Do you see a major problem with the idea of having an "active/inactive" flag, and if a user wants to "edit" an address, what they're really doing is marking the address that has been used in a previous order as inactive (for their address book purposes) and creating a new address?
Unnecessarily complicated. An order will typically have exactly two addresses, shipping and billing. No order has less than this (although they could be the same) or more. Therefore, there's no need to store them in a separate table at all.
For reference, our order_head table looks like this:
CREATE TABLE `order_head` (
`id` int(11) NOT NULL auto_increment,
`customer_id` int(11) NOT NULL,
`status` int(11) NOT NULL,
`created_date` datetime NOT NULL,
`confirmed_date` datetime default NULL,
`language_code` char(2) NOT NULL,
`billing_title` varchar(5) default NULL,
`billing_name` varchar(90) default NULL,
`billing_email` varchar(50) default NULL,
`billing_address` text,
`billing_postcode` varchar(20) default NULL,
`billing_country_code` char(2) default NULL,
`billing_country` varchar(30) default NULL,
`billing_telephone` varchar(30) default NULL,
`billing_fax` varchar(30) default NULL,
`shipping_title` varchar(5) default NULL,
`shipping_name` varchar(90) default NULL,
`shipping_address` text,
`shipping_postcode` varchar(20) default NULL,
`shipping_country_code` char(2) default NULL,
`shipping_country` varchar(30) default NULL,
`shipping_method_index` int(11) NOT NULL default '0',
`total` decimal(10,2) NOT NULL default '0.00',
`payment_total` decimal(10,2) NOT NULL default '0.00',
`payment_refunds` decimal(10,2) NOT NULL default '0.00',
`payment_module_code` varchar(10) default NULL,
`payment_module_name` varchar(100) default NULL,
`payment_info` blob,
`http_headers` text,
`remote_address` varchar(16) default NULL,
`affiliate_id` int(11) default NULL,
`affiliate_credited_amount` decimal(10,2) default '0.00',
`affiliate_commission` decimal(2,2) default NULL,
`original_referrer` varchar(200) default NULL,
`discount_code` varchar(10) default NULL,
`comments` text,
`payment_attempted` tinyint(4) NOT NULL default '0',
`last_payment_attempt_date` datetime default NULL,
`original_billing_title` varchar(5) default NULL,
`original_billing_name` varchar(90) default NULL,
`original_billing_email` varchar(50) default NULL,
`original_billing_address` text,
`original_billing_postcode` varchar(20) default NULL,
`original_shipping_title` varchar(5) default NULL,
`original_shipping_name` varchar(90) default NULL,
`original_shipping_address` text,
`original_shipping_postcode` varchar(20) default NULL,
`is_gift` tinyint(4) NOT NULL default '0',
`gift_message` text,
PRIMARY KEY (`id`),
KEY `customer_id` (`customer_id`),
KEY `status` (`status`),
KEY `created_date` (`created_date`),
KEY `ix_order_head_payment_attempted` (`payment_attempted`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Yes, 49 columns. We have considered at every point splitting it up and never found a good reason to do so.
Mark