Loading...

Notifications

We no longer maintain the Knowledge Base since version 4.3.x. All the latest user and developer documentation for 4.3.x and newer versions is now available at docs.cs-cart.com.

  • This article applies to CS-Cart versions:
  • 3.0.x

Notifications

Notifications in CS-Cart 2.0 are represented as pop-up rectangular areas in the top right corner of the screen.

There are three standard types of notifications:

  1. Notification(code type 'N')
  2. Error(code type 'E')
  3. Warning(code type 'W')

Each notification type has its color: notification – green, error – red, warning – orange. Visual format is defined in CSS file of that area where the notification is called.

Notification is created through the function fn_set_notification (/core/fn.common.php).

An empty container is added to HTML code of each program page. A notification block is displayed in this container if the notification is set. Container is created in the following template:

/[zone_name]/common_templates/notification.tpl

Ways to set a notification

There are two ways to set a notification:

  1. By standard execution of a script, prior to display of a page.
  2. With AJAX request, after a page is displayed and in a certain event.

The first way is used to create a notification that is to be displayed when a page is loaded. The second one is necessary to display a notification without a page reload on some event in the program.

Let's consider the process of notification creation in the first way:

1. The setting function is called in the controller code, for instance:

1
2
3
if ($mode == 'add_to_cart') {
    fn_set_notification('E', fn_get_lang_var('warning'), $msg, true, 'insecure_password'); 
}

 

This function adds a new element to the notification array.

2. Templater processes the template /[zone_name]/common_templates/notification.tpl and through the function fn_get_notifications passes a list of all notifications for display to the array search function foreach.

3. If the notification array is not empty, then HTML code of the notification itself is displayed.

 

The second way (AJAX):

1. When displaying a page the templater processes the template /[zone_name]/common_templates/notification.tpl and creates a container for notifications (<div class="cm-notification-container">). This container is either empty or contains notifications set in the first way.

2. The setting function is called in the controller code executed on AJAX request, for example:

1
2
3
if (defined('AJAX_REQUEST')) {
    fn_set_notification('E', fn_get_lang_var('warning'), $msg, true, 'insecure_password'); 
}

 

This function adds a new element to the notification array.

3. When script execution is completed or when the termination function exit() is called explicitly, invocation of the destructor of Ajax class (/core/class.ajax.php) takes place. The destructor passes the notification information to an array with data in JSON format and then passes this array to the JS function ajaxResponse(/js/ajax.js).

4. The function ajaxResponse in turn calls the function showNotification(/js/core.js) and passes the array with all defined AJAX notifications to it. Display of the notification occurs in the showNotification function by the notification.append method, which adds HTML code of the notification to a container of the declared template /[zone_name]/common_templates/notification.tpl(<div class="cm-notification-container">)

 

<< Read previous Read next >>
Home / Docs / General Methodology / Notifications