While we prepare some useful materials on Prestashop development we decided to present and explain the whole Prestashop inner workings in one graphical chart. The diagram describes the life of a request from the moment it gets into the system and till the controller starts working. We haven’t examined the process inside the controller as it’s not that important considering the context and the fact that different controllers operate on different logics. Here is what we have: (more…)
Today I will describe how push-notifications work in Prestаshоp. This article is written as a follow-up to this forum thread.
Default Prestashop features include the following functionalities: new orders, last registrations and open tickets. The module Gаmifiсаtiоn adds one more feature to this list.
There is the class “Notification” which can help to work with push-messages and which includes the following methods:
- __construct() – contains the initialization of default types of messages:
$this->types = array('order', 'customer_message', 'customer');
- getLastElements() – selects recent entries from the «employer» table: id_last_order, id_last_customer_message, id_last_customer
- getLastElementsIdsByType($type, $id_last_element) – returns all the element ids to show (order, customer registration, and customer message)
- updateEmployeeLastElement($type) – Updates the last seen element by the employee
These methods are invoked by аjаx-requests, which are initialized from the file js/notification.js
To better understand the work flow of push-notification, we should check the following files:
- adm/themes/default/template/header.tpl – includes html containers, whereto the data received via ajax is inserted
The module Gаmifiсаtiоn adds data by modifying html after the page is loaded, i.e. hooks to work with push-notification are not provided. The module uses just one hook: hookDisplayBackOfficeHeader. This hook is used only to connect the necessary js-files and libraries. So If you ever need to create your own custom push-notification, then you can use the files of the Gamification module as examples of best-practices.