Skip to content

Commit 485f789

Browse files
committed
Documentation for new module support infrastructure
1 parent 6f72d44 commit 485f789

File tree

8 files changed

+332
-0
lines changed

8 files changed

+332
-0
lines changed

content/dev/modules/_index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Modules Infrastructure
3+
description: New modules infrastructure
4+
weight: 100
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+
In order to make it easier and quicker to write modules(Payment/Shipping/Order Totals) a new infrastructure for these modules has been created.
15+
16+
This new infrastructure will reduce the amount of boilerplate code required, minimize copy/paste coding and adds helpers for common coding requirements.
17+
18+
{{% alert title="Note" color="primary" %}}
19+
Previous Payment/Shipping/Order total modules will continue to work without modification.
20+
{{% /alert %}}

content/dev/modules/base/_index.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Module Configuration Errors
3+
description:
4+
weight: 100
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+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Module Language defines
3+
description:
4+
weight: 120
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+
Language define files for modules follow the same format as normal language defines.
15+
16+
They are stored in `includes/languages/{language}/modules/` and at the very least should have an english translation.
17+
18+
e.g.
19+
20+
`includes/languages/english/modules/payment/lang.cod.php`
21+
22+
`includes/languages/english/modules/shipping/lang.flat.php`
23+
24+
`includes/languages/english/modules/order_total/lang.ot_subtotal.php`
25+
26+
27+
Like module configuration keys, naming of module language defines are the same
28+
e.g.
29+
30+
`MODULE_[module type]\_[module name]\_[define name]`
31+
32+
There are some other rules.
33+
34+
language define names should be unique and not match any other module configuration defines.
35+
36+
At a minimum you should provide the following
37+
38+
'TEXT_TITLE' => 'Stripe Checkout',
39+
40+
'TEXT_DESCRIPTION' => '<strong>Stripe Pay</strong>',
41+
42+
43+
e.g
44+
45+
```
46+
$define = [
47+
'MODULE_PAYMENT_STRIPE_PAY_TEXT_TITLE' => 'Stripe Checkout',
48+
'MODULE_PAYMENT_STRIPE_PAY_TEXT_DESCRIPTION' => '<strong>Stripe Pay</strong>',
49+
];
50+
return $define;
51+
```
52+
53+
Note: also if you want to provide a different tiile in the admin interface you can add something like
54+
55+
`MODULE_PAYMENT_STRIPE_PAY_ADMIN_TEXT_TITLE' => 'Stripe Checkout(ADMIN)`
56+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Module Logging
3+
description:
4+
weight: 120
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+
All modules have access to a new logging infrastructure.
15+
16+
This logging infrastructure uses monolog as the log provider.
17+
18+
It provides 3 log handlers
19+
20+
- File logging
21+
- Console logging
22+
- Email Logging
23+
24+
To log something in a module you can do
25+
26+
`$this->logger->log($logLevel, $message, $context)`
27+
28+
$logLevel is based on the standard log levels that PSR/log supports.
29+
30+
i.e
31+
32+
```
33+
class LogLevel
34+
{
35+
const EMERGENCY = 'emergency';
36+
const ALERT = 'alert';
37+
const CRITICAL = 'critical';
38+
const ERROR = 'error';
39+
const WARNING = 'warning';
40+
const NOTICE = 'notice';
41+
const INFO = 'info';
42+
const DEBUG = 'debug';
43+
}
44+
```
45+
46+
$context is not required but if passed, should be an array of values.
47+
48+
## File logging
49+
50+
This logs the message and context(if passed) to a file.
51+
52+
Logs all messages with a level of `debug` or higher.
53+
54+
The file name that is used is determined as follows.
55+
56+
A prefix will be generated based on the log channel, which is based on the module type.
57+
58+
e.g. payment/shipping/order_total.
59+
60+
The code of the module is then added.
61+
62+
e.g. `flat` or `paypal` etc.
63+
64+
following this a string will be added based on whether the code generating the log is either admin or storefront code.
65+
66+
The log file name will then be suffixed with the current date using a format that means logs will be aggregated daily.
67+
68+
### For logs generated by Admin code.
69+
70+
This will be prefixed with `admin-`
71+
72+
and the current session admin id will be added if applicable.
73+
74+
Then if the code generating the error references an order, the order id will be added.
75+
76+
### For logs generated by store front code.
77+
78+
This will be prefixed with `store-`
79+
80+
Then if a customer id is available in the context of the log then the customer id, and a partial customer first name and last name will be added to the log file name.
81+
82+
83+
## Console Logging
84+
85+
This will log the error message and context(if passed) to the javascript console.
86+
87+
So will be viewable using your browsers developer console.
88+
89+
Logs all messages with a level of `debug` or higher.
90+
91+
## Email Logging
92+
93+
This will send an email to the email address of the store owner. Currently there is no way to change this but that might change in the future.
94+
95+
Logs all messages with a level of `error` or higher.
96+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Order Totals Modules
3+
description:
4+
weight: 140
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
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Payment Modules
3+
description:
4+
weight: 100
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Shipping Modules
3+
description:
4+
weight: 120
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+
In order to make it easier and quicker to write modules(Payment/Shipping/Order Totals) a new infrastructure for these modules has been created.
15+
16+
This new infrastructure will reduce the amount of boiler plate code required, minimize copy/paste coding and adds helpers for common coding requirements.
17+
18+
{{% alert title="Note" color="primary" %}}
19+
Previous Payment/Shipping/Order total modules will continue to work without modification.
20+
{{% /alert %}}

0 commit comments

Comments
 (0)