X-cart 5 Knowledge Base

This section contains all the collected knowledge the Guru has to offer on X-cart 5.

X-cart 5 – Building Modules for X-cart 5

The X-cart 5 software development toolkit can be found here:

Some Next-SDK command examples:

The Guru develops on the Windows platform, so all examples here on for use in a Windows environment. You can use the examples in unix environments, as well, but it is likely that you can drop a portion of the command. You don’t need to specify the path to PHP.

Create Module:
..\..\php\php.exe ../next-sdk/devkit/macros/create-module.php --module=Baby\RFQ --version=5.1

Load yaml file:
..\..\php\php.exe ../next-sdk-master/devkit/macros/load-yaml.php classes/XLite/Module/XUSA/ModuleName/install.yaml

Create Customer Page:
..\..\php\php.exe ../next-sdk/devkit/macros/create-page.php --module=Tony\News --target=news --interface=customer

Create admin page:
../../next-sdk/devkit/macros/create-page.php --module=Tony\News --target=news_edit --interface=admin

Create admin page with menu entry:
..\..\php\php.exe ../next-sdk/devkit/macros/create-page.php --module=Tony\\News --target=news --interface=admin --menu=content

Validating your module:

First download and install PHP Codesniffer: https://github.com/squizlabs/PHP_CodeSniffer

Use codesniffer on your new module:
phpcs --standard=PSR2 path/to/your/files

Dumping your database:

You can dump your database from the command line easily. This technique works well for those with shell access to their server, or for those working on a local machine. Not an X-cart 5 specific tip, this will work for any MySQL database that you want to dump.

To dump the DB (export to a sql file):
mysqldump -u [your_username] -p[your_password] [database_name] > myDumpFile.sql

In some instances with certain passwords containing special characters, you need to enclose the password in single quotes -p’password’

Restoring an sql file:
mysql -u [your_username] -p[your_password] [database_name] < myDumpFile.sql

The greater than > and less than < symbols act as direction indicators. Point them in the direction you want the data to flow.

What if I can’t get shell access?
Never fear, PHP is here! Just create a PHP file with the following:

exec('mysqldump -u username -ppassword databasename > dumpfile.sql', $output, $return);
if (!$return) {
    echo "Finished!";
} else {
    echo "Got error code: " . $return;

OOPS! I broke something

When X-cart 5 breaks, it usually happens while rebuilding cache, and it is usually due to some malfunctioning code in your module. So what do you do when the rebuild has started and had an error? You fixed your code, but now you can’t access the admin to re-deploy the store. No problem.

Remove the directory:
{Your X-Cart Dir}/var/run
Just delete it completely. Also check for a file in the var directory .rebuildstarted and delete it as well. Try visiting {Your X-Cart Dir}/admin.php in your browser and the rebuild should begin automatically.

Installing WordPress in a subdirectory

Often you want to have X-Cart 5 installed in the root of your domain, then you want to install WordPress or another application in a subdirectory such as /blog. The challenge is that X-Cart in the root has rewrite rules located in the main .htaccess which will prevent that folder from loading and redirect the visitor to a 404 page instead.

Thankfully the fix is extremely simple. Open up the .htaccess file and change the directory index line near the top to read:

DirectoryIndex cart.php index.php

This way Apache will first look for a cart.php then an index.php if not found. And X-Cart will stop redirecting to the 404 and allow WordPress to be reached.

Force HTTPS on All Pages

X-cart 5 has a feature that can enable HTTPS for the store backend, checkout, sign-in and profile pages – assuming you have a valid SSL certificate. Many sites are moving to HTTPS everywhere for very good reasons. The performance hit is not so much of an issue now if you can employ HTTP/2 or SPDY.

Perhaps X-cart should consider this as a configurable option for a later release.

Setting up Apache or Nginx rewrite rules can achieve this.

But as an alternative, if anyone finds this useful, I created a tiny module with just one file in addition to main.php. NB. replace <modowner>, <modname> as you wish..


  * Force HTTPS everywhere

namespace XLite\Module\\\Controller;

class AController extends \XLite\Controller\AController implements \XLite\Base\IDecorator
      * force https
      * @return boolean
      public function isSecure()
          return true;

From Andrew – Xcart Forum

Need help? Contact the Guru!