Child pages
  • Creating a Dashboard Module

Versions Compared

Key

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

Table of contents

Table of Contents

Creating a Dashboard Module

...

Indeed, you can create your own dashboard modules, which you can make available for all to download or buy on PrestaShop Addons.

...

Differences with a regular PrestaShop module

A PrestaShop dashboard module is essentially the same thing as a regular PrestaShop module, with a few specifics.

...

It is located in the /modules folder

...

, and it can make use of PrestaShop's

...

controllers, just like any module does.

The specifics

The name

Your Dashboard dashboard module must have a unique name. As a convention, dashboard modules should all use the "dash" prefix: "dashproduct", "dashactivity", "dashgoals" are the names of some of the default dashboard modules

...

  • $this->push_filename: the directory where your push data should be stored.
  • $this->allow_push: a boolean indicating whether your module should have data be pushed to it. or not.
  • $this->push_time_limit: the numbers of seconds between two data pushes.

...

Code Block
languagephp
public function __construct()
{
	$this->name = 'dashactivity';
	$this->displayName = 'Dashboard Activity';
	$this->tab = '';
	$this->version = '0.1';
	$this->author = 'PrestaShop';
	$this->push_filename = _PS_CACHE_DIR_.'push/activity';
	$this->allow_push = true;
	$this->push_time_limit = 180;

	parent::__construct();
}

Note that the tab variable is empty. It is not needed as of today, but might be in future versions of PrestaShop.

...

As for any PrestaShop module, the main PHP file must contain a install() method, which declares the usual hooks, such as displayBackOfficeHeader.

PrestaShop 1.6 implements several new hooks dedicated to dashboard modules:

...

Note

The right column of the dashboard is not available for module.

The user cannot move a module from one column to the other, so you shouldn't hook your module to both zones unless necessary.

Each hook must call on a template file in order to display your content.

...

There are 4 data types that the Dashactivity your module usescan use:

  • Value: a single value, which can have any data type (string, number, boolean, etc.)
  • Trends: a specific type, available as an array two values:
    • 'way': either 'up' or 'down', depending on the trend
    • 'value': the difference between the past and current value.
  • List Small: an array of values.
  • Chart: an array of two values:
    • 'chart_type': the type of chart to be used (ie.: 'pie_chart_trends').
    • 'data': an array of arrays:
      • key: the data key.
      • y: the data value.

...

In addition to the default ones, you can create your own data type! For instance, you could feel the need for a slider Slider data type, or a clear boolean. You return code would therefore be:

...

The default data types have their data loaded and placed by specific JavaScript functions. In order for the data of your custom data types to still be loaded and correctly placed, you must add your own JavaScript function, which will be is called automatically when hookDashboardData() send its JSON back.

That JavaScript function should be in your own .js file, which you should add to the theme's header using the $this->context->controller->addjs('js/mymethods.js', 'all'); method.

...

To get an example of such JavaScript methods, check the ones for data_value, data_trends and the other default data type in the file https://github.com/PrestaShop/PrestaShop/blob/e71094283395b092ccd0b0a0bb0a0fdfe25cbabc/js/admin-dashboard.js#L112.

...

To declare the configuration form, you simply have to:

  1. Declare the PHP function that will render this form.
  2. Assign that function to a Smarty tag.
  3. Call that Smarty tag in the template.

Here is how the Dashactivity module does it.

...