SlideShare uma empresa Scribd logo
1 de 22
Magento EAV System
The EAV system is one of the most complex part of Magento system.
TRUONG DINH KHOA
Email: mrkhoa99@gmail.com
Do you know?
 MySQL has a hard limit of 4096 columns per table.
 Oracle has even less: 1000.
 Microsoft SQL Server offers up to 30,000 columns.
Traditional model
 In a traditional database model, tables have a fixed number of columns
products
product_id
name
price
atribute_1
……
product_id name price attribute_1 … …
000001 T-Shirt 16.9 Value 1 … …
000002 EAV Book 19 Value 2 … …
EAV Model
 However, if entities have a huge of possible attributes? What happens? E.g. a
product has a lot of attribute: price, name, color, image, tax, manufacturer , attribute_1…
attribute_n, etc..
EAV Model
 The problem can be addressed by EAV (row modelling).
 Traditional model : adding more attributes => more columns.
 EAV model: adding more attributes => more rows.
 EAV stands for entity, attribute and value.
 Many cloud computing platforms (Amazon, Google, Microsoft, etc.) offer EAV
Model as featuring data stores.
EAV Model
 “E” in EAV stands for Entity. In Magento case, they are such as product,
customer, category, order, etc.
 “A” stands for Attribute. These are the individual properties of each of the
entities, e.g. name, weight, email address, etc.
 “V” stands for Value. The value of any particular attribute.
EAV Model
 Magento Model Entity Model
EAV Attribute
Value Table
(varchar)
Value Table
(text)
Value Table
(int)
Value Table
(etc)
EAV Model
 For example : Catalog Product
catalog_product_entity
(entity_type_id)
eav_attribute
(entity_type_id,
attribute_id)
catalog_product_entity_attribute_varchar
(entity_type_id, attribute_id)
catalog_product_entity_attribute_text
(entity_type_id, attribute_id)
catalog_product_entity_attribute_int
(entity_type_id, attribute_id)
catalog_product_entity_attribute_etc
(entity_type_id, attribute_id)
Creating simple raw sql
 SELECT a list of product
 3 tables:
catalog_product_entity ,
eav_attribute,
catalog_product_entity_varchar
Creating simple raw sql
-eav_attribute:
+attribute_id: unique identifier and primary key of table.
+entity_type_id: relates each attribute to a EAV model type.
+attribute_code: the name or key of attributes.
+….
-catalog_product_entity:
+entity_id: unique identifier of product.
+entity_type_id: identifies each type of EAV model type.
+….
Creating simple raw sql
-catalog_product_entity_varchar
+value_id: unique identifier and primary key
+entity_type_id: this value belongs to product entity.
+attribute_id: a foreign key- references to attribute_id on eav_attribute
+…
Creating simple raw sql
Raw SQL:
SELECT
p.entity_id AS product_id,
var.value AS product_name,
p.sku AS product_sku
FROM
catalog_product_entity p,
eav_attribute eav,
catalog_product_entity_varchar var
WHERE p.entity_type_id = eav.entity_type_id
AND var.entity_id = p.entity_id
AND eav.attribute_code = 'name'
AND eav.attribute_id = var.attribute_id
ORDER BY `name` ASC
What’s next?
 Creating a raw sql shows a small piece. It is easy to understand for new
Magento developers. But for customizing and maintaining purpose, what
programming technique is used?
 In a big picture, we need to do more for our software => Magento used Object
Relational Mapping (ORM) system.
Magneto ORM System
 Object-relational mapping (ORM, O/RM, and O/R mapping) in computer
software is a programming technique for converting data between
incompatible type systems in object-oriented programming languages. This
creates, in effect, a "virtual object database" that can be used from within
the programming language.
https://en.wikipedia.org/wiki/Object-relational_mapping
Magento ORM System
 Building a simple query to retrieve products listing:
//Instantiate a product collection:
$collection = Mage::getModel('catalog/product')->getCollection();
//Select an attribute:
$collection->addAttributeToSelect('name');
//Sort the collection:
$collection->setOrder('name', 'asc');
//Load the collection:
$collection->load();
//Print the collection
echo $collection->getSelect();
Magento ORM System
SELECT
`e`.*,
IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS
`name`,
`price_index`.`price`, `price_index`.`tax_class_id`,
`price_index`.`final_price`,
IF(
price_index.tier_price IS NOT NULL,
LEAST(
price_index.min_price,
price_index.tier_price
),
price_index.min_price
) AS `minimal_price`,
`price_index`.`min_price`, `price_index`.`max_price`,
`price_index`.`tier_price`
FROM
`catalog_product_entity` AS `e`
LEFT JOIN `catalog_product_entity_varchar` AS `at_name_default`
ON (`at_name_default`.`entity_id` = `e`.`entity_id`)
AND (`at_name_default`.`attribute_id` = '71')
AND `at_name_default`.`store_id` = 0
LEFT JOIN `catalog_product_entity_varchar` AS `at_name`
ON (`at_name`.`entity_id` = `e`.`entity_id`)
AND (`at_name`.`attribute_id` = '71')
AND (`at_name`.`store_id` = 1)
INNER JOIN `catalog_product_index_price` AS `price_index`
ON price_index.entity_id = e.entity_id
AND price_index.website_id = '1'
AND price_index.customer_group_id = 0
ORDER BY `name` ASC
Magento ORM System
 Some differences in comparison with a raw sql:
-There are many columns.
-Getting products in current store: at_name_default`.`store_id` = 0
-Add more conditions: e.g. IF(at_name.value_id > 0, at_name.value,
at_name_default.value)
-etc.
Magento ORM System
The most useful collection methods
 addAttributeToSelect: adding an attribute to entities in a collection
 addAttributeToFilter: using to filter a collection of
EAV entities with the specified conditional parameters.
 addFieldToFilter: using also to filter a collection, but for non-EAV models, this
function is used regularly.
 addAttributeToSort: adding an attribute to sort order
 etc.
EAV-Advantages
 Flexibility.
 Don’t need to change database schema when adding new attributes.
 Quick to implement.
EAV-Disadvantages
 Performance problem: a lot of tables are required when making a query with
EAV Model.
 Find more…
Thanks you!
Khoa Truong Dinh
mrkhoa99@gmail.com
 http://www.boolfly.com/
 https://github.com/mrkhoa99
 https://vn.linkedin.com/in/truongdinhkhoa
 http://stackoverflow.com/users/5179786/khoa-truongdinh

Mais conteúdo relacionado

Mais procurados

Online shopping report-6 month project
Online shopping report-6 month projectOnline shopping report-6 month project
Online shopping report-6 month projectGinne yoffe
 
Online shopping-project-documentation-template
Online shopping-project-documentation-templateOnline shopping-project-documentation-template
Online shopping-project-documentation-templateLaibaMalik17
 
Full Documentation.docx
Full Documentation.docxFull Documentation.docx
Full Documentation.docxMilanKarki18
 
Voice wiki on mobile project report
Voice wiki on mobile project reportVoice wiki on mobile project report
Voice wiki on mobile project reportRahul E
 
e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)Mudasir Ahmad Bhat
 
Web Development on Web Project Presentation
Web Development on Web Project PresentationWeb Development on Web Project Presentation
Web Development on Web Project PresentationMilind Gokhale
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
Mini project report_on_online_shopping
Mini project report_on_online_shoppingMini project report_on_online_shopping
Mini project report_on_online_shoppingSandeep Bittu
 
Book Selling Website Report
Book Selling Website ReportBook Selling Website Report
Book Selling Website ReportSaloni Bajaj
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETRajkumarsoy
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsKostyantyn Stepanyuk
 

Mais procurados (20)

Online shopping report-6 month project
Online shopping report-6 month projectOnline shopping report-6 month project
Online shopping report-6 month project
 
Online shopping-project-documentation-template
Online shopping-project-documentation-templateOnline shopping-project-documentation-template
Online shopping-project-documentation-template
 
Full Documentation.docx
Full Documentation.docxFull Documentation.docx
Full Documentation.docx
 
Voice wiki on mobile project report
Voice wiki on mobile project reportVoice wiki on mobile project report
Voice wiki on mobile project report
 
Apache web service
Apache web serviceApache web service
Apache web service
 
e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)
 
Web Development on Web Project Presentation
Web Development on Web Project PresentationWeb Development on Web Project Presentation
Web Development on Web Project Presentation
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Web Development
Web DevelopmentWeb Development
Web Development
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
project-ppt1.pdf
project-ppt1.pdfproject-ppt1.pdf
project-ppt1.pdf
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Wordpress ppt
Wordpress pptWordpress ppt
Wordpress ppt
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
Mini project report_on_online_shopping
Mini project report_on_online_shoppingMini project report_on_online_shopping
Mini project report_on_online_shopping
 
Book Selling Website Report
Book Selling Website ReportBook Selling Website Report
Book Selling Website Report
 
Apache web server
Apache web serverApache web server
Apache web server
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 

Destaque

Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)Tâm
 
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...MagentoImagine
 
Integrating Magento into Joomla!
Integrating Magento into Joomla!Integrating Magento into Joomla!
Integrating Magento into Joomla!Yireo
 
Бизнес переходит в облака
Бизнес переходит в облакаБизнес переходит в облака
Бизнес переходит в облакаPolinchuk
 
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...i95Dev
 
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated Platform
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated PlatformTYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated Platform
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated PlatformMauro Lorenzutti
 
Anypoint Salesforce Connector With Mulesoft
Anypoint Salesforce Connector With MulesoftAnypoint Salesforce Connector With Mulesoft
Anypoint Salesforce Connector With MulesoftJitendra Bafna
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPTTrinath
 

Destaque (14)

Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...
Magento's Imagine eCommerce Conference 2011 - Mash-up of Magento and Salesfor...
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
Integrating Magento into Joomla!
Integrating Magento into Joomla!Integrating Magento into Joomla!
Integrating Magento into Joomla!
 
Бизнес переходит в облака
Бизнес переходит в облакаБизнес переходит в облака
Бизнес переходит в облака
 
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...
i95Dev Magento RMS Connect | eCommerce RMS Integration | Magento eCommerce In...
 
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated Platform
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated PlatformTYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated Platform
TYPO3 + Magento + SugarCRM + Alfresco: An Enterprise Integrated Platform
 
Yoav Kutner Dutchento
Yoav Kutner DutchentoYoav Kutner Dutchento
Yoav Kutner Dutchento
 
Salesforce Admin
Salesforce AdminSalesforce Admin
Salesforce Admin
 
Anypoint Salesforce Connector With Mulesoft
Anypoint Salesforce Connector With MulesoftAnypoint Salesforce Connector With Mulesoft
Anypoint Salesforce Connector With Mulesoft
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike BackSql Antipatterns Strike Back
Sql Antipatterns Strike Back
 
Salesforce Data Structures
Salesforce Data StructuresSalesforce Data Structures
Salesforce Data Structures
 
Data model in salesforce
Data model in salesforceData model in salesforce
Data model in salesforce
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
 

Semelhante a EAV Sytem- Magento EAV Model

Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
20. Magento Austria meetup - EAV Principles
20. Magento Austria meetup - EAV Principles20. Magento Austria meetup - EAV Principles
20. Magento Austria meetup - EAV Principlesmohammedhsalem
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web appsIvano Malavolta
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationRandy Connolly
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorialinfo_zybotech
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress sitereferences
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180Mahmoud Samir Fayed
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_uploadProf. Wim Van Criekinge
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django ormDenys Levchenko
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)Buck Woolley
 
DB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant codeDB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant codeKarsten Dambekalns
 
Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceZohar Elkayam
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용KyeongMook "Kay" Cha
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 

Semelhante a EAV Sytem- Magento EAV Model (20)

Session 2 django material for training at baabtra models
Session 2 django material for training at baabtra modelsSession 2 django material for training at baabtra models
Session 2 django material for training at baabtra models
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Developing a new Epsilon EMC driver
Developing a new Epsilon EMC driverDeveloping a new Epsilon EMC driver
Developing a new Epsilon EMC driver
 
20. Magento Austria meetup - EAV Principles
20. Magento Austria meetup - EAV Principles20. Magento Austria meetup - EAV Principles
20. Magento Austria meetup - EAV Principles
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
 
DB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant codeDB API Usage - How to write DBAL compliant code
DB API Usage - How to write DBAL compliant code
 
Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better Performance
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 

Último

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Último (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

EAV Sytem- Magento EAV Model

  • 1. Magento EAV System The EAV system is one of the most complex part of Magento system. TRUONG DINH KHOA Email: mrkhoa99@gmail.com
  • 2. Do you know?  MySQL has a hard limit of 4096 columns per table.  Oracle has even less: 1000.  Microsoft SQL Server offers up to 30,000 columns.
  • 3. Traditional model  In a traditional database model, tables have a fixed number of columns products product_id name price atribute_1 …… product_id name price attribute_1 … … 000001 T-Shirt 16.9 Value 1 … … 000002 EAV Book 19 Value 2 … …
  • 4. EAV Model  However, if entities have a huge of possible attributes? What happens? E.g. a product has a lot of attribute: price, name, color, image, tax, manufacturer , attribute_1… attribute_n, etc..
  • 5. EAV Model  The problem can be addressed by EAV (row modelling).  Traditional model : adding more attributes => more columns.  EAV model: adding more attributes => more rows.  EAV stands for entity, attribute and value.  Many cloud computing platforms (Amazon, Google, Microsoft, etc.) offer EAV Model as featuring data stores.
  • 6. EAV Model  “E” in EAV stands for Entity. In Magento case, they are such as product, customer, category, order, etc.  “A” stands for Attribute. These are the individual properties of each of the entities, e.g. name, weight, email address, etc.  “V” stands for Value. The value of any particular attribute.
  • 7. EAV Model  Magento Model Entity Model EAV Attribute Value Table (varchar) Value Table (text) Value Table (int) Value Table (etc)
  • 8. EAV Model  For example : Catalog Product catalog_product_entity (entity_type_id) eav_attribute (entity_type_id, attribute_id) catalog_product_entity_attribute_varchar (entity_type_id, attribute_id) catalog_product_entity_attribute_text (entity_type_id, attribute_id) catalog_product_entity_attribute_int (entity_type_id, attribute_id) catalog_product_entity_attribute_etc (entity_type_id, attribute_id)
  • 9. Creating simple raw sql  SELECT a list of product  3 tables: catalog_product_entity , eav_attribute, catalog_product_entity_varchar
  • 10. Creating simple raw sql -eav_attribute: +attribute_id: unique identifier and primary key of table. +entity_type_id: relates each attribute to a EAV model type. +attribute_code: the name or key of attributes. +…. -catalog_product_entity: +entity_id: unique identifier of product. +entity_type_id: identifies each type of EAV model type. +….
  • 11. Creating simple raw sql -catalog_product_entity_varchar +value_id: unique identifier and primary key +entity_type_id: this value belongs to product entity. +attribute_id: a foreign key- references to attribute_id on eav_attribute +…
  • 12. Creating simple raw sql Raw SQL: SELECT p.entity_id AS product_id, var.value AS product_name, p.sku AS product_sku FROM catalog_product_entity p, eav_attribute eav, catalog_product_entity_varchar var WHERE p.entity_type_id = eav.entity_type_id AND var.entity_id = p.entity_id AND eav.attribute_code = 'name' AND eav.attribute_id = var.attribute_id ORDER BY `name` ASC
  • 13. What’s next?  Creating a raw sql shows a small piece. It is easy to understand for new Magento developers. But for customizing and maintaining purpose, what programming technique is used?  In a big picture, we need to do more for our software => Magento used Object Relational Mapping (ORM) system.
  • 14. Magneto ORM System  Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. https://en.wikipedia.org/wiki/Object-relational_mapping
  • 15. Magento ORM System  Building a simple query to retrieve products listing: //Instantiate a product collection: $collection = Mage::getModel('catalog/product')->getCollection(); //Select an attribute: $collection->addAttributeToSelect('name'); //Sort the collection: $collection->setOrder('name', 'asc'); //Load the collection: $collection->load(); //Print the collection echo $collection->getSelect();
  • 16. Magento ORM System SELECT `e`.*, IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF( price_index.tier_price IS NOT NULL, LEAST( price_index.min_price, price_index.tier_price ), price_index.min_price ) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_entity` AS `e` LEFT JOIN `catalog_product_entity_varchar` AS `at_name_default` ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND (`at_name_default`.`attribute_id` = '71') AND `at_name_default`.`store_id` = 0 LEFT JOIN `catalog_product_entity_varchar` AS `at_name` ON (`at_name`.`entity_id` = `e`.`entity_id`) AND (`at_name`.`attribute_id` = '71') AND (`at_name`.`store_id` = 1) INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 ORDER BY `name` ASC
  • 17. Magento ORM System  Some differences in comparison with a raw sql: -There are many columns. -Getting products in current store: at_name_default`.`store_id` = 0 -Add more conditions: e.g. IF(at_name.value_id > 0, at_name.value, at_name_default.value) -etc.
  • 18. Magento ORM System The most useful collection methods  addAttributeToSelect: adding an attribute to entities in a collection  addAttributeToFilter: using to filter a collection of EAV entities with the specified conditional parameters.  addFieldToFilter: using also to filter a collection, but for non-EAV models, this function is used regularly.  addAttributeToSort: adding an attribute to sort order  etc.
  • 19. EAV-Advantages  Flexibility.  Don’t need to change database schema when adding new attributes.  Quick to implement.
  • 20. EAV-Disadvantages  Performance problem: a lot of tables are required when making a query with EAV Model.  Find more…
  • 22. Khoa Truong Dinh mrkhoa99@gmail.com  http://www.boolfly.com/  https://github.com/mrkhoa99  https://vn.linkedin.com/in/truongdinhkhoa  http://stackoverflow.com/users/5179786/khoa-truongdinh