User Tools

  • (Use the same account as the official website)

Site Tools


how_to_create_an_order_module

How To Create an Order Module

Order modules can interact with orders and support several different behaviors.

This is an overview of an order module:

includes/modules/order/om_my_order_module.inc.php
<?php
  class om_my_order_module {
    public $id = __CLASS__;
    public $name = 'My Order Module';
    public $description = 'Order module that does something with order data';
    public $version = '1.0';
    public $author = 'ACME Corp.';
    public $website = 'http://www.litecart.net';
 
    public function actions() {}
 
    public function validate($order) {}
 
    public function update($order) {}
 
    public function before_process($order) {}
 
    public function after_process($order) {}
 
    public function success($order) {}
 
    function settings() {
      return array(
        array(
          'key' => 'status',
          'default_value' => '1',
          'title' => 'Status',
          'description' => 'Enables or disables the module.',
          'function' => 'toggle("e/d")',
        ),
        array(
          'key' => 'priority',
          'default_value' => '0',
          'title' => 'Priority',
          'description' => 'Process this module by the given priority value.',
          'function' => 'number()',
        ),
      );
    }
 
    public function install() {}
 
    public function uninstall() {}
  }

actions()

The action() method can return a set of action buttons on the orders page that triggers certain methods upon click. Simply select orders from the list and click an action button.

    public function actions() {
 
      if (empty($this->settings['status'])) return;
 
      return array(
        'id' => __CLASS__,
        'name' => 'My Actions',
        'description' => 'Click any button to perform an action',
        'actions' => array(
          array(
            'id' => 'firstbutton',
            'title' => 'My Button Text',
            'description' => 'Click this button to do something',
            'function' => 'my_fancy_method',
          ),
          // Action 2
          // Action 3
          // ...
        ),
      );
    }
 
    public function my_fancy_method($order_ids) {
 
      foreach($order_ids as $order_id) {
        $order = new ent_order($order_id);
        // Custom code to do whatever
      }
    }
 

validate()

The validate method() is called during checkout during validations before the order is processed. An error message returned will prevent the customer from being able to checkout.

    public function validate($order) {
      return ['error' => 'This order is no good'];
    }

before_process()

The before_process() method is called during checkout before saving the order to database.

    public function before_process($order) {
      // Do something ...
    }

after_process()

The after_process() method is called during checkout after the order is saved to database.

    public function after_process($order) {
      // Do something ...
    }

update()

The update() is an event that is called every time an order is saved.

    public function update($order) {
      // Do something
    }

success()

The success() method can output HTML on the order success page e.g. a sales tracker pixel or a receipt.

    public function success($order) {
      return '<script>...</script>';
    }
how_to_create_an_order_module.txt · Last modified: 2022/09/19 21:46 by tim