Prefill some or all fields in the checkout based on a updated field trigger.
<?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 = 'http://www.acme.com'; public $priority = 0; 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' => '', ); } 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; } public function update($data) { if (empty($this->settings['status'])) return; // The customer profile was saved. Do something with the saved data. // ... } function settings() { return array( array( '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")', ), array( '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' => 'int()', ), ); } public function install() {} public function uninstall() {} } ?>
Run some operations after a customer account is created or updated. In this example adding/removing a customer from an external newsletter service.
<?php class cm_newsletter_service { public $id = __CLASS__; public $name = 'Newsletter Service Module'; public $description = ''; public $author = 'ACME Corp.'; public $version = '1.0'; public $website = 'http://www.acme.com'; public $priority = 0; public function update($data) { if (empty($this->settings['status'])) return; if (!empty($data['newsletter'])) { // Subscribe user to newsletter // ... } else { // Unsubscribe user to newsletter // ... } } function settings() { return array( array( '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")', ), array( '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' => 'int()', ), ); } public function install() {} public function uninstall() {} } ?>