Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Magento training - EAV part 1

No description
by

Diana Botean

on 31 May 2016

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Magento training - EAV part 1

What is EAV?
Wikipedia
defines EAV as

"Entity-Attribute-Value model
(EAV), also known as
object-attribute-value model
and open schema is a data model that is used in circumstances where the number of attributes (properties, parameters) that can be used to describe a thing (an "entity" or "object") is potentially very vast, but the number that will actually apply to a given entity is relatively modest. In mathematics, this model is known as a sparse matrix. EAV is also known as
object–attribute–value
model,
vertical database model
and
open schema
."
Magento EAV
- in Magento, each product has a row in '
catalog_product_entity
'
- all available attributes in the entire system are stored in '
eav_attribute
'
- the values of these attributes are stored in tables like '
catalog_product_entity_varchar
', '
catalog_product_entity_int
', etc.
Attributes
Magento training - EAV part 1
Roadmap
Magento architecture, module structure
Request flow
Rendering
Working with DB in Magento
Entity-Attribute-Value (EAV) Model
Catalog
Customers
Sales
Checkout
Adminhtml
EAV
- in a
traditional db
, tables have a
fixed number of columns
- in an EAV model, each "
entity
"(a product in our case) has a different
set of attributes (which can contain different number of attributes)
- Magento engineers have built an EAV system out of PHP objects that use MySQL as data-store, actually
an EAV database system on top of a traditional relational db
Entity
is somewhat of a “data item”. In Magento, those are for example categories, products and customers.
Attribute
is again a “data item”, but to differ it from the Entity, in Magento, attributes are for example: Title, Description, Price, etc. for each Product entity.
And
Value
for simplicity of explanation represents “real value” that is attached to Entity’s Attribute.


Magento
backend_table
: this property is closely connected to the attribute’s backend_type, and its values are dependent on what is set in the backend type. That is why the column backend_table in the table eav_attribute is empty. Despite the dynamic generation of backend_table values, you can explicitly set a table name and store it in the database.

backend_label
: this has the label of the attribute as shown in admin.

fontend_model
: this class is used to change the presntation form of the values if required. For example,

Mage_Eav_Model_Entity_Attribute_Frontend_Datetime
has a
getValue()
which is used to format dates.

fontend_input
: this sets how an attribute should be displayed on frontend, basically what kind of input element is used for the attribute in HTML forms.

fontend_label
: this is the label used in frontend when the attribute is displayed

fontend_class
: the method
getClass()
of the attribute’s frontend model uses the
frontend_class
value to assign CSS classes to the attribute’s input element. You can set a CSS class that your custom JavaScript validator can pick up to check the input values against whatever validation rules you want.
attribute_id
: this is the primary key

entity_type_id
: this is a foreign key of table
eav_entity_type


attribute_code
: this is a unique code used to identity an attribute

attribute_model
: this property points to a class that contains the attribute's model. Catalog entities (
catalog_product
and
catalog_category
) have
Mage_Catalog_Model_Resource_Eav_Attribute
as attribute model, while customer has
Mage_Customer_Model_Attribute
. The values for this property are not set in the db, instead, when loading the attribute models, Magento will look for the entity type assigned to the attribute and load it's proper model.

backend_model
: this usually has the path of a model class. These model classes are used when saving attribute value in database. Like for example saving of product media images requires some operating to happen before and after save. So those operations are defined in these classes. During these operations the object’s model performs “attribute walking” by calling functions
afterLoad(), beforeSave(), afterSave(), beforeDelete() and afterDelete()
on the attribute backend model.

backend_type
: this specifies that data type of the attribute. Backend types can be
varchar, int, text, decimal, datetime

or

static
. The backend type
static

is a special case
. Attributes of this type store their data in the entity’s main table, even though the data can be int, decimal, or varchar
(see '
sku
' of products, for example)
source_model
: source models are mainly used by attributes with frontend_input of type select or multiselect. Source models contain functionality that allows such attributes to have a list of options to choose from.

is_required
: when set to true property indicates that this attribute must have a value. The frontend_model will add a required CSS class to the attribute’s HTML input field to enable the client-side JavaScript validation.

is_user_defined
: this property is used to distinguish between system attributes and attributes created by shop users. The former may not be deleted – and that is why the edit form for such attributes doesn’t display the “delete” button. You still can delete system attributes programmatically, but this would be a bad idea.

default_value
: you can provide a default value for the attribute. A default value will come pre-entered into the form input field, or will be used when an entity is created programmatically (e.g. product import), provided the attribute has no explicitly set value.

is_unique
: setting this attribute to 1 will command the system to check that no two or more entities of the given type share the same value for this attribute. An example could be product SKUs or bar codes.

note
: you can enter a short descriptive text into this field, if you need a tip displayed next to the attribute’s input field in the backend. For example, see the “Meta Description” field in the product edit form.
Entity types
entity_type_id
: this is the primary key of the table, and also used as the foreign key in
entity_type_id
column in
eav_attribute
table
entity_type_code
: these are unique codes use to specifies varies entities for wich the EAV table structure is used
entity_mode
l: the base Magento model class for that entity
attribute_model
: there are attribute_model classes. If no attribute model class is given the default eav/attribute is taken
entity_table:
the based entity database table name, where the required attributes of are entity are stored
Attribute sets
-
attribute sets
add flexibility to the attribute system by allowing attributes to be grouped together so that different entity types (or different entities of the same type) could have only those attributes that they really need.

- are represented by the
Mage_Eav_Model_Entity_Attribute_Set
class and its resource model
Mage_Eav_Model_Resource_Entity_Attribute_Set
. The information on the shop’s attribute sets is contained in the table
eav_attribute_set
.
attribute_set_id
: this is the primary key of the table
entity_type_id
: this is a foreign key to the table eav_entity_type. This associates the attribute set name to the entity type.
attribute_set_name
: the name of the attribute set
sort_order
: order in which attribute sets are shown in admin.
Attribute set groups
- the main role of attribute groups is organizing entity attributes into tabs in the entity edit form. 
- you might have already seen and used tabbed attribute forms when editing products and categories.
attribute_group_id
: primary key
attribute_set_id
: foreign key of the

eav_attribute_set
table
attribute_group_name
: name of the group
sort_order
: display order of groups
default_id
: set group as default
if the old one is removed

Values
Attribute -  Attribute set - Group
-
eav_entity_attribute
table contains all relations between an attribute, its attribute set and attribute set group
Pros
scalability
- you can add almost anything into db
without changing its structure
.
flexibility -
you can associate attributes to any entity
quick to implement


Cons

inefficient
- a query returning 20 columns normally would consist of 20 self joins in EAV
no grouping of related entity types
PROs and CONs
Backend types of attributes havetheir values are stored in
<entitytypename>_entity_varchar
<entitytypename>_entity_int
<entitytypename>_entity_text
<entitytypename>_entity_decimal
<entitytypename>_entity_datetime

(replace
<entitytypename>
with

customer, catalog_product,
or
catalog_category
)
catalog_product_entity_varchar
Full transcript