Child pages
  • Using the backward compatibility toolkit

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Using the backward compatibility

...

toolkit

Description

PrestaShop's module API has greatly improved between version 1.4 and version 1.5 of the software.

Because there is a huge ecosystem of modules that are being upgraded to support the 1.5 module API while many shops are still using PrestaShop 1.4, the developers of PrestaShop chose to build Backward Compatibility, a free module toolkit which is only available for PrestaShop 1.4, and makes it possible to make 1.5 modules work in PrestaShop 1.4.

Including this module toolkit makes it possible to develop a 1.4 module that uses PrestaShop 1.5 standards.

...

Code Block
$this->context->customer->id;
$this->context->language->id;
$this->context->smarty->assign('content', 'empty');
...

Download and install

You can download it directly from PrestaShop's repository: https://github.com/PrestaShop/PrestaShop-backward_compatibility .
Just clone the Git project, then copy the content of the /backward_compatibility folder to the root folder of the module you are developing.

You do not have to click "Install" on this module in PrestaShop's "Modules" administration.

For instance, if your module is called TestModule, the folder should be here: /modules/testmodule/backward_compatibility.

The /backward_compatibility folder should contain the following files:

  • backward.ini: the version number of the toolkit.
  • backward.php: the main code.
  • Context.php: adds a Context-like support to PrestaShop 1.4, as well as backward compatible Controller- and Customer-like methods.
  • Display.php: enables the display of TPL files in the back-office.
  • index.php: just a file to prevent the display of the folder to visitors.
Note

It is useless the to install the module toolkit in PrestaShop 1.5.

How to use the module

To properly us the module, you must first declare it in the module constructor method:

...

Once this is in place, you can call $this->backward in your module in order to pinpoint 1.5- or 1.4-specific code:

Code Block
public function install()
{
    if (!$this->backward && _PS_VERSION_ < 1.5)
    {
        echo '<div class="error">'.Tools::safeOutput($this->l('In order to work properly in PrestaShop v1.4, the Test module requires the Backward Compatibility module 0.3+.')).'</div>';
        return false;
    }

    ...

...or if you want to prevent code from being used under PrestaShop 1.4 as long as the Backward Compatibility module is not available:

...

use more of the 1.5 API's goodness, such as the Context.