产品和产品变体的数据库设计
我正在建立一个商业网站,并且一直在研究不同的方式来展示具有变体的产品。我正在尝试对隐形眼镜进行此操作,并想知道最好的方法是什么。
产品可以很简单,例如没有变体的镜片盒或镜片溶液,或者对于隐形眼镜,每个镜片最多可以有三个可配置的变体,具体取决于镜片,用于处方(例如功率,基弧、直径)。
在我的结构中,我有简单的产品,只是一个产品,没有父产品。隐形眼镜将存储为产品,每个变体将存储为引用其父代的单独产品,并且变体本身将使用 products_variants 表进行链接。
我的结构如下:
products
- id
- parent_id
- name
- price
- type_id
- brand_id
type
- id
- name
brand
- id
- name
product_variant_group
- id
- name
product_variant_value
- id
- product_variant_group_id
- value
products_variants (isCrossRef = true for Propel relationships)
- id
- product_id
- product_variant_value_id
我的代码已经相当慢了,我什至还没有开始构建选择框来选择处方。
public function getPossibleVariants($productId)
{
$product = ProductQuery::create()->findPk($productId);
$children = $product->getChildren();
$options = array();
foreach ($children as $child) {
if ($child->countProductsVariantss()) {
$variants = $child->getProductVariantValues();
foreach ($variants as $variant) {
$group = $variant->getProductVariantGroup();
$options[$group->getName()][] = $variant->getValue();
}
}
}
ksort($options);
return $options;
}
我正在使用 propel 和 Zend Framework。我以正确的方式处理这件事吗?大多数人需要两个相同类型的镜片,但每只眼睛的处方不同。我将如何实施这个?
我尝试过查看其他系统,例如 magento 和 oscommerce。前者让我感到困惑,我发现后者的代码很混乱。由于这是一次学习经历,我想以最好的方式做事。
谢谢
I'm building an commerce site and I've been researching different ways to show products with variants. I'm trying to do this for contact lenses and wondering what the best way is.
Products can be either simple, such as a lens case or lens solution that have no variants, or in the case of a contact lens, each lens can have up to three configurable variants, depending on the lens, for the prescription (e.g. Power, Base Curve, Diameter).
In my structure I have simple products as just a product, with no parent. A contact lens will be stored as a product, and each variant will be stored as a separate product referencing its parent, and the variants themselves will be linked using a products_variants table.
I have a structure like:
products
- id
- parent_id
- name
- price
- type_id
- brand_id
type
- id
- name
brand
- id
- name
product_variant_group
- id
- name
product_variant_value
- id
- product_variant_group_id
- value
products_variants (isCrossRef = true for Propel relationships)
- id
- product_id
- product_variant_value_id
My code is quite slow already, and I haven't even started to build the select boxes to select the prescription.
public function getPossibleVariants($productId)
{
$product = ProductQuery::create()->findPk($productId);
$children = $product->getChildren();
$options = array();
foreach ($children as $child) {
if ($child->countProductsVariantss()) {
$variants = $child->getProductVariantValues();
foreach ($variants as $variant) {
$group = $variant->getProductVariantGroup();
$options[$group->getName()][] = $variant->getValue();
}
}
}
ksort($options);
return $options;
}
I'm using propel and Zend Framework. Am I going about this the right way? Most people will need two of the same lens types, but with different prescriptions for each eye. How would I implement this?
I've tried looking at other systems, such as magento and oscommerce. The former confuses me and I find the code messy in the latter. As this is a learning experience, I'd like to do things the best possible way.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好对所有产品和产品变型使用一张表。让基于产品的运营变得更加简单。最终变体只是一种产品。
所以我建议。
附加字段
variant_id
应引用变体组。这样就比较简单了。并且您可以根据变体组 ID 检索所有变体。
我经常使用亚马逊产品 API。他们的做法与此类似。
It is better to use one table for all your products and products variants. So that the operations based on products get easier. Ultimately a variant is a product only.
So I would suggest.
The additional field
variant_id
should reference the variant group.It is simpler this way. And you can retrieve all the variants based on variant group id.
I have played with Amazon product API a lot. Their approach is similar to this.