Blog Posts

How to create module in X-Cart 5

How to create module in X-Cart 5

How to create module in X-Cart 5

This article will help you to create a module in X-Cart 5.

Why choose X‑Cart?
Easy to use, easy to maintain, easy to modify E-commerce shopping cart (X-Cart), is an ideal platform for businesses looking forward to taking their products and services online. It allows users to securely sell their products and services from their own servers.

Before starting module you need to choose two identifiers.
1) Developer ID
2) Module ID

Developer ID – Tell other programmers that this module is written by you. This is just like your name as a developer in the X-Cart repository of modules.
Module ID – This is the name of your module.
Note: The identifiers must begin with an uppercase letter and may consist of a maximum of 64 alphanumeric characters.

Steps to create Module:

1) Create classes/XLite/Module/// directory inside your installation. Use your own developer and module IDs instead of the ones mentioned in the path.
2) Create Main.php file inside classes/XLite/Module/// folder with the following content:

<?php
namespace XLite\Module\<YOUR-DEVELOPER-ID>\<YOUR-MODULE-ID>;

abstract class Main extends \XLite\Module\AModule
{
    /**
     * Author name
     *
     * @return string
     */
    public static function getAuthorName()
    {
        return 'Your name';
    }

    /**
     * Module name
     *
     * @return string
     */
    public static function getModuleName()
    {
        return 'Your module name';
    }

    /**
     * Get module major version
     *
     * @return string
     */
    public static function getMajorVersion()
    {
        return '5.3';
    }

    /**
     * Module version
     *
     * @return string
     */
    public static function getMinorVersion()
    {
        return 0;
    }

    /**
     * Module description
     *
     * @return string
     */
    public static function getDescription()
    {
        return 'Your module description';
    }
}

Change the namespace section in this file and replace placeholders with your actual developer and module IDs.

3) Define the getDescription(), getModuleName(), getAuthorName() methods so that they would return your own module description, module name and module author.

4) Re-deploy your store via the admin area of your X-Cart:

 

Or just remove /var/run directory and refresh the page.

5) After the re-deployment process is over, your module will show up among the installed modules in your store’s admin area.

However, this module is not activated yet and you need to enable it to make it start working.

Found the article useful? Share it with your friends and co-workers… Now!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.