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 6 Next »

Table of contents

Creating Modules

PrestaShop has a very flexible module system that lets you add functionality to PrestaShop without modifying any of its core files.  Much of PrestaShop’s core functionality is also written using modules, which minimises the size of PrestaShop’s core.  Unneeded modules can be deleted to save space on the server.  The following sections describe how to create various types of PrestaShop modules.

Creating a Basic Module

Creating the Module Files

The first step to creating a module is coming up with a unique directory name for the module.   It is convention for a module’s directory name to be all lowercase letters and have one of the following prefixes:

Prefix

Description

block

Used for modules that appear as a block in the left or right columns.

graph

Used for graphing modules on the Statistics tab.

grid

Used for grid modules on the Statistics tab.

home

Used for modules that appear in the centre column on the homepage.

product

Used for modules that appear on the product page

stats

Used for statistics modules on the Statistics tab.

If the module doesn’t fit any of these categories, then no prefix is used.  One way to ensure your module name is unique is to use a vendor suffix.  For example, Nethercott Constructions uses the nc suffix on its module names to ensure they are unique.

Once you’ve selected a name, create a directory in the /modules directory with the name you selected.  Next, create a file in the new directory with the same name as the directory followed by .php.  For example, if the name of your module is helloworldnc, then create a file helloworldnc.php in the helloworldnc directory.  In that file, copy the required if statement from the top of another module, then add a new class with the same name as the file that extends the Module class.  The case of the class name isn’t important, though it is convention to use an uppercase letter at the start of each word.  Here’s an example:

<?php
if (!defined('_CAN_LOAD_FILES_'))
    exit;
class HelloWorldNC extends Module
{
}
?>

Your module will now appear on the Modules tab in the Other Modules section.

Adding the Constructor

Although your module will now appear in the Other Modules section on the Modules tab, it will not display a name or description.  You will need to add a constructor inside the class to add that information.  Here’s an example constructor:

public function __construct()
{
    $this->name = 'helloworldnc';
    $this->tab = 'front_office_features';
    $this->version = '1.0';
    $this->author = 'Nethercott Constructions';
    parent::__construct();
    $this->displayName = $this->l('Hello World');
    $this->description = $this->l('This is an example module');
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
    if (!Configuration::get('HELLO_WORLD_NC_NAME'))
        $this->warning = $this->l('No name provided');
}

The name variable must be the directory name you chose for the module.  The tab variable is used to select which section the module appears in.  It must be one of the following values:

Tab Value

Tab Name

administration

Administration

advertising_marketing

Advertising & Marketing

analytics_stats

Analytics & Stats

billing_invoicing

Billing & Invoicing

checkout

Checkout

content_management

Content Management

export

Export

front_office_features

Front Office Features

i18n_localization

I18n & Localization

market_place

Market Place

merchandizing

Merchandizing

migration_tools

Migration Tools

others

Other Modules

payments_gateways

Payments & Gateways

payment_security

Payment Security

pricing_promotion

Pricing & Promotion

quick_bulk_update

Quick / Bulk update

search_filter

Search & Filter

seo

SEO

shipping_logistics

Shipping & Logistics

slideshows

Slideshows

smarty_shopping

Smart Shopping

social_networks

Social Networks

Any value other than the ones above will place the module in the Other Modules section.

The version variable can be any number you like.  It is used to make it easy to identify which version of the module you are using.  It is convention to use numbers below 1.0 before all the planned features have been added to the module, then increment the value as bugs are fixed and more features are added.

The author variable is the author name displayed after “by” in the module listings.  It can also be used to filter modules by author.

Next, the parent constructor is called, which sets the name variable to the module’s ID if no name was provided, then it adds the module to the cache, then creates a _path variable with the module’s path.

The displayName variable must be the module name that is displayed in bold on the Modules tab and the description variable must be the description of the module displayed below the module’s name.

The confirmUninstall variable is an optional variable that lets you specify a confirmation message to display before uninstalling the module.  If uninstalling your module will cause important information to be lost, then it is a good idea to add a confirmation message.

The warning variable is another optional variable that lets you specify a warning message to display at the top of the Modules tab.  If your module requires information to be entered before it can function correctly, then it is a good idea to check whether it has been set and display a warning if it hasn’t been set.

You must also put a 16 x 16 pixel GIF image called logo.gif in your module’s directory.  Your module should then display on the Modules tab.

Adding the config.xml File

The next thing you should do is add a config.xml file to your module.  Although one isn’t required, it helps to reduce the amount of memory required by the Modules tab by loading only the file instead of the entire module to get the module’s name and description.  Here is an example config.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<module>
    <name><![CDATA[helloworldnc]]></name>
    <displayName><![CDATA[Hello World]]></displayName>
    <version><![CDATA[1.0]]></version>
    <author><![CDATA[Nethercott Constructions]]></author>
    <description><![CDATA[This is an example module]]></description>
    <tab><![CDATA[front_office_features]]></tab>
    <is_configurable>1</is_configurable>
    <need_instance>1</need_instance>
    <limited_countries></limited_countries>
</module>

The first line is used to define the file as an XML file with UTF-8 encoding.  The rest of the file creates a module object with a number of variables.  The values of most variables are wrapped in <![CDATA[ ]]> to prevent the values being parsed as XML.  The name variable is the directory name of the module.  It is important for this value to match the module’s directory, otherwise the logo will not display and none of the module links will work. 

The displayName, version, author, description and tab variables should be the same as the module display name, version, description and tab that you specified in the module’s code.  It is best that they match the ones in the module, though no errors will occur if they don’t.

The is_configurable variable is used to indicate whether the module has a configuration page.  If it does, set the variable to 1, otherwise set it to 0.  It is important for this value to be correct, otherwise the Configure link may be missing from the module, making it impossible to access the configuration page, or cause an error when it is clicked and no configuration page actually exists.

The need_instance variable is used to indicate whether an instance of the module needs to be created when the Modules tab is loaded.  If the value is 0, then the module will not be loaded, which will save time and memory.  If the value is 1, then the module will be loaded.  If your module may need to display a warning message on the Modules tab, then you should choose the value 1.  Otherwise, choose 0 to save time and memory.

The limited_countries variable can optionally be used if a module should only be available in a specific country. For example, the following line uses the country ISO code to limit a module to France only:

<limited_countries>fr</limited_countries>

Adding the Install and Uninstall Functions

Although your module is now displayed on the Modules tab, you won’t be able to install it yet.  You will need to add an install() function inside the class before you can install the module.  Here’s an example install() function:

public function install()
{
    if (!parent::install() OR
        !$this->registerHook('leftColumn') OR
        !$this->registerHook('header') OR
        !Configuration::updateValue('HELLO_WORLD_NC_SHOW_NAME', 1) OR
        !Configuration::updateValue('HELLO_WORLD_NC_NAME', 'World'))
        return false;
    return true;
}

The install() function uses an if statement to call the parent install function, place the module in left column and header hooks, and set variables to their default values.  If any of these return false, then the install() function will return false, which causes PrestaShop to display an error message.

If they all return true, then the install() function will return true, which causes PrestaShop to display the "Module installed successfully" message.

It is also a good idea to add an uninstall() function, so that all the module’s settings are removed from the database when the module is not being used.  For example:

public function uninstall()
{
    if (!parent::uninstall() OR
        !Configuration::deleteByName('HELLO_WORLD_NC_SHOW_NAME') OR
        !Configuration::deleteByName('HELLO_WORLD_NC_NAME'))
        return false;
    return true;
}

The uninstall() function uses an if statement to call the parent uninstall() and delete all configuration values related to the module from the database.  Like the install function, the uninstall() function returns false if any of these return false or returns true otherwise, which causes messages similar to the ones above to be displayed.

It is convention for configuration names to be all uppercase and use underscores between words.  They must also be no more than 32 characters long, otherwise PrestaShop will display an error message.

You now have a module that can be installed and uninstalled.

Adding the Configuration Page

Although your module can now be installed and uninstalled, you won’t be able to configure the module.  If your module has settings that should be easy to change, you should add a configuration page.  The getContent() function is called when the Configure link on a module is clicked.  It displays the name of the module, then calls the displayForm() function to display the configuration page form.  Here’s an example:

public function getContent()
{
    $output = '<h2>'.$this->displayName.'</h2>';
    return $output.$this->displayForm();
}
public function displayForm()
{
    return '
    <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
        <fieldset>
            <legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
            <label>'.$this->l('Name').'</label>
            <div class="margin-form">
                <input type="text" name="name" value="'.Tools::getValue('name', Configuration::get('HELLO_WORLD_NC_NAME')).'" />
                <p class="clear">'.$this->l('The name that will appear after Hello').'</p>
            </div>
            <label>'.$this->l('Show Name').'</label>
            <div class="margin-form">
                <input type="radio" name="showName" id="showName_on" value="1" '.(Tools::getValue('showName', Configuration::get('HELLO_WORLD_NC_SHOW_NAME')) ? 'checked="checked" ' : '').'/>
                <label class="t" for="showName_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
                <input type="radio" name="showName" id="showName_off" value="0" '.(!Tools::getValue('showName', Configuration::get('HELLO_WORLD_NC_SHOW_NAME')) ? 'checked="checked" ' : '').'/>
                <label class="t" for="showName_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
                <p class="clear">'.$this->l('Whether to show the name after Hello').'</p>
            </div>
            <center><input type="submit" name="submitHelloWorldNC" value="'.$this->l('Save').'" class="button" /></center>
        </fieldset>
    </form>';
}

This function simply returns a single long text string that contains the HTML of the configuration page.  The <form> line is used to post the current configuration settings to the module.  If you add a file field as one of the configuration settings, you must change this to the following before the files will be posted:

<form action="'.$_SERVER['REQUEST_URI'].'" method="post" enctype="multipart/form-data">

The <fieldset> line is used to create a box around all related configuration settings and the <legend> line is used to add a label to the top of the box to describe the contents.  In the example, the label Settings is used along with the module’s logo.  The code $this->l('Settings') is used to make the text translatable via Tools > Translations > Module translations in the Back Office.

The <label> lines are used to display the labels of the configuration setting on the left side of the box and the <div class="margin-form"> lines display the configuration values on the right side of the box.

The first <input> line creates a text field with a unique name name, so it can be identified when it is posted.  The value Tools::getValue('name', Configuration::get('HELLO_WORLD_NC_NAME')) makes the text field use the current value of the text field before getting its saved value in the database.  This is important, since it allows the text field to retain its value when an error occurs instead of resetting the text field to the saved value.  This allows you to see what caused the error instead of wondering why the text field didn’t appear to save.

The <p> lines display descriptions that make it easier to understand what the configuration options do.

The second and third <input> lines are radio buttons that let you turn a configuration option on or off.  Both of these inputs have the same name showName, which is used to get the selected radio from the posted data.  Each input has a different ID though, which is the name followed by _on for the first input and _off for the second input.  The first input has a value of 1 and the second input has a value of 0.  After the first input is a green tick image and after the second input is a red cross image.  This makes it clear that the first option turns the configuration setting on and the second radio button turns it off.  The images are in <label> tags that link the labels to the images, so that clicking on an icon selects the radio button.

Lastly, the <center> line adds a save button at the bottom of the box.  It has a unique name submitHelloWorldNC and a value of Save, which is displayed as the label on the button.  The class="button" code styles the button using the current Back Office theme.

You should now have a Configure link on your module.

When you click the Configure link, you should see a configuration page.

Saving the Configuration Page Settings

Although you’ve now got a configuration page, you can’t save any of the settings.  To do that, you will need to add more code to the getContent() function.  Here’s an example:

public function displayErrors()
{
    $errors = 
        '<div class="error">
            <img src="../img/admin/error2.png" />
            '.sizeof($this->_errors).' '.(sizeof($this->_errors) > 1 ? $this->l('errors') : $this->l('error')).'
            <ol>';
    foreach ($this->_errors AS $error)
        $errors .= '<li>'.$error.'</li>';
    $errors .= '
            </ol>
        </div>';
    return $errors;
}
public function displayConf($conf)
{
    return
        '<div class="conf">
            <img src="../img/admin/ok2.png" /> '.$conf.'
        </div>';
}
public function getContent()
{ 
    $this->_errors = array();
    $output = '<h2>'.$this->displayName.'</h2>';
    if (Tools::isSubmit('submitHelloWorldNC'))
    {
        $name = Tools::getValue('name');
        $showName = (int)(Tools::getValue('showName'));
        if ($showName != 0 AND $showName != 1)
            $this->_errors[] = $this->l('Show Name: Invalid choice.');
        if (sizeof($this->_errors) == 0)
        {
            Configuration::updateValue('HELLO_WORLD_NC_NAME', $name);
            Configuration::updateValue('HELLO_WORLD_NC_SHOW_NAME', $showName);
            $output .= $this->displayConf($this->l('Settings updated'));
        }
    }
    else
        $output .= $this->displayErrors();
    return $output.$this->displayForm();
}

This function builds upon the previous function by checking whether data was posted, validating the data, and then displaying an error or success message after the module’s name and before the form.  The displayErrors() function groups all the error messages into a single box. The displayConf() function displays a confirmation message in the new PrestaShop v1.4 style.  It is the first if statement in the getContent() function that checks whether data was posted.  The first line in the if statement gets the value of the text field and second line gets the value of the radio buttons.  The radio button value is converted to an integer for data validation purposes.  If the radio button value isn’t either 0 or 1, then an error message is displayed.  This ensures that the setting always has a valid value.  If the radio button has a valid value, then the text field and radio button values are written to the database, then a success message is displayed.  Your module will now save the configuration settings.

Adding the Hooks

Although your module now has a fully working configuration page, it doesn’t do anything on the website.  To make the module do something, you must register hooks the module can be placed in.  Here’s an example:

public function hookLeftColumn($params)
{
    global $smarty;
    $smarty->assign(array(
        'name' => Configuration::get('HELLO_WORLD_NC_NAME'),
        'showName' => (int)(Configuration::get('HELLO_WORLD_NC_SHOW_NAME'))
    ));
    return $this->display(__FILE__, 'helloworldnc.tpl');
}
public function hookRightColumn($params)
{
    return $this->hookLeftColumn($params);
}
public function hookHeader()
{
    Tools::addJS($this->_path.'js/helloworldnc.js');
    Tools::addCSS($this->_path.'css/helloworldnc.css', 'all');
}

The hookLeftColumn function defines what code should be added when the module is placed in the left column hook.  The first line in the function makes the global $smarty variable accessible to the function.  This variable can be used to pass variables into a template file.  The next line gets the text field and radio settings from the database and creates Smarty variables.  The last line of the function calls the helloworldnc.tpl file in the module’s directory, which has access to the Smarty variables that were created.  It then returns the HTML generated by the template, which is displayed in place of the {$HOOK_LEFT_COLUMN} along with the HTML from any other modules that are also in the hook.

The hookRightColumn function simply calls the hookLeftColumn function, passing its parameters and returning the result.  This is a shortcut that makes it so that the module will display the exact same in either the left or right column.  Doing this also makes the code easier to maintain, since you don’t have to worry about changing code in two places.

The hookHeader function is used to add Javascript and CSS code inside the <head> tag of the website.  Be careful how you use it, since it is easy to confuse it with the hookTop function, which adds code to the top of the website in the header.  The first line in the function adds /modules/helloworldnc/js/examplenc.js to the list of Javascript files and the second line adds /modules/helloworldnc/css/helloworldnc.css to the list of CSS files with media type all.  This will add the following code in the <head> tag of the website (if CCC is disabled):

<link href="http://www.yoursite.com/modules/helloworldnc/css/helloworldnc.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="http://www.yoursite.com/modules/helloworldnc/js/helloworldnc.js"></script>

The reason these functions are called instead of adding this code directly is so that the module’s JavaScript and CSS are combined, compressed and cached along with all the other files.

Your module can now be added to the left and right columns.

Adding the Smarty Templates

Although the module can now be added to the left and right columns, it will generate an error, since it references a Smarty template that doesn’t exist.  The last step to creating a basic PrestaShop module is to add the Smarty templates.

Smarty templates are files ending in .tpl that contain HTML code and embedded PHP code using a special Smarty syntax.  See the official Smarty documentation for more information.  Here’s an example helloworldnc.tpl:

<div id="hello_world_block_left" class="block">
    <h4>{l s='Message' mod='helloworldnc'}</h4>
    <div class="block_content">
        <p>Hello, {if isset($showName) AND $showName AND isset($name) AND $name}{$name}{else}World{/if}</p>
    </div>
</div>

The first line creates a standard block with a unique ID so that it can be styled independently of other blocks.

The second line adds the label "Message" at the top of the block and makes it translatable in the Back Office.  The function name l stands for language, the parameter s stands for string and the parameter mod stands for module.  It is important to include the mod parameter with the name of the module for the translations to appear in the module translations.

The third line creates the content area of the block.

The fourth line adds the message in the content area.  When the module has its default configuration, the message will be "Hello, World".  If the name is changed on the configuration page, it will also change in the message.  If the module has been configured to hide the name, then only "Hello" will be displayed.

You now have a fully functioning module.

Adding CSS and JS

Although you have a fully functioning module, it doesn’t have any CSS or JS, which is usually required to create any module that is useful. In the Adding the Hooks section, you added code to include JavaScript and CSS files in the module, but you didn’t actually put anything inside these files.

It’s a good idea to put the CSS in a separate /css directory and the JavaScript in a separate /js directory to keep a clean file structure that matches the structure PrestaShop uses.  Here’s an example helloworldnc.css:

div#hello_world_block_left p { font-weight: bold }

In PrestaShop, it is convention to put CSS blocks containing only one line on a single line, and the last line of a CSS block doesn’t have a semicolon.  When there are multiple lines, it is convention to display the lines indented like this:

div#hello_world_block_left p {
    font-weight: bold;
    color: green
}

PrestaShop 1.4.3 uses jQuery v1.4.4, so including it in your module is unnecessary. The only JavaScript you need to include is any third-party libraries you require that build on jQuery. If you need to include inline JavaScript to the module's TPL file, be aware that Smarty will generate an error if there are any curly braces in the code. To prevent the errors, you should add {literal} before the JavaScript code and {/literal} after like this:

{literal}
function testFunction() { alert('Test'); }
{/literal}

If you need to combine both JavaScript and Smarty tags, then it's better to replace the JavaScript curly braces with the {ldelim} and {rdelim} tags like this:

function testFunction() {ldelim} alert('{$message}'); {rdelim}

This code will display the contents of the $message Smarty variable in a JavaScript alert box when the testFunction() is called.

Creating a Back Office Tab

The first step to creating a new Back Office tab is coming up with a unique filename ending in .php.   It is convention for a tab’s filename to start with Admin.  One way to ensure your tab name is unique is to use a vendor suffix.  For example, Nethercott Constructions uses the NC suffix on its tabs to ensure they are unique.

A new tab must be in the following format:

include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
 
class AdminHelloWorldNC extends AdminTab
{

}

The class name must match the filename of the tab.  The name of the class can be anything, though it is convention for the class name to start with Admin.

The next step is to add the constructor inside the class.  Here’s an example constructor:

private $_helloWorld = null;
 
public function __construct()
{
     $this->className = 'Configuration';
     $this->table = 'configuration';

     $this->_helloWorld = new HelloWorldNC();

     parent::__construct();
}

The first line creates a private variable that contains the Hello World module object.  The $this->className line specifies the class and the $this->table line specifies which database table is used to store and display data.  This can be used to display a table of categories, products or other data from the database.  Since this tab is simply a configuration page, the class name is 'Configuration' and the table is 'configuration'.

The $this->_helloWorld line creates the instance of the Hello World module used later in the tab to display the configuration page.  The parent::__construct() line calls the AdminTab class constructor, which sets up tab’s ID and default error messages.

Lastly, the display() and postProcess() functions need to be added.  For example:

public function display()
{
     $this->_helloWorld->displayForm();
}
 
public function postProcess()
{
     echo $this->_helloWorld->getContent();
}

To avoid duplicating code, the display() function calls the displayForm() function from the Hello World module object to display the same configuration page.  The postProcess() function calls the getContent() function of the Hello World module object to save the configuration page settings.

Module Hooks

Here's a list of all the module hooks available in PrestaShop.  The hooks are listed by title in the Back Office and some have a brief description. The descriptions have been replaced in the table below with more informative explanations of the hooks.  By default, only the hooks with a "Position" of 1 are displayed on the Modules > Positions tab.  To view all hooks, you must tick the "Display non-positionable hooks" checkbox.  Hooks with a "Live Edit" of 1 can have their modules rearranged visually using the "Live Edit" option on the Modules > Positions tab.

To call a hook, use the code Module::hookExec('name'), where name is from the name column below. In PrestaShop, it is convention to put the code generated by the hook in a variable called HOOK_NAME.  For example, the code to call all the modules in the left column blocks hook and then pass them into a TPL is:

$smarty->assign('HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'));

Hook Name

Title

Description

Pos

LE

payment

Payment

Used in order-payment.tpl to display the payment methods when checking out.

1

1

newOrder

New orders

Used to send emails and perform other actions after an order has completed.

0

0

paymentConfirm

Payment confirmation

Used by display a confirmation page before payment is completed.

0

0

paymentReturn

Payment return

Used in order-confirmation.tpl to display a payment successful message.

0

0

updateQuantity

Quantity update

Used for out-of-stock notifications when the quantity of a product changes.

0

0

rightColumn

Right column blocks

Used to add blocks in the right column.

1

1

leftColumn

Left column blocks

Used to add blocks in the left column.

1

1

home

Homepage content

Used to add blocks to centre column on homepage.

1

1

header

Header of pages

Used to add JavaScript or CSS inside the <head> tag.

1

0

cart

Cart creation and update

Used to run code when a cart is created or updated.

0

0

authentication

Successful customer authentication

Used to run code after a customer has successfully logged in.

0

0

addproduct

Product creation

Used to run code after a new product is created.

0

0

updateproduct

Product Update

Used to run code after a product is modified.

0

0

top

Top of pages

Used to add code in header at top of website.

1

0

extraRight

Extra actions on the product page (right column).

Used to add blocks below the "Add to cart" block on the product page.

0

0

deleteproduct

Product deletion

Used to run code after a product has been deleted.

0

0

productfooter

Product footer

Used to add new blocks above the "More info" tab.

1

1

invoice

Invoice

Used to add blocks on the right side when viewing order on the Orders tab.

1

0

updateOrderStatus

Order’s status update event

Used to run code before the status of an order is changed.

0

0

adminOrder

Display in Back-Office, tab AdminOrder

Used to run code before the status of an order is changed.

0

0

footer

Footer

Used to add code to footer at bottom of website.

1

0

PDFInvoice

PDF Invoice

Used to add extra information to the PDF invoice.

0

0

adminCustomer

Display in Back-Office, tab AdminCustomers

Used to add blocks when viewing a customer on the Customers tab.

0

0

orderConfirmation

Order confirmation page

Used in order-confirmation.tpl to display an order confirmation message.

0

0

createAccount

Successful customer create account

Used to run code after a new customer account has been created.

0

0

customerAccount

Customer account page display in front office

Used in my-account.tpl to add more entries on the "My Account" page.

1

0

orderSlip

Called when a order slip is created

Used to run code after a credit slip has been created.

0

0

productTab

Tabs on product page

Used to adds a new tab to the product page.

0

0

productTabContent

Content of tabs on product page

Used to add content to the new tab on the product page.

0

0

shoppingCart

Shopping cart footer

Used in shopping-cart.tpl to add a message below the shopping cart.

0

0

AdminStatsModules

Stats – Modules

Used to add a statistics module on the Stats tab.

1

0

GraphEngine

Graph Engines

Used to add a graph engine used to display statistics on the Stats tab.

0

0

orderReturn

Product returned

Used to run code after a merchandise return request has been added.

0

0

productActions

Product actions

Used to add buttons below the "Add to cart" button on the product page.

1

0

backOfficeHome

Administration panel homepage

Used to add code at the bottom of the Back Office Dashboard.

1

0

GridEngine

Grid Engines

Used to add a grid engine to display statistics on the Stats tab.

0

0

watermark

Watermark

Used to add a watermark to new images.

0

0

cancelProduct

Product cancelled

Used to run code after a product has been removed from an order.

0

0

extraLeft

Extra actions on the product page (left column).

Used to add links on the left side of the product page below the image.

0

0

productOutOfStock

Product out of stock

Used to run code when a product runs out of stock.

1

0

updateProductAttribute

Product attribute update

Used to run code when a product attribute has been updated.

0

0

extraCarrier

Extra carrier (module mode)

Used in order-carrier.tpl to add carriers when checking out.

0

0

shoppingCartExtra

Shopping cart extra button

Used in shopping-cart.tpl to add code at the bottom of the shopping cart summary.

1

0

search

Search

Used to run code after a search has been performed.

0

0

backBeforePayment

Redirect in order process

Used to redirect customer to a separate payment page instead payment methods.

0

0

updateCarrier

Carrier Update

Used to run code after a carrier has been modified.

0

0

postUpdateOrderStatus

Post update of order status

Used to run code after the status of an order has been changed.

0

0

createAccountTop

Block above the form for create an account

Used in authentication to add fields to the top of the account registration form.

1

0

backOfficeHeader

Administration panel header

Used in header.inc.php to add CSS and JS inside the <head> tag of the Back Office.

0

0

backOfficeTop

Administration panel hover the tabs

Used in header.inc.php to add code above the tabs in the Back Office.

1

0

backOfficeFooter

Administration panel footer

Used in footer.inc.php to add code above the footer of the Back Office.

1

0

deleteProductAttribute

Product Attribute Deletion

Used to run code after a product attribute has been deleted.

0

0

processCarrier

Carrier Process

Used to run code after the carrier step has been completed.

0

0

orderDetail

Order Detail

Used in order-detail.tpl to add a tracking URL.

1

0

beforeCarrier

Before carrier list

Used in order-carrier.tpl to add a message before the carrier list.

1

0

orderDetailDisplayed

Order detail displayed

Used in order-detail.tpl to add more information below the addresses.

1

0

paymentCCAdded

Payment CC added

Used to run code after credit card details have been added to the database.

0

0

extraProductComparison

Extra Product Comparison

Used in product-comparison.tpl to add code to bottom of product comparison table.

0

0

categoryAddition

Category creation

Used to run code after a category has been added.

0

0

categoryUpdate

Category modification

Used to run code after a category has been modified.

0

0

categoryDeletion

Category removal

Used to run code after a category has been deleted.

0

0

beforeAuthentication

Before Authentication

Used to run code after login details have been entered, even if they are wrong.

0

0

paymentTop

Top of payment page

Used in order-payment.tpl to add a message above all the payment methods.

0

0

afterCreateHtaccess

After htaccess creation

Used to run code after the .htaccess file has been generated.

0

0

afterSaveAdminMeta

After save configuration in AdminMeta

Used to run code after the Preferences > SEO & URLs tab has been saved.

0

0

myAccountBlock

My account block

Used to add more entries to the My Account block.

0

0

Cookie Structure

PrestaShop uses cookies encrypted with Rijndael or Blowfish to store all session information for customers and employees.  Separate cookies for each customer and employee are stored in the user's browser cache.  PrestaShop uses classes/Cookie.php to read and write its cookies.

The customer cookie is read on line 94 (in PrestaShop v1.4.2) of init.php and the employee cookie is read on line 32 of /admin/init.php.  To access the cookie from inside PrestaShop, add global $cookie; (or add $cookie to the list of global variables) to the top of the function in a class or at the top of a non-class file.  A variable in the cookie can then be accessed or changed using $cookie->variable.  To access the cookie from outside of PrestaShop, use code like the following:

include_once('path_to_prestashop/config/config.inc.php');
include_once('path_to_prestashop/config/settings.inc.php');
include_once('path_to_prestashop/classes/Cookie.php');
$cookie = new Cookie('ps');

Change 'ps' to 'psAdmin' to read the employee cookie.

Customer Cookie

The following table contains the public variables in PrestaShop's customer cookie, which are related to the current visitor on your website:

Variable

Description

date_add

The date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format).

id_lang

The ID of the selected language.

id_currency

The ID of the selected currency.

last_visited_category

The ID of the last visited category of product listings.

ajax_blockcart_display

Whether the cart block is "expanded" or "collapsed".

Viewed

The IDs of recently viewed products as a comma-separated list.

id_wishlist

The ID of the current wishlist displayed in the wishlist block.

checkedTOS

Whether the "Terms of service" checkbox has been ticked (1 if it has and 0 if it hasn't)

id_guest

The guest ID of the visitor when not logged in.

id_connections

The connection ID of the visitor's current session.

id_customer

The customer ID of the visitor when logged in.

customer_lastname

The last name of the customer. 

customer_firstname

The first name of the customer.

logged

Whether the customer is logged in.

passwd

The MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the customer used to log in.

email

The email address that the customer used to log in.

id_cart

The ID of the current cart displayed in the cart block.

checksum

The Blowfish checksum used to determine whether the cookie has been modified by a third party.
The customer will be logged out and the cookie deleted if the checksum doesn't match.

There are also variables for product customisation.  For example, pictures_1 contains the filenames of the images the customer has uploaded to product 1 (in the upload directory) and textfields_1 contains the text the customer has uploaded to product 1.  Use the following code to get the customisation files and textfields of product 1:

$files = $cookie->getFamily('pictures_1');
$textFields = $cookie->getFamily('textFields_1');

Employee Cookie

The following table contains the public variables in PrestaShop's employee cookie, which relates to the employee who is currently logged in to the Back Office:

Variable

Description

date_add

The date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format).

id_lang

The ID of the selected language.

id_employee

The ID of the employee.

lastname

The last name of the employee.

firstname

The first name of the employee.

email

The email address the employee used to log in.

profile

The ID of the profile that determines which tabs the employee can access.

passwd

The MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the employee used to log in.

checksum

The Blowfish checksum used to determine whether the cookie has been modified by a third party.
The customer will be logged out and the cookie deleted if the checksum doesn't match. 

There are also pagination and filter variables stored in the employee cookie so that the state of the tables is saved.  For example, the order_pagination variable stores how many orders are displayed per page and orderFilter_id_order stores the filter applied to the id_order column of the orders table.

Private Variables

These private cookie variables cannot be accessed directly like the public variables above.

Variable

Description

_name

The unique name of the cookie (the MD5 hash of "ps" for customer cookie or "psAdmin" for employee cookie and _COOKIE_KEY_ in config/settings.inc.php).

_expire

The expiry date of the cookie.  It can be changed using the setExpire function in classes/Cookie.php.  By default, PrestaShop cookies expire after 1728000 seconds (or 20 days).  This can be changed on line 65 (in PrestaShop v1.4.2) of classes/Cookie.php.

_domain

The domain name of the website where the cookie was created.  For example, yoursite.com.

_path

The path of the website where the cookie was created.  For example, /prestashop/.

_bf

The Blowfish instance used to encrypt and decrypt the cookie.

_key

The encrypted cookie key that is used by Blowfish to decrypt the cookie.

_iv

The encrypted cookie iv that is used by Blowfish to decrypt the cookie.

Database Structure

Here are descriptions of the database tables in PrestaShop v1.4.2. By default, each table has a prefix of ps_. When you install PrestaShop, you have the option of changing this prefix, which lets you install PrestaShop multiple times in the same database, and also helps to prevent table name conflicts with other shopping carts installed in the same database. The table names are all lowercase and use underscores between words, and include the types of objects in the table. For example, the ps_product table contains all the product information. Tables that end with _lang contain translations for the object. For example, ps_product_lang contains all the product translations. When a table links together two types of objects, both objects are included in the table name. For example, ps_category_product links products to categories. The ID of each table starts with id_ followed by the object name. For example, the ID of the ps_product table is id_product.

Table Name

Description

Primary Key

ps_access

The employee profile permissions.

id_profile, id_tab

ps_accessory

Product accessories.

id_product_1, id_product_2

ps_address

Customer, manufacturer and supplier addresses.

id_address

ps_address_format

Address format for each country.

id_country

ps_alias

Search keyword alias

id_alias

ps_attachment

Product attachments.

id_attachment

ps_attachment_lang

Product attachment names and descriptions.

id_attachment, id_lang

ps_attribute

Product attributes.

id_attribute

ps_attribute_group

Product attribute groups.

id_attribute_group

ps_attribute_group_lang

Product attribute group names.

id_attribute_group, id_lang

ps_attribute_impact

Product attribute price and weight impacts.

id_attribute_impact

ps_attribute_lang

Product attribute names.

id_attribute, id_lang

ps_carrier

Carriers.

id_carrier

ps_carrier_group

Carrier customer group restrictions.

id_carrier, id_group

ps_carrier_lang

Carrier transit time messages.

id_carrier

ps_carrier_zone

Zones each carrier is available

id_carrier, id_zone

ps_cart

Customer and guest carts.

id_cart

ps_cart_discount

Voucher codes used in carts.

id_cart, id_discount

ps_cart_product

Products in customer carts.

id_cart, id_product, id_product_attribute

ps_category

Product categories.

id_category

ps_category_group

Product category customer group restrictions.

id_category, id_group

ps_category_lang

Product category names and descriptions.

id_category, id_lang

ps_category_product

Products in each category.

id_category, id_product

ps_cms

CMS pages.

id_cms

ps_cms_block

CMS blocks.

id_cms_block

ps_cms_block_lang

CMS block names.

id_cms_block, id_lang

ps_cms_block_page

CMS block pages.

id_cms_block_page

ps_cms_category

CMS categories.

id_cms_category

ps_cms_category_lang

CMS category names.

id_cms_category, id_lang

ps_cms_lang

CMS page content.

id_cms, id_lang

ps_configuration

Configuration settings.

id_configuration

ps_configuration_lang

Configuration setting translations.

id_configuration, id_lang

ps_connections

Visitor IP addresses, referrers and pages visited.

id_connections

ps_connections_page

Start and end times of page visits.

id_connections, id_page, time_start

ps_connections_source

Visitor referrers and search engine keywords.

id_connections_source

ps_contact

Contact form subjects.

id_contact

ps_contact_lang

Contact form subject names.

id_contact, id_lang

ps_country

Countries.

id_country

ps_country_lang

Country names.

id_country, id_lang

ps_county

Counties

id_county

ps_county_zip_code

County zip codes.

id_county, from_zip_code, to_zip_code

ps_currency

Currencies.

id_currency

ps_customer

Customers.

id_customer

ps_customer_group

Customer groups.

id_customer, id_group

ps_customer_message

Customer messages through contact form.

id_customer_message

ps_customer_thread

Threads of messages through contact form.

id_customer_thread

ps_customization

Customised product data in cart.

id_customization, id_cart, id_product

ps_customization_field

Product customisation fields.

id_customization_field

ps_customization_field_lang

Product customisation field names.

id_customization_field, id_lang

ps_customized_data

Customised product data entered by customers.

id_customization, type, index

ps_date_range

Page view date ranges.

id_date_range

ps_delivery

Carrier delivery prices.

id_delivery

ps_discount

Vouchers.

id_discount

ps_discount_category

Voucher category restrictions.

id_category, id_discount

ps_discount_lang

Voucher descriptions.

id_discount, id_lang

ps_discount_type

Voucher types.

id_discount_type

ps_discount_type_lang

Voucher type names.

id_discount_type, id_lang

ps_editorial

Homepage logo links.

id_editorial

ps_editorial_lang

Homepage text.

id_editorial, id_lang

ps_employee

Back Office employees.

id_employee

ps_feature

Product features.

id_feature

ps_feature_lang

Product feature names.

id_feature, id_lang

ps_feature_product

Links feature values to products.

id_feature, id_product

ps_feature_value

Product feature values.

id_feature_value

ps_feature_value_lang

Product feature value names.

id_feature_value, id_lang

ps_group

Customer groups and reductions.

id_group

ps_group_lang

Customer group names.

id_group, id_lang

ps_group_reduction

Customer group category reductions.

id_group_reduction

ps_guest

Guests.

id_guest

ps_help_access

Viewed help articles and versions.

id_help_access

ps_hook

Module hook names and descriptions.

id_hook

ps_hook_module

Position of modules in each hook.

id_module, id_hook

ps_hook_module_exceptions

Page exceptions for each module.

id_hook_module_exceptions

ps_image

Product images.

id_image

ps_image_lang

Product image legends.

id_image, id_lang

ps_image_type

Product image thumbnail sizes.

id_image_type

ps_import_match

Saved CSV import configurations.

id_import_match

ps_lang

Languages.

id_lang

ps_log

Log of PHP errors and warnings.

id_log

ps_manufacturer

Manufacturers.

id_manufacturer

ps_manufacturer_lang

Manufacturer descriptions.

id_manufacturer, id_lang

ps_memcached_servers

Memcached servers.

id_memcached_server

ps_message

Order messages.

id_message

ps_message_readed

Order messages that have been marked as read.

id_message, id_employee

ps_meta

Page names.

id_meta

ps_meta_lang

Page meta information.

id_meta, id_lang

ps_module

Modules directories.

id_module

ps_module_country

Module country restrictions.

id_module, id_country

ps_module_currency

Module currency restrictions.

id_module, id_currency

ps_module_group

Module customer group restrictions.

id_module, id_group

ps_operating_system

Recognised operating systems.

id_operating_system

ps_orders

Orders.

id_order

ps_order_detail

Order products.

id_order_detail

ps_order_discount

Order vouchers.

id_order_discount

ps_order_history

Order status history.

id_order_history

ps_order_message

Predefined order messages.

id_order_message

ps_order_message_lang

Predefined order message names.

id_order_message, id_lang

ps_order_return

Merchandise returns.

id_order_return

ps_order_return_detail

Merchandise return products.

id_order_return, id_order_detail, id_customization

ps_order_return_state

Merchandise return statuses.

id_order_return_state

ps_order_return_state_lang

Merchandise return status names.

id_order_return_state, id_lang

ps_order_slip

Credit slips

id_order_slip

ps_order_slip_detail

Credit slip products.

id_order_slip, id_order_detail

ps_order_state

Order statuses.

id_order_state

ps_order_state_lang

Order status names.

id_order_state, id_lang

ps_pack

Product packs.

id_product_pack, id_product_item

ps_page

Pages.

id_page

ps_pagenotfound

Page not found data.

id_pagenotfound

ps_page_type

Page names.

id_page_type

ps_page_viewed

Viewed pages.

id_page, id_date_range

ps_payment_cc

Credit card information.

id_payment_cc

ps_product

Product information.

id_product

ps_product_attribute

Product attribute information.

id_product_attribute

ps_product_attribute_combination

Product attribute combinations.

id_attribute, id_product_attribute

ps_product_attribute_image

Product attribute images.

id_product_attribute, id_image

ps_product_country_tax

Product country taxes.

id_product, id_country, id_tax

ps_product_download

Downloadable products.

id_product_download

ps_product_group_reduction_cache

Product customer group reductions.

id_product, id_group

ps_product_lang

Product names and descriptions.

id_product, id_lang

ps_product_sale

Product sale data.

id_product

ps_product_tag

Product tags.

id_product, id_tag

ps_profile

Employee profile.

id_profile

ps_profile_lang

Employee profile name.

id_profile, id_lang

ps_quick_access

Back Office quick accesses.

id_quick_access

ps_quick_access_lang

Back Office quick access names.

id_quick_access, id_lang

ps_range_price

Carrier price ranges.

id_range_price

ps_range_weight

Carrier weight ranges.

id_range_weight

ps_referrer

Affiliate program accounts.

id_referrer

ps_referrer_cache

Affiliate program referrals.

id_connections_source, id_referrer

ps_required_field

Required fields.

id_required_field

ps_scene

Category page product banners.

id_scene

ps_scene_category

Links product banners to categories.

id_scene, id_category

ps_scene_lang

Category page product banner names.

id_scene, id_lang

ps_scene_products

Category page banner products.

id_scene, id_product, x_axis, y_axis

ps_search_engine

Recognised search engines.

id_search_engine

ps_search_index

PrestaShop search engine keyword index.

id_product, id_word

ps_search_word

PrestaShop search engine keywords.

id_word

ps_sekeyword

External search engine keywords.

id_sekeyword

ps_specific_price

Specific prices.

id_specific_price

ps_specific_price_priority

Specific price priorities.

id_specific_price_priority, id_product

ps_state

States.

id_state

ps_statssearch

PrestaShop search engine statistics.

id_statssearch

ps_stock_mvt

Stock movements.

id_stock_mvt

ps_stock_mvt_reason

Stock movement reasons.

id_stock_mvt_reason

ps_stock_mvt_reason_lang

Stock movement reason names.

id_stock_mvt_reason, id_lang

ps_store

Store addresses.

id_store

ps_subdomain

Cookie subdomains.

id_subdomain

ps_supplier

Suppliers.

id_supplier

ps_supplier_lang

Supplier names.

id_supplier, id_lang

ps_tab

Back Office tabs.

id_tab

ps_tab_lang

Back Office tab names.

id_tab, id_lang

ps_tag

Product tags used in tag cloud.

id_tag

ps_tax

Taxes.

id_tax

ps_tax_lang

Tax names.

id_tax, id_lang

ps_tax_rule

Tax rules.

id_tax_rule

ps_tax_rules_group

Tax rule names.

id_tax_rules_group

ps_timezone

Timezones.

id_timezone

ps_webservice_account

Webservice accounts.

id_webservice_account

ps_webservice_permission

Webservice permissions.

id_webservice_permission

ps_web_browser

Recognised web browsers

id_web_browser

ps_zone

Carrier zones.

id_zone

  • No labels