MODULE_HEADER_TAGS_NOSCRIPT_TEXT
Login | Create an account | Contact us
  • english French
  • Author :
    A module is a small program that will display information to a specific location on the site. In the market place, you'll find all the modules allowing you to display a specific variable. This tutorial aims to help you create a new module through an example. Depending on your needs, you can use the database to javascript or not.

    Here is an example of building a module on the product description which is inserted in the product description page.


     


    Step  1  : The module


    This one is going to find in the / sources / template / montemplate / modules / products_info / 

    A careful 

    The name of your module is found in the following

    intitulé pi_products_info_description.php

       class pi_products_info_description;
       var $code = 'pi_products_info_description';
        function pi_products_info_description() {

    The variables that will be stored in the database or language file type will MODULE_PRODUCTS_INFO_DESCRIPTION which includes part of the directory name.

    Please note that all variables take the name of the module and must be capitalized. 
    For example, I need to create a module in the new special directory (modules_products_specials).
    The name of my file so called ps.products_specials.php therefore the variable or affiliated variables all begin with MODULE_PRODUCTS_SPECIAL_SuiteNomDeLaVariable (which shows the hard name directory module part)

    In case you make a mistake, it will be much easier to find all the same variables related itemps module in the database. 

    Here below is an example module commented.
     
    /**
     * pi_products_info_description.php 
     * @copyright Copyright 2008 - http://www.e-imaginis.com
     * @copyright Portions Copyright 2003 osCommerce
     * @license Licensed under GPL and MIT
     * @version $Id:  
     */

      class pi_products_info_description {
        var $code = 'pi_products_info_description';
        var $group = 'modules_products_info';
        var $title;
        var $description;
        var $sort_order;
        var $enabled = false;


        function pi_products_info_description() {
             
          $this->title = MODULE_PRODUCTS_INFO_DESCRIPTION;
          $this->description = MODULE_PRODUCTS_INFO_DESCRIPTION_DESCRIPTION;

          if (defined('MODULE_PRODUCTS_INFO_DESCRIPTION_STATUS')) {
            $this->sort_order = MODULE_PRODUCTS_INFO_DESCRIPTION_SORT_ORDER;
            $this->enabled = (MODULE_PRODUCTS_INFO_DESCRIPTION_STATUS == 'True');
          }
        }

        function execute() {
          global $OSCOM_Template, $OSCOM_PDO, $PHP_SELF;

          if ($PHP_SELF == FILENAME_PRODUCT_INFO) {

            $products_description = osc_products_info_description();
    // -----------------------------------------------------------------------------------
    //  Content that will be displayed in the template: Party change
    // -----------------------------------------------------------------------------------
            $products_description_content = '' . "\n";
            $products_description_content .= '
     
    ';          
            $products_description_content .= '
    ';
            $products_description_content .= '
    ';   
            $products_description_content .= ''  . $products_description .''; 
            $products_description_content .= '
    '; 
            $products_description_content .= '
    ' . "\n"; 
            $products_description_content .= '' . "\n";

            $OSCOM_Template->addBlock($products_description_content, $this->group);

          } // php_self
        } // function execute

    // -----------------------------------------------------------------------------------
    // Audit Module activation
    // -----------------------------------------------------------------------------------
        function isEnabled() {
          return $this->enabled;
        }

        function check() {
          return defined('MODULE_PRODUCTS_INFO_DESCRIPTION_STATUS');
        }
    // -----------------------------------------------------------------------------------
    // Installing the database management module
    // -----------------------------------------------------------------------------------
        function install() {
          osc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Souhaitez-vous afficher une description du produit dans la page de description ?', 'MODULE_PRODUCTS_INFO_DESCRIPTION_STATUS', 'True', 'Affiche une description du produit dans la page de description', '6', '1', 'osc_cfg_select_option(array(\'True\', \'False\'), ', now())");
          osc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('A quel endroit souhaitez-vous afficher les descriptions ?', 'MODULE_PRODUCTS_INFO_DESCRIPTION_POSITION', 'none', 'Affiche la description du produit a  gauche ou a  droite

    (Valeur Left = Gauche
    Valeur Right = Droite
    Valeur None = Aucun)
    ', '6', '2', 'osc_cfg_select_option(array(\'right\', \'left\', \'none\'), ', now())");
          osc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Ordre de tri d\'affichage', 'MODULE_PRODUCTS_INFO_DESCRIPTION_SORT_ORDER', '40', 'Ordre de tri pour l\'affichage (Le plus petit nombre est montré en premier).', '6', '3', now())");
          osc_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '1' where configuration_key = 'WEBSITE_MODULE_INSTALLED'");
        }
    // -----------------------------------------------------------------------------------
    // Removal of the database management module
    // -----------------------------------------------------------------------------------
        function remove() {
          osc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
        }

        function keys() {
          return array (
            'MODULE_PRODUCTS_INFO_DESCRIPTION_STATUS',
            'MODULE_PRODUCTS_INFO_DESCRIPTION_POSITION',
            'MODULE_PRODUCTS_INFO_DESCRIPTION_SORT_ORDER'
          );
        }
      }
    ?>
     
     
     

    Etape 2 :  le template d'affichage


    In the directory : sources/template/bootrstrap/products_info/content
    Create a fiche containing this name  : products_description.php
    Inside, there will variables containing the template
     
     
     
     

       
     


    Step 3 :  the language 


    In the directory of my template: sources / template / bootrstrap / languages ​​/ english / modules_products_info 
    Create a file containing the same name as the module: pi.products_description.php 
    Inside there will variables defining the language 
    This module is to reproduce for each language.
     
    /**
     * pi_products_info_dimension.php 
     * @copyright Copyright 2008 - http://www.e-imaginis.com
     * @copyright Portions Copyright 2003 osCommerce
     * @license GNU Public License V2.0
     * @version $Id:  
     */
      define('MODULE_PRODUCTS_INFO_DESCRIPTION', 'Do you want display the product description ?');
      define('MODULE_PRODUCTS_INFO_DESCRIPTION_DESCRIPTION', 'Displays the size of the product in the product description page');
    ?>
     

    Note : if you have to create new functions or classes then we invite you to create in the module directory.
     
     

    Step 4 : css creation


    To allow presentation of the module and bring him such as colors, positioning .... this happens at the css. 

    The example shown above, we have a css class like: class = "Product Description" 

    So to assign a color code, create a css in / sources / template / Bootstrap / graphism / english / css / moules_products_info / pi.products_description.css 
    pi.products_description.php is the file name

    Note : Some module provides simple positioning (including modules parge description of the products: modules_products_info). In the case, or the basic options are not satisfactory, the css can solve a number of problems. It will be necessary at times to change in the module in order to make small changes.

    It will put the following code
     
    div.productDescription, span.productDescription  h3{
      color: #000000;
      font-size: 12px;
      padding-bottom: 5px;
    }

    This element is to reproduce for all languages​​.

    Note : need to compress the code, this is done automatically cached by compressed_css.php located in the french directory graphism.
     


    Etape 5 : Compression le zip pour téléchargement


    To use the system module installation you must create a zip containing the following elements:

    This procedure applies to the level of implementation of a module for a template

    Please note that if you have several template, it will copy the module in every templates
     

    ====> Download the module



    Level CSS:
    Create directories containing the elements as follows
     
    graphism
    ------> french
    ----------->css
    --------------> Module directory + file (with index.php (redirect to home page) or index.html (redirect to home page).
    ------------------->module file :  pi_products_info_description.php
    -----> english
    ----------->css
    ​--------------> Module directory + file (with index.php (redirect to home page) or index.html (redirect to home page). 
    ------------------->module file : : pi_products_info_description.php
     
    Level language :
    Create directories containing the elements as follows
     
    languages
    ------> french
    ---------->modules
    -------------->Module directory :  ici module_products_info
    ------------------->module file : pi_products_info_description.php
    -----> english
    ---------->modules
    -------------->Module directory : ici module_products_info
    ------------------->module file : pi_products_info_description.php

    Au niveau du modules :
    Create directories containing the elements as follows
     
    modules
    ------>Module directory :  module_products_info
    -------------->module file  :  pi_products_info_description.php
    ----------> template directory : content
    --------------> templatefile : products_description.php

    Compression

    Compress the 3 directories, graphism, languages, modules in zip format


    Cette procédure s'applique au niveau de la mise en place d'un module fixe. Il s'applique a  tous les template


    Au niveau de la langue :
    Create directories containing the elements as follows
     
    languages
    ------> french
    ---------->modules
    --------------> Module directory
    ------------------->module file 
    -----> english
    ---------->modules
    --------------> Module directory
    ------------------->module file 

    Au niveau du modules :
    Create directories containing the elements as follows
     
    modules
    ------> Module directory
    --------------> module file 

    Compression

    Compress the 2 directories, languages, modules in zip format

     
     

    Etape 6 : Module  install


    To install a module, simply go into administration tool section / module installation and follow the steps that are available.
     

     

     

     

    Step 7 : Activation Module


    To activate the module, simply visit the administraiton Design / Sheet Description of Products / View modules 
    A list of modules is displayed, click on the Install button (green) to activate the module. Just by following the edit to see options related to the module.