Do you know how many users browse online stores on PC/laptops and which of them prefer (or have a free time) to visit stores from their smartphones? Store owners may feel lost and exhausted trying to figure out what gadgets are trendy in eCommerce now. Add-ons on Friday offer stylish themes with module functionality in on package that work both on PC and mobile devices.
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.