I develop Magento extension for both Magento1.x and Magento2.x.
I want to provide a source code for all version(Magento1.x, Magento2.x).
I need to check Magento version in first part.
How to check?
function getVersion() {
……
}
if(getVersion() == “2.0”){
}
if(getVersion() == “1.x”) {
}
if(getVersion() == “2.2”){
}
I need script for getVersion function.
3
Answers
In Magento 1.x go to the root folder of your magento installation and type the following
This will output something like this:
In magento 2.x go to the root folder of your magento installation and type:
This will output something like this:
Magento 1
In Magento 1, you can simply find the version by this:
Magento 2.0
Up to Magento 2.0.7, you can get the version from
AppInterface
, which is a reference to theMagentoFrameworkAppInterface::VERSION
constant.Magento 2.1
But, after the release of Magento 2.1, you have two options to get Magento version programmatically.
First option is dependency injection (DI), by injecting
MagentoFrameworkAppProductMetadataInterface
into your constructor to retrieve the version, something like this:Another option is
ObjectManager
which is not recommended by MagentoN.b. well, if you use
MagentoFrameworkAppProductMetadata::getVersion()
function, then whether you are on 2.0.x or 2.1.x, you will get the correct version.In version 2 Magento support created a URL to help them determine the version of your store: example.com/magento_version.
Version 1 of Magento includes a Magento Connect Manager at the following URL: example.com/downloader.
In the footer of this page the Magento Connect Manager version shown, and we know this to be the same version as the Magento install.