{"id":11882,"date":"2020-11-27T14:52:19","date_gmt":"2020-11-27T09:22:19","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=11882"},"modified":"2020-12-07T18:23:52","modified_gmt":"2020-12-07T12:53:52","slug":"magento-2-edition-version","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento\/magento-2-edition-version\/","title":{"rendered":"Magento 2 &#8211; How to get Magento 2 Edition and Version"},"content":{"rendered":"<p>In this post I am going to explain how to get Magento 2 edition and version.<\/p>\n<p><strong>1. Using Dependency Injection<\/strong><\/p>\n<p>Add below code snippet in Block class.<\/p>\n<pre class=\"lang:default decode:true \">protected $_productMetadataInterface;\r\n    \r\npublic function __construct(\r\n    \\Magento\\Framework\\View\\Element\\Template\\Context $context,\r\n    \\Magento\\Framework\\App\\ProductMetadataInterface $productMetadataInterface,\r\n    array $data = []\r\n) {\r\n    $this-&gt;_productMetadataInterface = $productMetadataInterface;\r\n    parent::__construct($context, $data);\r\n}\r\n\r\n\/* Get Magento 2 Edition *\/\r\npublic function getEdition()\r\n{\r\n    $edition = $this-&gt;_productMetadataInterface-&gt;getEdition();\r\n    return $edition;\r\n}\r\n\r\n\/* Get Magento 2 Version *\/\r\npublic function getVersion()\r\n{\r\n    $version = $this-&gt;_productMetadataInterface-&gt;getVersion();\r\n    return $version;\r\n}<\/pre>\n<p>Add below code snippet in template file.<\/p>\n<pre class=\"lang:default decode:true\">\/\/Get Magento 2 Edition\r\n$edition = $block-&gt;getEdition();\r\necho $edition;\r\n\r\n\r\n\/\/Get Magento 2 Version\r\n$version = $block-&gt;getVersion();\r\necho $version;<\/pre>\n<p><strong>2. Using Object Manager<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n\r\n$productMetadataInterface = $objectManager-&gt;get('Magento\\Framework\\App\\ProductMetadataInterface');\r\n\r\n\/\/Get Magento 2 Edition\r\n$edition = $productMetadataInterface-&gt;getEdition();\r\necho $edition;\r\n\r\n\/\/Get Magento 2 Version\r\n$version = $productMetadataInterface-&gt;getVersion();\r\necho $version;<\/pre>\n<p>It will return edition name like Community or Enterprise and the version like 2.3.5-p1.<\/p>\n<div class=\"angwp_12010 _ning_cont _ning_hidden _ning_outer _align_center responsive\" data-size=\"custom\" data-bid=\"12010\" data-aid=\"0\" style=\"max-width:800px; width:100%;height:inherit;\"><div class=\"_ning_label _left\" style=\"\"><\/div><div class=\"_ning_inner\" style=\"\"><a href=\"https:\/\/www.hiddentechies.com\/blog?_dnlink=12010&t=1775814037\" class=\"strack_cli _ning_link\" target=\"_blank\">&nbsp;<\/a><div class=\"_ning_elmt\"><img decoding=\"async\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/angwp\/items\/12010\/Banner-2.png\" \/><\/div><\/div><\/div><div class=\"clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>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. protected $_productMetadataInterface; public function __construct( \\Magento\\Framework\\View\\Element\\Template\\Context $context, \\Magento\\Framework\\App\\ProductMetadataInterface $productMetadataInterface, array $data = [] ) { $this-&gt;_productMetadataInterface = $productMetadataInterface; parent::__construct($context, $data); } \/* Get Magento 2 Edition *\/ public&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento\/magento-2-edition-version\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":12109,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[181,59,2138],"tags":[735,9,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/11882"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=11882"}],"version-history":[{"count":3,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/11882\/revisions"}],"predecessor-version":[{"id":12104,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/11882\/revisions\/12104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/12109"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=11882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=11882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=11882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}