In ‘From Core to Custom: A Deep Dive into Magento Entity Extension,’ we’ll explore advanced techniques for extending Magento entities, focusing on best practices and recommended approaches.
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
38. Magento Meetup Austria: Ivan Cuk - From Core to Custom. A Deep Dive into Magento Entity Extension
1. 38. Magento-Meetup Wien
Ivan Cuk
Software Developer
From Core to Custom
A Deep Dive into Magento Entity Extension
2. What is a Magento Entity?
● Entity is data item (customer, product, order & more)
● Each item has its attributes and values for them
● Represented with one main entity database table (and few other tables)
3. Why this topic?
● Extending core entities is frequently needed for
customizations
● Important for the stability, modularity, upgradability
and overall quality of the Magento Store
● Different approaches (even within same teams)
4. Magento core entities
EAV Not EAV
customer order
customer_address invoice
catalog_category creditmemo
catalog_product shipment
EAV available with some entities, Extension Attributes with all entities
5. The Problem
When to use EAV and when to use Extension Attributes?
How to properly implement Extension Attributes and why
is that important?
6. Often seen approaches
Developers tend to some of the following things:
● Not use Extension Attributes at all: use a (hacky)
workaround
● Implement Extension Attributes almost always: EAV
capabilities are getting heavily overlooked
7. EAV Attributes
Basic EAV Attributes can be developed quickly.
No-brainer situation:
Attributes that have simple scalar values.
Example: a custom ERP-ID attribute for the customer
entity
8. EAV Attributes
Often overlooked: EAV Attributes can be also used for
more complex data-processing and functionalities.
EAV-Models:
attribute_model - overall behaviour
backend_model - before and after attribute save
frontend_model - data representation
source_model - retrieving set of choices
9. Extension Attributes
When?
● Entity without EAV
● The complexity of the new custom attributes requires
even more flexibility than what EAV offers
12. Modifying Core Tables?
● Not recommended - source:
https://experienceleague.adobe.com/docs/commerce-
operations/implementation-playbook/best-
practices/development/modifying-core-and-third-party-tables.html?lang=en
● Decreases upgradability & stability of the project
● Underlying logic contains raw SQL queries - can cause side effects difficult to
troubleshoot
● Changes can cause performance problems
● 3rd party modules expect standard core tables
● Standard ways are safer:
● With EAV-Attributes we are not changing DB-structure
● Extension Attributes have their own tables
13. Modifying Core Tables?
● We are using or relying on directly the implementation (model) classes
instead of Service Contracts
● Example: $model->getData('erp_id');
17. Conclusion
● Requirements & custom attributes
● The right implementation
● Full potential of the EAV attributes
● All features of the Extension Attributes
● Avoid hacky solutions when possible