1

我正在建立一个在线商店,但我遇到了问题。我将拥有具有直接价格的产品(例如 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 智能手机),以便可以像多价产品一样将其添加到购物车。

4

3 回答 3

2

当您说“我认为插入购物车的物品应该来自同一张桌子”时,您一针见血。

HTC 手机应该存在于组合表中,只是作为一个组合。使用上面的示例,在组合表中插入另一个条目,例如:

---------------+-------------+------------------------
combinationId  |     price   |  description
---------------+-------------+------------------------
6              |     299     |  Base Model
---------------+-------------+------------------------

这解决了直接的问题,并且没有缺点。此外,当您的商店发展壮大时,HTC 可能会发布不同价位的新型号,您已经拥有了适合您的数据库结构。

例如

---------------+-------------+------------------------
combinationId  |     price   |  description
---------------+-------------+------------------------
6              |     299     |  Base Model
7              |     349     |  Exclusive Edition
---------------+-------------+------------------------
于 2011-03-10T11:34:20.460 回答
0

您可能想看看 OpenCarts 数据库。它实际上做得很好...

本质上:

为以下内容创建表格: 产品 产品选项(您的“规格”) 产品选项值(您的“规格值”)

每个产品都将列在“产品表”中并有一个价格在“产品选项”表中,您基本上列出了产品的不同“规格”......
产品选项值表列出了实际选项和更改基本价格 (+/-)...

为了存储已完成的订单,OpenCart 具有基本相同的表......(与订单 ID 相关联)

Recetly 我撕掉了购物车功能来处理锦标赛的玩家注册......

基本“产品”是玩家注册 - 25 美元“产品选项”只需列出“规格”/“注册类型”

对于“注册类型”,值存储在“product_option_value”表中......他们可以注册为付费或付费玩(付费玩进入迷你游戏) 付费只是默认选项,价格没有变化... Pay and Play 增加了 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');
于 2011-03-10T11:33:57.483 回答
0

在我看来,最简单的解决方案是只给智能手机一个规格记录和一个规格值记录。这样,您就可以为每种类型的产品记录保持结构完整。当只有一个选项时,不要在产品视图中显示任何可选选项。

于 2017-01-30T23:55:06.267 回答