|
| 1 | +--- |
| 2 | +title: Base Module Support |
| 3 | +description: |
| 4 | +weight: 10 |
| 5 | +layout: docs |
| 6 | +--- |
| 7 | + |
| 8 | +{{% alert title="Warning" color="warning" %}} |
| 9 | +The documentation in this section is Work in progress and relates to features that might not be available yet. |
| 10 | +{{% /alert %}} |
| 11 | + |
| 12 | +# Introduction |
| 13 | + |
| 14 | +The base module support classes contain common code that is used across all module types e.g Payments, Shipping and Order Total modules. |
| 15 | + |
| 16 | +It also provides some common helper methods that you can use in you modules. |
| 17 | + |
| 18 | +## Accessing Define Values |
| 19 | + |
| 20 | +All module types store information about themselves in the database `configuration` table. |
| 21 | + |
| 22 | +The `keys` for this table will look something like |
| 23 | + |
| 24 | +- MODULE_PAYMENT_COD_STATUS |
| 25 | +- MODULE_SHIPPING_FLAT_COST |
| 26 | +- MODULE_ORDERTOTAL_TOTAL_SORT_ORDER |
| 27 | + |
| 28 | +The structure of these defines is |
| 29 | + |
| 30 | +MODULE_[module type]\_[module name]\_[define name] |
| 31 | + |
| 32 | +where module type is one of `PAYMENT` or `SHIPPING` or `ORDERTOTAL` |
| 33 | + |
| 34 | +The module name is taken from the $code class variable of the module, and the define name describes the purpose of the define. |
| 35 | + |
| 36 | +In previous version of Zen Cart,these configuration values were accessed directly using the key that was stored in the database, however using |
| 37 | +the new module support classes we access them through a helper method. |
| 38 | + |
| 39 | +e.g In legacy code we might have done |
| 40 | + |
| 41 | +`$this->sort_order = defined('MODULE_PAYMENT_COD_SORT_ORDER') ? MODULE_PAYMENT_COD_SORT_ORDER : null;` |
| 42 | + |
| 43 | +With the new infratructure we can simply do |
| 44 | + |
| 45 | +`$this->sort_order = $this->getDefine('SORT_ORDER);` |
| 46 | + |
| 47 | +The `getDefine` method is context aware, so knows which type of module you are using(PAYMENT/SHIPPING/ORDERTOTAL) and the current define name (e.g. COD) for |
| 48 | +the module you are using. |
| 49 | + |
| 50 | +Furthermore, you can also set a value that will be returned from the method if the configuration value does not exist. |
| 51 | + |
| 52 | +In the example above, the method will return `null` if the `MODULE_PAYMENT_COD_SORT_ORDER` does not exist. |
| 53 | + |
| 54 | +However you could also do `$this->sort_order = $this->getDefine('SORT_ORDER, 0);` |
| 55 | + |
| 56 | +and the method will return `0`, if the configuration value does not exist. |
| 57 | + |
| 58 | +There are also a number of helper methods to get some of the most common module configuration keys. |
| 59 | + |
| 60 | +### getTitle |
| 61 | + |
| 62 | +This gets the title for the Module. |
| 63 | + |
| 64 | +It looks for defines with suffixes in an array of ['TITLE', 'TEXT_TITLE', 'CATALOG_TITLE'] |
| 65 | + |
| 66 | +If your module uses a different define for the title then you should override the getTitle method. |
| 67 | + |
| 68 | +### getAdminTitle |
| 69 | + |
| 70 | +This returns a title to display on the Admin interface. In general this would be the same as the getTitle as above, but sometimes you may want it to be different. |
| 71 | +It expects to be passed a default title, which would normally be what the getTitle function returns, ans will use this if it does not find a define related to the admin title. |
| 72 | + |
| 73 | +This function looks for defines with a suffix in an array ['TITLE_ADMIN', 'TEXT_TITLE_ADMIN', 'ADMIN_TITLE'] |
| 74 | + |
| 75 | +If your admin title is defined through other means, them you will need to override this method in your module. |
| 76 | + |
| 77 | +### getDescription |
| 78 | + |
| 79 | +returns a module define with the suffix `DESCRIPTION` |
| 80 | + |
| 81 | +### getSortOrder |
| 82 | + |
| 83 | +returns a module define with the suffix `SORT_ORDER` |
| 84 | + |
| 85 | +### getZone |
| 86 | + |
| 87 | +returns a module define with the suffix `ZONE` |
| 88 | + |
| 89 | +### getDebugMode# |
| 90 | + |
| 91 | +returns a module define with the suffix `DEBUG_MODE` |
| 92 | + |
| 93 | +### isEnabled |
| 94 | + |
| 95 | +This function checks to see if the module is enabled. |
| 96 | + |
| 97 | +it first checks to see if the module has any missing configuraitions and then check the module define suffix `STATUS` |
| 98 | + |
| 99 | +### moduleAutoloadSupportClasses |
| 100 | + |
| 101 | +This function is only called if it exists. |
| 102 | + |
| 103 | +It allows a module to add autoload classes using the psr4autoaload Aura autoload. |
0 commit comments