In this blog, I will show how we can get the Magento edition name and the version number.
When we are creating module which must be compatible with multiple versions of Magento 2 and/or must be compatible with both Magento 2 editions then we can use the edition name and/or the version number to write different code for each one if required. This approach is much better than creating multiple version of the module for minor Magento version upgrades. This makes maintenance as well testing easier.
To get the Magento 2 edition and version we have to use \Magento\Framework\App\ProductMetadataInterface , don’t confuse ProductMetadata with catalog product. This refers to the installed Magento, which is a product of Magento, Inc.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface'); $edition = $productMetadata->getEdition(); $version = $productMetadata->getVersion();
It will return edition name as Enterprise or Community and the version number like 2.4.0
Please comment if you face any issue or if there is any confusion. Thanks for checking out the blog.