How to Create a Customer Module
Get Address
Prefill some or all fields in the checkout based on a updated field trigger.
~/includes/modules/customer/cm_get_address.inc.php:
<?php
class cm_get_address {
public $id = __CLASS__;
public $name = 'Get Address Module';
public $description = '';
public $author = 'ACME Corp.';
public $version = '1.0';
public $website = 'https://www.acme.com';
public $priority = 0;
// Return an address based on data collected. Trigger indicates the last filled input field
public function get_address($data) {
if (empty($this->settings['status'])) return;
if (!isset($data['trigger']) || ($data['trigger'] != 'tax_id')) return;
// Do something so we can return some data
// ...
return array(
'firstname' => '',
'lastname' => '',
'company' => '',
'address1' => '',
'address2' => '',
'postcode' => '',
'city' => '',
'country_code' => '',
'zone_code' => '',
);
}
// Validate (or update) customer details
public function validate(&$data) {
if (empty($this->settings['status'])) return;
// Rewrite
$data['email'] = strtolower($data['email']);
// Validate some data and return an error
//if (something == bad) {
// return array('error' => 'Your data is not valid');
//}
return true;
}
function settings() {
return [
[
'key' => 'status',
'default_value' => '1',
'title' => language::translate(__CLASS__.':title_status', 'Status'),
'description' => language::translate(__CLASS__.':description_status', 'Enables or disables the module.'),
'function' => 'toggle("e/d")',
],
[
'key' => 'priority',
'default_value' => '0',
'title' => language::translate(__CLASS__.':title_priority', 'Priority'),
'description' => language::translate(__CLASS__.':description_priority', 'Process this module in the given priority order.'),
'function' => 'number()',
],
];
}
public function install() {}
public function uninstall() {}
}
Revisions
Top Editors
Recently Edited Articles