During some tasks, I was not aware of exactly how Magento loads values for attributes that are available. for example, if we have loaded Product Model and attributes in $product->getData(). Which classes and methods are responsible for loading text attribute values?
I'm searching how Magento loads attribute values for \Magento\CatalogImportExport\Model\Export\Product
but cant figure it out. I ran debug over and over again. but, it's a massive object-oriented relations code. Can anyone point to the place that is responsible for that? Xdebug points me to \Magento\Eav\Model\ResourceModel\Entity\Attribute
but the magic happens there and we have value :).
But, I want to know how it's working now?
PS. happy for me that it was not needed for the task, but now I need to figure out how it work for myself.
Best Answer
You can load product in Magento with 2 ways, load single product and load collection. As I correct understand you are interest how Magento EAV works for single load. In this case:
The following methods are generally doing the same
\Magento\Catalog\Api\ProductRepositoryInterface::get()
\Magento\Catalog\Api\ProductRepositoryInterface::getById()
\Magento\Catalog\Model\Product::load()
How it works
\Magento\Catalog\Model\ResourceModel\Product
.loadAttributesForObject
method to determine which attribute should be loaded. By default uses\Magento\Eav\Model\Entity\AttributeLoader::loadAllAttributes
logic.\Magento\Framework\EntityManager\EntityManager::load
) and pass product model.read
(\Magento\Framework\EntityManager\Operation\Read
) operation from\Magento\Framework\EntityManager\OperationPool
\Magento\Framework\EntityManager\Operation\Read\ReadAttributes::execute
) and read extensions (\Magento\Framework\EntityManager\Operation\Read\ReadExtensions::execute
) inexecute
method\Magento\Framework\EntityManager\Operation\AttributePool
) the system collectread
actions for entity (seedi.xml
)execute
for each actions and loads default attributes data in\Magento\Eav\Model\ResourceModel\ReadHandler::execute
and collect product data\Magento\Catalog\Model\Product\Hydrator
) sets collected data into product model