¿Cómo se almacenan los atributos de producto y las opciones de atributos en la base de datos Magento?


Estoy tratando de averiguar cómo se hace el enlace entre las opciones de atributo y atributo, y el producto y los atributos en Magento. ¿Hay alguna referencia a cómo funciona esto? o que alguien me dé una pista sobre esto.

Gracias,

Balan

 30
Author: balanv, 2012-02-27

6 answers

Como Alan Storm me dijo: "no necesitas saber cómo funciona tu base de datos. Deberías aprender cómo funcionan los modelos ". (Esto no es una cita exacta. Te di el significado).

Pero he creado mi propio esquema para entender la estructura de la base de datos. Así que esta pantalla muestra cómo funciona: introduzca la descripción de la imagen aquíintroduzca la descripción de la imagen aquí

Esperanza, ayuda.

También te recomiendo que mires a través de estos enlaces:

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

Http://alanstorm.com/magento_advanced_orm_entity_attribute_value_part_1

 52
Author: Anthony,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-27 10:54:05

1) Los atributos se almacenan en eav_attribute. Ahí tienes el attribute_id.

2) Las opciones se almacenan en eav_attribute_option_value. Ahí tienes el option_id.

3) Las opciones se asignan al producto en catalog_product_entity_varchar. Allí necesita el entity_id del producto, el attribute_id de 1) y el valor que son las comas separadas option_ids de 2)

 31
Author: Martin Sedlmeier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-18 10:33:48

Cada vez que quiero saber algo sobre cómo funciona magento db relations compruebo esto

Herramienta de Diagrama de Base de Datos en Línea

 12
Author: Ovidiu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-28 13:07:41
SELECT pei.value 
FROM `catalog_product_entity_int` pei 
JOIN `eav_attribute` ea 
ON pei.attribute_id = ea .attribute_id 
WHERE pei.entity_id = {your product_id} 
AND ea.attribute_code = '{your attribute_code}'

Tenga en cuenta que hay un número de tablas diferentes como catalog_product_entity_int dependiendo del tipo del atributo, por lo que una de esas otras podría ser apropiada.

 3
Author: colmde,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-22 15:17:17

He encontrado que estas consultas son muy útiles para buscar cosas como: ¿dónde dice que el color del producto es negro? por ejemplo.

-- 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}
;

Y para 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}
;

Debe reemplazar {datatype} con text, varchar, int, decimal, etc., para la primera consulta, y {eid} con entity_id para ambas consultas. Lo que se puede hacer en el comando como así:

$ 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        |
+-----------+---------+--------------+--------------+---------------------------+-------+----------+-----------+----------+--------------------+-------------+

Se puede crear un conjunto similar de scripts sql para catalog.

 3
Author: dlink,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-09 21:10:20

Los atributos del producto son valores adicionales que puede asignar a un producto y se almacenan en la tabla principal de EAV, por nombre, y los datos se almacenan en algunas tablas diferentes según el tipo de datos, como varchar, decimal, entero de texto, fecha, etc.

Si tiene varios valores para su Atributo Product, entonces se almacenará en las tablas de Opciones de atributos, de nuevo, diferentes tablas según el tipo de datos.

El siguiente enlace explica las relaciones mejor: http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_database_diagram

Y un detalle más profundo del desarrollador: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-7-advanced-orm-entity-attribute-value

Y los conjuntos de atributos serán la otra cosa que encontrará, como su nombre sugiere, un conjunto de atributos agrupados. http://www.magentocommerce.com/knowledge-base/entry/how-do-i-create-an-attribute-set

HTH Shaun

 2
Author: ShaunOReilly,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-27 12:00:12