{ Hello Magento 2 }

解决 Magento 2 应用问题,更注重深度挖掘。(ง •̀_•́)ง

0%

how eav load

Experiments

1
2
3
4
5
6
7
8
9
10
11
12
13
<?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();
}

}
1
2
3
4
5
6
7
...
$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)