How To Create A Customer Module

Título

Sem alterações

Link permanente

Sem alterações

Conteúdo

OldNew
1# How to Create a Customer Module1# How to Create a Customer Module
22
3## Get Address3## Get Address
44
5Prefill some or all fields in the checkout based on a updated field5Prefill some or all fields in the checkout based on a updated field trigger.
6trigger.6
77```php ~/includes/modules/customer/cm_get_address.inc.php
8```php ~/includes/modules/customer/cm_get_address.inc.php8<?php
9
10 class cm_get_address {
11 public $id = __CLASS__;
12 public $name = 'Get Address Module';
13 public $description = '';
14 public $author = 'ACME Corp.';
15 public $version = '1.0';
16 public $website = 'https://www.acme.com';
17 public $priority = 0;
18
19 // Return an address based on data collected. Trigger indicates the last filled input field
20 public function get_address($data) {
21
22 if (empty($this->settings['status'])) return;
23
24 if (!isset($data['trigger']) || ($data['trigger'] != 'tax_id')) return;
25
26 // Do something so we can return some data
27 // ...
28
29 return array(
30 'firstname' => '',
31 'lastname' => '',
32 'company' => '',
33 'address1' => '',
34 'address2' => '',
35 'postcode' => '',
36 'city' => '',
37 'country_code' => '',
38 'zone_code' => '',
39 );
40 }
41
42 // Validate (or update) customer details
43 public function validate(&$data) {
44
45 if (empty($this->settings['status'])) return;
46
47 // Rewrite
48 $data['email'] = strtolower($data['email']);
49
50 // Validate some data and return an error
51 //if (something == bad) {
52 // return array('error' => 'Your data is not valid');
53 //}
54
55 return true;
56 }
57
58 function settings() {
59
60 return [
61 [
62 'key' => 'status',
63 'default_value' => '1',
64 'title' => language::translate(__CLASS__.':title_status', 'Status'),
65 'description' => language::translate(__CLASS__.':description_status', 'Enables or disables the module.'),
66 'function' => 'toggle("e/d")',
67 ],
68 [
69 'key' => 'priority',
70 'default_value' => '0',
71 'title' => language::translate(__CLASS__.':title_priority', 'Priority'),
72 'description' => language::translate(__CLASS__.':description_priority', 'Process this module in the given priority order.'),
73 'function' => 'number()',
74 ],
75 ];
76 }
77
78 public function install() {}
79
80 public function uninstall() {}
81 }
82```

Editado por tim em 28 dez. 2023 às 11:47

Veja o código no GitHub