Child pages
  • New Developers Features In PrestaShop 1.5
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

What's new in PrestaShop 1.5

The new version of PrestaShop brings a lot of new and updated features to improve online shopping for both customers and shop owners, and the API have been dutifuly updated and expanded in order to help developers and designers leverage these new possibilities.

The technical documentation itself has been updated to reflect the new state of working with PrestaShop. This chapter describes all the changes between v1.4 and v1.5, in order to help you get up to date quickly.

PrestaShop Core

Coming soon...

Module API

There are six main aspects of PrestaShop's Module API which received a significant overhaul for version 1.5: dynamic hooks, evolution of the override system, new filetree and operations, multishop feature, Addons webservice, and the update system. We will explore these one by one.

Hooks

Hooks are a fundamental part of PrestaShop's modules API. They enable modules to 'hook into' the rest of PrestaShop, and call functions at specific times, thereby setting your own code in motion.

There are two families of hooks:

  • "Action" hooks. For example, to send out a mail when a client creates a user account.
  • "View" hooks. For example, to display a module in a column.

New hooks

Coming soon...

Dynamic hooks

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.

Coming soon...

Evolution Of The Override System

PrestaShop's override system, which was introduced with PrestaShop 1.4, makes it easier for third party developers to include changes to the core methods without changing the core files.

Until now, you could only override PrestaShop's classes and controllers by placing the appropriate file(s) in either the /override/classes folder or the /override/controllers on.. The module API in PrestaShop 1.5 now enables you to override classes and controllers directly from a module.

For instance, should you need to override the Cart.php class, you could do this from a module: instead of placing your customized Cart.php file in the root's /override/classes folder, now you can simply put your Cart.php file directly in the /override/classes of your module's folder. PrestaShop will automatically merge of the module's overriding code and the overriding code that would already exist in the root /override folder.

The advantages are numerous, the major ones being:

  • easier to manage, install, and share along with the module itself.
  • multiple modules can make changes to the core classesn as long as they do not attempt to override the same functions.

New Filetree And Operations

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

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

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

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

Here is an example:

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');
  }
}

The payment_execution.tpl template file, called at the end of this controller, must be placed in the following path: /modules/cheque/views/templates/front/payment_execution.tpl

With this in place, when calling this URL: http://localhost/prestashop-15x/index.php?fc=module&module=cheque&controller=payment, 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.

Un module dit "non compatible" multiboutique, est un module qui aura une seule configuration pour toutes les boutiques.
Cela n'empêchera donc pas son bon fonctionnement.

Addons Webservice

Vous l'avez surement remarqué beaucoup de modules natifs (tels que PayPal) ne sont plus présents physiquement en 1.5
La liste des modules natifs est récupéré via webservices avec PrestaShop Addons et varie selon le pays par défaut de votre boutique (ainsi les modules qui vous sont proposés sont en rapport avec votre pays).
Lors du clic sur le bouton "install", PrestaShop récupère automatiquement la dernière version du module vous permettant ainsi de bénéficier des nouvelles fonctionnalités du module sans avoir à le mettre à jour manuellement par la suite.

Update System

Si il s'agit d'un module présent sur Addons (un module acheté ou un module natif), PrestaShop proposera un bouton "Mise à jour" au niveau du module et il sera alors possible de mettre à jour le module en un clic.

Le bouton apparait aussi si vous faites une mise à jour du module en uploadant le zip manuellement et que PrestaShop détecte que la version a changé.

Il est également possible de faire des fichiers d'upgrade :
Créer un répertoire /upgrade/ et placer vos fichiers d'upgrade à l'intérieur sous la forme install-VersionModule.php

// Code

Le fichier install-1.8.0.php devra être construit de la manière suivante :

<?php

// File Example for upgrade

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

// object module ($this) available
function upgrade_module_1_8_0($object)
{
}

// Code

Par exemple si le répertoire contient les fichiers suivants :
install-1.8.0.php
install-1.8.1.php
install-1.8.2.php
install-1.8.3.php

Et que vous passez de la version 1.8.1 à la version 1.8.3, seuls les fichiers install-1.8.2.php et install-1.8.3.php seront appelés

Theme API

Coming soon...

  • No labels