Child pages
  • New Developers Features In PrestaShop 1.5

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

PrestaShop brings the ability of defining dynamic hooks. In effect, there is now a hook before and after each action of each controller: PrestaShop's ObjectModel has been updated so that this new feature is automatically applied to existing code.

Info

Coming soon...

Evolution Of The Override System

...

New Filetree And Operations

A présent, il est conseillé d'éviter l'appel de fichier de module directement.
Exemple avant, lors d'un paiement par le module cheque, on arrivait sur une url du type In previous version of PrestaShop, there could be situations when you would have to call one of the module's file directly. For instance, when paying with the Cheque module, you would have to reach such a URL: http://localhost/prestashop-14x/modules/cheque/payment.php Cette méthode fonctionne toujours en 1.5 mais il est possible (et fortement conseillé) de construire ces modules afin d'appeler les pages des modules sous la forme suivante :

It is now recommended to avoid directly calling files from the module. While it will still work in v1.5, we strongly advise you to refrain from it, and use this safer URL path: http://localhost/prestashop-15x/index.php?fc=module&module=cheque&controller=payment

Pour procéder ainsi, on place des FrontController dans le module. Dans le cas du paiement pour le module cheque, on a placé le fichier suivant dans le module This is achieved by using FrontController classes in your module. In the example of the Cheque module, the following file has been place in the module's filetree: /modules/cheque/controllers/front/payment.php

Le nom de la "classe" doit être composé de la manière suivante NomDuModule NomDeLaPage suivi de "ModuleFrontController"

That "class" name must be built using the following syntax: class ModuleNamePageName extends ModuleFrontController.

Here is an example:

Code Block
class ChequePaymentModuleFrontController extends ModuleFrontController
{
  public $display_column_left = false;
  public $ssl = true;

  /**
  * @see FrontController::initContent()
  */
  public function initContent()
  {
    parent::initContent();

    $cart = $this->context->cart;
    if (!$this->module->checkCurrency($cart))
      Tools::redirect('index.php?controller=order');

    $this->context->smarty->assign(array(
      'nbProducts'    => $cart->nbProducts(),
      'cust_currency' => $cart->id_currency,
      'currencies'    => $this->module->getCurrency((int)$cart->id_currency),
      'total'         => $cart->getOrderTotal(true, Cart::BOTH),
      'isoCode'       => $this->context->language->iso_code,
      'chequeName'    => $this->module->chequeName,
      'chequeAddress' => Tools::nl2br($this->module->address),
      'this_path'     => $this->module->getPathUri(),
      'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->module->name.'/'
    ));

    $this->setTemplate('payment_execution.tpl');
  }
}

Le template The payment_execution.tpl appelé dans ce controller doit être placé de la manière suivante :
template file, called at the end of this controller, must be placed in the following path: /modules/cheque/views/templates/front/payment_execution.tpl

Avec l'url With this in place, when calling this URL: http://localhost/prestashop-15x/index.php?fc=module&module=cheque&controller=payment,
PrestaShop chargera automatiquement le controller si il est bien placé et bien nommé.

D'une manière générale, il est conseillé que l'architecture des modules doit ressembler à ceci en 1.5

...

PrestaShop will automatically load the controller, provided it is correctly placed and named.

Generally speaking, a PrestaShop 1.5 module should now use the following filetree:

  • /config.xml: Automatically created by PrestaShop when the module is loaded.
  • /mymodule.php
  • /mymodule.jpg: Logo file, 16*16 pixels. For versions of PrestaShop up to v1.4.
  • /mymodule.png: Logo file, 32*32 pixels. For PrestaShop 1.5 and later.
  • /controllers/
  • /controllers/front/myfile.php: As explained above.
  • /translations/
  • /translations/fr.php: French language file, created automatically when you start translating the module in your back-office.
  • /translations/de.php: Deutsh language file, created automatically when you start translating the module in your back-office.
  • /translations/...: ...and so on...
  • /views/
  • /views/css/: For CSS files.
  • /views/js/: For JavaScript files.
  • /views/templates/front/: For template files used by the module's controllers.
  • /views/templates/hooks/: For template files directly used by the module. For backward compatibility purposes, this type of files can also be placed in the root folder of the module.

Multishop Feature

Si votre module ne fait qu'utiliser des Configuration::get et Configuration::updateValue pour stocker des données, alors il est déjà compatible multiboutique.
Si votre module créé des tables de données spécifiques à son fonctionnement, il faut penser à ajouter une ligne id_shop que vous pourrez remplir avec l'id shop du content lors des insertions en base.

...