CubeCart’s hooks system lets you add custom functionality without modifying core files. This means your customisations survive upgrades and can be easily distributed to other store owners.

How Hooks Work

CubeCart’s core code contains “hook points” — named locations where external plugin code can be injected. When CubeCart reaches a hook point during execution, it loads and runs any plugin code registered for that hook.

This is the foundation of CubeCart’s plugin architecture and the recommended way to customise your store.

Plugin Directory Structure

Plugins live in modules/plugins/. Here’s the standard structure:

modules/plugins/my_plugin/
  config.xml                    — Plugin metadata
  language/
    module.definitions.xml      — Language strings (English)
  admin/
    index.inc.php               — Admin controller
    logo.png                    — Plugin icon (shown in Extensions list)
  hooks/
    class.cubecart.construct.php  — Hook file (named after the hook point)
  skin/
    admin/
      index.tpl                 — Admin template

Step 1: Create config.xml

This file defines your plugin’s metadata:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <uid>[email protected]</uid>
  <type>plugins</type>
  <folder>my_plugin</folder>
  <name>My Plugin</name>
  <description>A short description of what the plugin does.</description>
  <version>1.0.0</version>
  <minVersion>6.0.0</minVersion>
  <creator>Your Name</creator>
  <homepage>https://www.example.com</homepage>
</config>
Field Description
uid Unique identifier for the module (email format)
type Must be plugins (other types: gateway, shipping, social)
folder Must exactly match the plugin’s folder name (case-sensitive)
minVersion Minimum CubeCart version required

Step 2: Create Language Strings

Create language/module.definitions.xml:

<?xml version="1.0" encoding="UTF-8"?>
<definitions version="1.0">
  <definition>
    <key>my_plugin_title</key>
    <value>My Plugin</value>
  </definition>
  <definition>
    <key>my_plugin_enabled</key>
    <value>Enable Plugin</value>
  </definition>
</definitions>

See our multilingual plugin guide for adding translations.

Step 3: Create the Admin Interface

The admin controller (admin/index.inc.php) loads your plugin’s configuration and template. CubeCart provides a standard admin controller that works for most plugins — it handles loading settings and saving form data automatically.

The admin template (skin/admin/index.tpl) defines the configuration form shown in the Extensions area. Use Smarty syntax and CubeCart’s standard form elements.

Step 4: Create Hook Files

This is where the real power lies. Hook files go in the hooks/ directory, named after the hook point they target.

For example, to run code when CubeCart initialises, create hooks/class.cubecart.construct.php:

<?php
// This code runs when CubeCart initialises

// Get your plugin's settings
$my_settings = $GLOBALS['config']->get('my_plugin');

if ($my_settings['enabled']) {
    // Your custom logic here

    // Assign data to templates
    $GLOBALS['smarty']->assign('MY_DATA', $myValue);
}

Common Hook Points

Hook Name When It Runs
class.cubecart.construct CubeCart initialisation (every page load)
class.cubecart.cart Cart/basket page
class.cubecart.order_success After successful order completion
class.catalogue.product Product detail page
class.catalogue.category Category listing page
class.gui.display Page rendering (before output)
admin.order.index Admin order management page
admin.product.save When a product is saved in admin

To find all available hook points, search the CubeCart source code for $GLOBALS['hooks']->load(.

Working with the Database

Plugins can create custom database tables. In your admin controller, check if your table exists and create it if not:

$GLOBALS['db']->query("CREATE TABLE IF NOT EXISTS CubeCart_my_plugin (
    id INT AUTO_INCREMENT PRIMARY KEY,
    data VARCHAR(255),
    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");

Query your tables with:

$results = $GLOBALS['db']->select('CubeCart_my_plugin', false, array('id' => 1));
$GLOBALS['db']->insert('CubeCart_my_plugin', array('data' => 'value'));

Using Templates

Assign variables in your hook and display them in your skin templates:

// In your hook file:
$GLOBALS['smarty']->assign('MY_COUNTER', $count);

// In your skin template (e.g. skins/foundation/templates/main.html):
// {$MY_COUNTER}

Installing Your Plugin

  1. Upload the plugin folder to modules/plugins/.
  2. In admin, go to Extensions > Plugins.
  3. Find your plugin and click Enable.
  4. Configure settings as needed.

Best Practices

  • Always use hooks instead of modifying core files.
  • Namespace your database tables and Smarty variables to avoid conflicts.
  • Include a config.xml with accurate version requirements.
  • Test your plugin after CubeCart upgrades.
  • Use the $GLOBALS['config'] system to store plugin settings.