Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare magento version programmatically?

Tags:

magento

I am trying to compare magento version so I can check if the current version is greater then 1.6 use the code otherwise don't. I can get the magento version by using Mage::getVersion() and it returns 1.7.0.2 (a string) but how do I compare it so that my code won't break the page when installed on another magento whose version lower then this? Is there any other way better than this. solution must be from within magento.

like image 303
R T Avatar asked Jan 10 '14 07:01

R T


People also ask

How do I check Magento version?

In order to check the Magento version, you need to log into your Magento Admin Panel. Once you scroll down the page, you will see the Magento version in the bottom (footer) right corner.

How do I know if I have Magento 2 community or enterprise?

You can check using Magento admin panel, Click On Sales Tab from left panel, If Archive is display in your sub navigation, Its enterprise feature.

What are the different versions of Magento?

Magento offers two versions of its platform – Magento community edition, a free open source version and Magento Enterprise edition a paid premium version allowing businesses to leverage Magento's full set of features.


2 Answers

You can use the version_compare function.

$magentoVersion = Mage::getVersion();
if (version_compare($magentoVersion, '1.6', '>=')){
    //version is 1.6 or greater
} 
else {
    //version is below 1.6
}
like image 113
Marius Avatar answered Oct 02 '22 06:10

Marius


if(version_compare(Mage::getVersion(), '1.7.0.2') > 0)
like image 38
Asif hhh Avatar answered Oct 02 '22 07:10

Asif hhh