In the previous article, we provided you with the basic principle of EAV but have you concretely known how Magento stores the data according to the EAV model and how to create an EAV entity in Magento? If not, my tutorial today will surely be a good reference for you.

1. Describe the database tables for EAV entities and how to create them

• Table Eav_Entity

This table includes the basic information of entities.

  • entity_id: the ID of the entity
  • entity_type_id: the ID of the entity type. To get this ID, it’s necessary to add a new type of entity to the table eav_entity_type
  • attribute_set_id: the ID of the attribute set used for the entity

• Table Eav_entity_type

The table Eav_entity_type contains the information of the entity types such as: customer, product, order…

  • entity_type_id: the ID of the entity type
  • entity_type_code: the code of the entity type. For instance: customer, catalog_product
  • entity_model: The model used to work with this entity type (customer/customer, catalog/product)
  • attribute_model: The model used to work with the attribute of this entity type (to add, edit, delete). For example: customer/attribute, catalog/resource_eav_attribute
  • entity_table: The table which stores entities (catalog_product_entity)

• Table Eav_attribute

This table includes the attributes’ information

  • attribute_id: the ID of the attribute
  • entity_type_id: the ID of the entity type having this attribute
  • attribute_code: the code of the attribute
  • attribute_model
  • backend_model
  • backend_type
  • backend_table
  • frontend_model
  • frontend_input
  • frontend_lable
  • frontend_class
  • source_model

• Table Eav_Entity_attribute

The table Eav_Entity_attribute contains information of the Attribute Group and the Attribute Set of attributes

  • entity_attribute_id
  • entity_type_id: the ID of the entity type
  • attribute_set_id: the ID of the attribute set
  • attribute_group_id: the ID of the attribute group
  • attribute_id: the ID of the attribute

• Table Eav_attribute_set

This table includes information of the attribute sets.

  • attribute_set_id
  • entity_type_id: the ID of the entity type
  • attribute_set_name: The name of the attribute set

• Table Eav_attribute_group

The table Eav_attribute_group contains the information of the attribute group.

  • attribute_group_id: the ID of the attribute group
  • attribute_set_id: the ID of the attribute set
  • attribute_group_name: The name of the attribute group

• Tables stored the value of the attribute

Eav_entity_int

Eav_entity_datetime

Eav_entity_decimal

Eav_entity_text

Eav_entity_varchar

The table Eav_entity_int stores the value of the “int” type of attributes.

  • entity_type_id: the ID of entity type
  • attribute_id: the ID of the attribute
  • store_id: the Store ID
  • entity_id: the ID of the entity
  • value: the attribute’s value of the entity

2. Key differences between EAV and Flat Table collections

3. Give a new entity, identify the factors that influence the choice of the resource type to use (EAV vs. flat)

For example:

The Banner Entity

Attributes: Title, Images, Link, Status, Description

  • The number of attribute: small (5 attributes)
  • Attributes are fixed and there’s no need to create more attributes.

→ Use the flat table

The Customer Entity

Attributes: First Name, Last Name, Email, Password, Group, Gender, Birthday, Tax Number

  • The number of attributes: small (about 10 attributes)
  • Need to create more attributes: Company, Interested…

→ Use the EAV model

That’s all for today. Thanks for your following and hope that you will find it helpful.

Have fun! 😉


Author

Alex is the CTO & Co-founder of Magestore which has been providing retail solutions for Magento merchants since 2009. He started as a Magento developer just one year after the release of the first version of Magento. With over 10 years experience of working with Magento and clients all over the world, he gained great knowledge on e-commerce development, order management systems, inventory control & retail POS.

Write A Comment