PHP code example of rubenmartindev / prestashop-version-checker

1. Go to this page and download the library: Download rubenmartindev/prestashop-version-checker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rubenmartindev / prestashop-version-checker example snippets


// Check if PrestaShop version is less than 1.7
if (is_ps_version('<1.7')) {
    // PrestaShop 1.6.x code
}

// Check if PrestaShop version is greater than or equal to 1.7
if (is_ps_version('>=1.7')) {
    // PrestaShop 1.7+ code
}

use RubenMartinDev\PrestaShopVersionChecker\PrestaShopVersionChecker;

if (PrestaShopVersionChecker::is('<1.7')) {
    // PrestaShop 1.6.x code
}

use RubenMartinDev\PrestaShopVersionChecker\PrestaShopVersionChecker;

// Less than
PrestaShopVersionChecker::lt('1.7');    // Same as is('<1.7')

// Less than or equal
PrestaShopVersionChecker::lte('1.7');   // Same as is('<=1.7')

// Greater than
PrestaShopVersionChecker::gt('1.6');    // Same as is('>1.6')

// Greater than or equal
PrestaShopVersionChecker::gte('1.7');   // Same as is('>=1.7')

// Equal
PrestaShopVersionChecker::eq('1.7.8');  // Same as is('==1.7.8')

// Not equal
PrestaShopVersionChecker::neq('1.6');   // Same as is('!=1.6')

use RubenMartinDev\PrestaShopVersionChecker\PrestaShopVersionChecker;

PrestaShopVersionChecker::isCompareValid('<1.7');    // true
PrestaShopVersionChecker::isCompareValid('gt 1.7');  // true

PrestaShopVersionChecker::isCompareValid(1.7);       // false
PrestaShopVersionChecker::isCompareValid('foobar');  // false

class MyModule extends Module
{
    public function hookDisplayHeader()
    {
        if (is_ps_version('<1.7')) {
            return $this->display(__FILE__, 'views/templates/hook/header_16.tpl');
        }

        return $this->display(__FILE__, 'views/templates/hook/header.tpl');
    }
}