Experiments
<?php
namespace VendorName\TestModule\Model\ResourceModel;
class CustomEav extends \Magento\Eav\Model\Entity\AbstractEntity
{
public function getEntityType() {
if(empty($this->_type)) {
$this->setType(\Magento\Catalog\Model\Product::ENTITY);
}
return parent::getEntityType();
}
}
...
$res = $this->_objectManager->get('VendorName\TestModule\Model\ResourceModel\CustomEav');
$product = $this->_objectManager->get('Magento\Catalog\Model\Product');
$res->load($product, 1);
var_dump($product->getData());
...
Now we get the proudct’s eav attributes.
Notes
Source: Magento\Eav\Model\Entity\AbstractEntity
See _loadModelAttributes()
in the above fle for details about the loading
process. Magento creates a UNION select to load attributes from each of the entity
type tables to locate the applicable attribute values.
See _collectSaveData()
in the above fle for how the saving process works.
EAV collections offer other methods such as addAttributeToSelect (note
that the feld methods, such as addFieldToFilter have been mapped to their
attribute counterparts).
Simple resource model extens Magento\Framework\Model\ResourceModel\Db\AbstractDb
References
Magento 2: Creating New Eav Entity and Model (Updated for Data Installation)