When looking around the M2 source trying to figure out how to get the entity_type_id I see a lot of this :

$this->_entityTypeId = $this->_objectManager->create(

However, I thought never invoking the ObjectManager directly was the new mantra in M2. Is this the best way to get the entity_type_id?


You can use Dependency Injection instead of the Object Manager:

private $eavConfig;

public function __construct(
    \Magento\Eav\Model\Config $eavConfig
) {
    $this->eavConfig = $eavConfig;

public function myFunction()
    $entityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntityTypeId();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.