Pergunta

I've create my first plugin for prestashop. I want to add autoupdate functionality for autoupdate as do for example eBay module.

enter image description here

I did not found anything about that on documentation.

Foi útil?

Solução

I've been struggeling to figure out the correct process for this for a while. I thought the "upgrade it" button was only available for developers, who release their modules through the prestashop addons website (which is true) but if you chose not to publish there, here's how you update your own modules:

In the main file of your model, within the contructor method, you must have this line of code:

 $this->version = '1.0.0';
  • make a subdirectory in your module folder called upgrade
  • create a new file in this directory called install-1.0.1.php
  • put this code in the file:

<?php
  if (!defined('_PS_VERSION_'))
    exit;

  function upgrade_module_1_0_1($object, $install = false)
  {
    //your code here, for example changes to the DB...
    return true; //if there were no errors
  }
?>

  • In your main file, change it to $this->version = '1.0.1';
  • Create a zip file of your module folder
  • Navigate to the Modules page on your stores back end, and say "upload new module"
  • Upload the zip file

Now you should see 2 messages:

The module was successfully downloaded.

and

The following module(s) were upgraded successfully:

MyModule :

Current version: 1.0.1

1 file upgrade applied

Outras dicas

Prestashop Documentation.

You can also add an update file to your module: create an /upgrade folder in your module's folder, and put your update files in it, using the install-1.8.0.php name norm.

<?php
// Sample file for module update

if (!defined('_PS_VERSION_'))
  exit;

// object module ($this) available
function upgrade_module_1_8_0($object)
{
  // Your code to upgrade from version 1.8.0 of the module
}
?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top