Back to Top

Get Magento 2 Version and Edition in Frontend Programatically

Updated 28 February 2018

Hello everyone.
There are several situations where we need to programmatically know the Version and Edition of Magento 2. You can use the below code to get both the version and edition (Community or Enterprise) of Magento.

First of all, make an instance of the class \Magento\Framework\App\ProductMetadataInterface in the construct as below

 public function __construct(
        ...
        \Magento\Framework\App\ProductMetadataInterface $productMetadata,
        ...
    ) {
        ...
        $this->_productMetadata = $productMetadata;
        ...
    }

After that, you can use the following codes to print the version and edition of Magento-

public function getMagentoInformation() {
    echo "Magento Version => ".$this->_productMetadata->getVersion();
    echo "Magento Edition => ".$this->_productMetadata->getEdition();
}

Above lines of code will print the Magento 2 Version and Magento 2 Edition as you can see in the below screenshot-

Magento 2 Version and Edition

Searching for an experienced
Magento 2 Company ?
Find out More

I have Used this snippet of code in Controller, but you can use this in Block or Helper files as per your need.

This is all for now. Hope it will help. ­čÖé

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home