产品属性和属性选项如何存储在Magento数据库中?

bal*_*anv 31 magento

我试图弄清楚如何在Magento中创建属性和属性选项以及产品和属性之间的链接.有没有提到这是如何工作的?或者任何人都给我一个暗示.

谢谢,

巴兰

Ant*_*ony 57

正如Alan Storm写信给我的那样:"你不必了解你的数据库是如何工作的.你必须了解这些模型是如何工作的".(这不是一个确切的引用.我给你的意思).

但我创建了自己的方案来理解数据库结构.所以这个屏幕显示它是如何工作的: 在此输入图像描述 在此输入图像描述

希望能帮助到你.

另外,我建议您浏览以下链接:

http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_database_diagram

http://alanstorm.com/magento_advanced_orm_entity_attribute_value_part_1

  • 哎呀!只是呀!(对于惊人的研究也是+1) (15认同)
  • 链接到上面的图像,以便正确阅读:http://i.stack.imgur.com/PQsc1.png,http://i.stack.imgur.com/d65bi.png (7认同)

小智 35

1)属性存储在eav_attribute.你得到了attribute_id.

2)选项存储在eav_attribute_option_value.你得到了option_id.

3)选项分配给产品catalog_product_entity_varchar.那里你需要entity_id产品,attribute_id从1)和逗号分隔的值option_ids2)


Ovi*_*diu 12

每次我想知道关于magento db关系如何工作的事情我都会检查一下

在线数据库图工具


dli*_*ink 5

我发现这些查询对于寻找诸如 - 哪里说产品颜色是黑色的东西非常有帮助,例如。

-- show_product_attr.sql
select
   p.entity_id,
   p.entity_type_id,
   p.attribute_set_id,
   p.type_id,
   p.sku,
   a.attribute_id,
   a.frontend_label as attribute,
   av.value
from
   catalog_product_entity p
   left join catalog_product_entity_{datatype} av on
      p.entity_id = av.entity_id
   left join eav_attribute a on
      av.attribute_id = a.attribute_id
where
   -- p.entity_id = 28683
   -- p.sku = '0452MR'
   p.entity_id = {eid}
;
Run Code Online (Sandbox Code Playgroud)

对于 attr_options

-- show_product_attr_options.sql
select
   p.entity_id,
   -- p.entity_type_id,
   -- p.attribute_set_id,
   p.type_id,
   p.sku,
   a.attribute_id,
   a.frontend_label as attribute,
   -- a.attribute_code,
   av.value,
   ao.*
from
   catalog_product_entity p

   left join catalog_product_entity_int av on
      p.entity_id = av.entity_id

   left join eav_attribute a on
      av.attribute_id = a.attribute_id
   left join eav_attribute_option_value ao on
      av.value = ao.option_id 
where
   -- p.entity_id = 28683
   p.entity_id = {eid}
;
Run Code Online (Sandbox Code Playgroud)

对于第一个查询,您需要将 {datatype} 替换为 text、varchar、int、decimal 等,并将 {eid} 替换为两个查询的 entity_id。您可以像这样对命令执行以下操作:

$ cat show_product_attr_options.sql | sed -e "s/{eid}/30445/" | mysql -uUSER -pPASS DATABASE -t
+-----------+---------+--------------+--------------+---------------------------+-------+----------+-----------+----------+--------------------+-------------+
| entity_id | type_id | sku          | attribute_id | attribute                 | value | value_id | option_id | store_id | value              | colorswatch |
+-----------+---------+--------------+--------------+---------------------------+-------+----------+-----------+----------+--------------------+-------------+
|     30445 | simple  | 840001179127 |           96 | Status                    |     1 |     5972 |         1 |        0 | Male               | NULL        |
|     30445 | simple  | 840001179127 |          102 | Visibility                |     1 |     5972 |         1 |        0 | Male               | NULL        |
|     30445 | simple  | 840001179127 |          122 | Tax Class                 |     2 |     5973 |         2 |        0 | Female             | NULL        |
|     30445 | simple  | 840001179127 |          217 | Size                      |   257 |    17655 |       257 |        0 | XS                 | NULL        |
|     30445 | simple  | 840001179127 |          217 | Size                      |   257 |    17657 |       257 |        1 | XS                 | NULL        |
|     30445 | simple  | 840001179127 |          224 | Color                     |   609 |    18717 |       609 |        0 | Arctic Ice Heather | NULL        |
|     30445 | simple  | 840001179127 |          260 | Featured                  |     0 |     NULL |      NULL |     NULL | NULL               | NULL        |
|     30445 | simple  | 840001179127 |          262 | Clearance Product         |     0 |     NULL |      NULL |     NULL | NULL               | NULL        |
|     30445 | simple  | 840001179127 |          263 | Skip from Being Submitted |     0 |     NULL |      NULL |     NULL | NULL               | NULL        |
|     30445 | simple  | 840001179127 |          283 | Discontinued              |     0 |     NULL |      NULL |     NULL | NULL               | NULL        |
+-----------+---------+--------------+--------------+---------------------------+-------+----------+-----------+----------+--------------------+-------------+
Run Code Online (Sandbox Code Playgroud)

可以为目录创建一组类似的 sql 脚本。