网店的MySQL数据库结构

我正在建立一个网上商店,我有一个问题。 我会有直接价格的产品(例如HTC Touch 2智能手机:299.00美元),但同时我会根据规格提供组合价格的产品: 在此图中,您可以看到数据库图表,我认为这对于多价格产品是可以的: 主要问题: 由于这是一个网上商店,人们会把物品放在购物车里。我认为插入购物车的商品应该来自同一张桌子(在我们的例子中,它将是
[combinations]
表,因为存储了价格)。 以下是这些表的一些数据,为了更清楚:
[products]
productid   |   productName
1           |   Nike T-Shirt
2           |   HTC Touch 2 Smartphone
[specifications]
specId   |   productId   |   specName
1        |   1           |   Size
2        |   1           |   Color
[specvalues]
specValueId   |   specId   |   svValue
1             |   1        |   L
2             |   1        |   XL
3             |   2        |   white
4             |   2        |   blue
5             |   2        |   red
[combinations]
(物品放入购物车)
combinationId   |   price   |   description
1               |   10      |   White L Nike T-Shirt
2               |   15      |   White XL Nike T-Shirt
3               |   11      |   Blue L Nike T-Shirt
4               |   16      |   Blue XL Nike T-Shirt
5               |   18      |   Red XL Nike T-Shirt
[combinationParts]
nmid   |   combinationId   |   specValueId
1      |   1               |   1
2      |   1               |   3
3      |   2               |   2
4      |   2               |   3
5      |   3               |   1
1      |   3               |   4
2      |   4               |   2
3      |   4               |   4
4      |   5               |   2
5      |   5               |   5
我希望我的图表和数据库人口确实有意义:)。 所以问题是如何存储单一价格的产品(HTC Touch 2智能手机),以便它可以像多种价格产品一样添加到购物车中。     
已邀请:
您可能想看看OpenCarts数据库..它实际上做得很好...... 实质上: 为以下内容创建表: 制品 产品选项(您的'spcifications') 产品选项值(您的'specvalues') 每个产品都会列在“产品表”中并有价格 在“产品选项”表中,您基本上列出了产品的不同“规格”...... 产品选项值表列出了实际选项和基本价格的变化(+/-)... 为了存储已完成的订单,OpenCart基本上具有相同的表...(与订单ID相关联) 我刚刚撕掉购物车功能来处理锦标赛的玩家注册...... 基础“产品”是玩家注册 - 25美元 'product_option'只列出'规范'/“注册类型” 对于“注册类型”,值存储在“product_option_value”表中... 他们可以注册为pay或pay&玩(付费和游戏进入迷你游戏) 薪水只是默认选项,价格没有变化...... 付费和游戏加价15美元(总共40美元) 我可以轻松地将多个“Product_options”和“product_option_value”集添加到产品中......每个都添加或减去运行总计的产品... 至于脚本方面,它只需要几个循环来查询和构建带有产品数组的数组,产品选项作为子产品数组,产品选项值作为每个产品选项数组的子数组 'product_option_value'表
--
-- Table structure for table `product`
--

CREATE TABLE IF NOT EXISTS `product` (
  `product_id` int(11) NOT NULL auto_increment,
  `site_id` int(11) NOT NULL,
  `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `description` text character set utf8 collate utf8_unicode_ci NOT NULL,
  `price` decimal(15,2) NOT NULL default '0.00',
  `date_available` date NOT NULL,
  `date_unavailable` date NOT NULL,
  `status` int(1) NOT NULL default '0',
  `date_added` datetime NOT NULL default '0000-00-00 00:00:00',
  `date_modified` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`product_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;

--
-- Dumping data for table `product`
--

INSERT INTO `product` (`product_id`, `site_id`, `name`, `description`, `price`, `date_available`, `date_unavailable`, `status`, `date_added`, `date_modified`) VALUES
(1, 2, 'Player Registration', 'This year we have two options:  Pay or Pay &amp; Play.<br />Pay &amp; Play allows you to enroll in the Flights Minigames for the weekend (Master''s Marks and Flights Doubles) and gives you twenty dollars worth of prize raffles.  <br />Pay &amp; Play is a $60.00 value and is only avalible during pre-registration.', 25.00, '2011-03-01', '2011-03-31', 1, '2011-03-01 00:00:00', '2011-03-01 00:00:00');

-- --------------------------------------------------------

--
-- Table structure for table `product_option`
--

CREATE TABLE IF NOT EXISTS `product_option` (
  `product_option_id` int(11) NOT NULL auto_increment,
  `product_id` int(11) NOT NULL,
  `sort_order` int(3) NOT NULL default '0',
  `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`product_option_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;

--
-- Dumping data for table `product_option`
--

INSERT INTO `product_option` (`product_option_id`, `product_id`, `sort_order`, `name`) VALUES
(1, 1, 1, 'Registration Type');

-- --------------------------------------------------------

--
-- Table structure for table `product_option_value`
--

CREATE TABLE IF NOT EXISTS `product_option_value` (
  `product_option_value_id` int(11) NOT NULL auto_increment,
  `product_option_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `price` decimal(15,2) NOT NULL,
  `prefix` char(1) collate utf8_bin NOT NULL,
  `sort_order` int(3) NOT NULL,
  `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`product_option_value_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ;

--
-- Dumping data for table `product_option_value`
--

INSERT INTO `product_option_value` (`product_option_value_id`, `product_option_id`, `product_id`, `price`, `prefix`, `sort_order`, `name`) VALUES
(1, 1, 1, 15.00, '+', 1, 'Pay &amp; Play'),
(2, 1, 1, 0.00, '', 2, 'Pay');
    
当你说'我认为插入购物车的物品应该来自同一张桌'时,你的头上钉了一针。 HTC手机应该存在于组合表中,只需作为单一组合。使用上面的示例,在组合表中插入另一个条目,例如:
---------------+-------------+------------------------
combinationId  |     price   |  description
---------------+-------------+------------------------
6              |     299     |  Base Model
---------------+-------------+------------------------
这解决了中间问题,并没有缺点。此外,当您的商店增长,并且HTC可能会发布具有不同价格带的新型号时,您已经拥有适合的数据库结构。 例如
---------------+-------------+------------------------
combinationId  |     price   |  description
---------------+-------------+------------------------
6              |     299     |  Base Model
7              |     349     |  Exclusive Edition
---------------+-------------+------------------------
    
在我看来,简单的解决方案是给智能手机只有一个规格记录的一个规格记录。这样,您可以保持每种类型的产品记录的结构完整。 只有一个选项时,只是不要在产品视图中显示任何可选选项。     

要回复问题请先登录注册