我正在建立一个网上商店,我有一个问题。我将有直接价格的产品(例如HTC Touch2智能手机: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 Touch2智能手机),以便它可以像多价产品一样添加到购物车中。
发布于 2011-03-10 19:33:57
你可能想看看OpenCarts数据库..它在这方面做得很好。
本质上:
为以下项创建一个表:产品产品选项(您的“规范”)产品选项值(您的“specvalue”)
每种产品都会在“产品表”中列出,并在“产品选项”表中有一个价格,你实际上列出了产品的不同“规格”……
产品选项值表列出了实际选项和对基本价格(+/-)的更改...
为了存储完成的订单,OpenCart本质上具有相同的表...(关联了订单id )
最近,我删除了购物车功能,以处理球员注册的锦标赛…
基本的‘产品’是一个播放器注册- $25 'product_option‘只是列出了’规格‘/’注册类型‘
对于“注册类型”,值存储在“product_option_value”表中...他们可以注册为pay或pay & play (pay & play进入迷你游戏),pay只是默认选项,不改变价格……Pay and Play加15美元(总共40美元)
我可以很容易地将多个"Product_options“和"product_option_value”集合添加到产品中...每一个或加或减乘积运行总数...
在脚本端,查询和构建数组只需要几次循环,其中products数组将产品选项作为产品的子数组,产品选项值作为每个产品选项数组的子数组
'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 & Play.<br />Pay & 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 & 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 & Play'),
(2, 1, 1, 0.00, '', 2, 'Pay');发布于 2011-03-10 19:34:20
你说的“我认为放进购物车的东西应该来自同一张桌子”,这句话一针见血。
HTC电话应该以单一组合的形式存在于组合表中。使用上面的示例,在组合表中插入另一个条目,例如:
---------------+-------------+------------------------
combinationId | price | description
---------------+-------------+------------------------
6 | 299 | Base Model
---------------+-------------+------------------------这解决了即时问题,并且没有缺点。此外,当你的商店增长时,HTC可能会发布具有不同价格区间的新机型,你已经有了一个迎合需求的数据库结构。
例如
---------------+-------------+------------------------
combinationId | price | description
---------------+-------------+------------------------
6 | 299 | Base Model
7 | 349 | Exclusive Edition
---------------+-------------+------------------------发布于 2017-01-31 07:55:06
在我看来,最简单的解决方案是只给智能手机一个规格记录和一个specvalues记录。这样,您就可以为每种类型的产品记录保持您的结构完好无损。当只有一个选项时,不要在productview中显示任何可选选项。
https://stackoverflow.com/questions/5258992
复制相似问题