How To Create An Order Module

Başlık

No changes

Permalink

No changes

İçerik

OldNew
1# How To Create an Order Module1# How To Create an Order Module
22
3Order modules can interact with orders and support several different3Order modules can interact with orders and support several different behaviors.
4behaviors.4
55This is an overview of an order module:
6This is an overview of an order module:6
77```php includes/modules/order/om_my_order_module.inc.php
8```php includes/modules/order/om_my_order_module.inc.php8<?php
9
10 class om_my_order_module {
11 public $id = __CLASS__;
12 public $name = 'My Order Module';
13 public $description = 'Order module that does something with order data';
14 public $version = '1.0';
15 public $author = 'ACME Corp.';
16 public $website = 'http://www.litecart.net';
17
18 public function actions() {}
19
20 public function validate($order) {}
21
22 public function update($order) {}
23
24 public function after_process($order) {}
25
26 public function success($order) {}
27
28 function settings() {
29 return [
30 [
31 'key' => 'status',
32 'default_value' => '1',
33 'title' => 'Status',
34 'description' => 'Enables or disables the module.',
35 'function' => 'toggle("e/d")',
36 ],
37 [
38 'key' => 'priority',
39 'default_value' => '0',
40 'title' => 'Priority',
41 'description' => 'Process this module by the given priority value.',
42 'function' => 'number()',
43 ],
44 ];
45 }
46
47 public function install() {}
48
49 public function uninstall() {}
50 }
51```
52
53## actions()
54
55The 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.
56
57```php
58 public function actions() {
59
60 if (empty($this->settings['status'])) return;
61
62 return [
63 'id' => __CLASS__,
64 'name' => 'My Actions',
65 'description' => 'Click any button to perform an action',
66 'actions' => [
67 [
68 'id' => 'firstbutton',
69 'title' => 'My Button Text',
70 'description' => 'Click this button to do something',
71 'function' => 'my_fancy_method',
72 ],
73 // Action 2
74 // Action 3
75 // ...
76 ],
77 ];
78 }
79
80 public function my_fancy_method($order_ids) {
81
82 foreach($order_ids as $order_id) {
83 $order = new ent_order($order_id);
84 // Custom code to do whatever
85 }
86 }
87```
88
89## validate()
90
91The 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.
92
93```php
94 public function validate($order) {
95 return ['error' => 'This order is no good'];
96 }
97```
98
99## after_process()
100
101The after_process() method is called during checkout after the order is saved to database.
102
103```php
104 public function after_process($order) {
105 // Do something ...
106 }
107```
108
109## success()
110
111The success() method can output HTML on the order success page e.g. a sales tracker pixel or a receipt.
112
113```php
114 public function success($order) {
115 return '<script>...</script>';
116 }
117```

Edited by tim on 28 Ara 2023 at 11:49