In this post I am going to explain how to get Magento 2 edition and version.
1. Using Dependency Injection
Add below code snippet in Block class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | protected $_productMetadataInterface; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\ProductMetadataInterface $productMetadataInterface, array $data = [] ) { $this->_productMetadataInterface = $productMetadataInterface; parent::__construct($context, $data); } /* Get Magento 2 Edition */ public function getEdition() { $edition = $this->_productMetadataInterface->getEdition(); return $edition; } /* Get Magento 2 Version */ public function getVersion() { $version = $this->_productMetadataInterface->getVersion(); return $version; } |
Add below code snippet in template file.
1 2 3 4 5 6 7 8 | //Get Magento 2 Edition $edition = $block->getEdition(); echo $edition; //Get Magento 2 Version $version = $block->getVersion(); echo $version; |
2. Using Object Manager
1 2 3 4 5 6 7 8 9 10 11 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productMetadataInterface = $objectManager->get('Magento\Framework\App\ProductMetadataInterface'); //Get Magento 2 Edition $edition = $productMetadataInterface->getEdition(); echo $edition; //Get Magento 2 Version $version = $productMetadataInterface->getVersion(); echo $version; |
It will return edition name like Community or Enterprise and the version like 2.3.5-p1.
Leave a Reply