Apps are self-contained packages that add new features and extend existing features without the need to edit core source code files. All files of an App are located in one main directory, with an external public directory for public resources (eg, images, javascript, stylesheets, ..).
Apps are located in the following directory:
includes/OSC/Apps/VENDOR/APP
Files that need to be publicly accessible are located at:
public/Apps/VENDOR/APP
A JSON structured oscommerce.json metadata file must exist in the top level App directory that describes the App and the modules it makes available. Modules do not need to exist in a specific directory within the package - rather the namespace is defined in the metadata file which the framework uses as a reference to find the location of the module class file.
Metadata File Example: osCommerce\Core
{
"title": "osCommerce Core Modules",
"app": "Core",
"vendor": "osCommerce",
"version": 1.0.0,
"req_core_version": 2.4.0,
"license": "MIT",
"authors": [
{
"name": "osCommerce",
"company": "osCommerce",
"email": "[email protected]",
"website": "https://www.oscommerce.com"
}
],
"modules": {
"Payment": {
"COD": "Module\\Payment\\COD"
},
"Shipping": {
"Flat": "Module\\Shipping\\Flat",
"Zones": "Module\\Shipping\\Zones"
},
"Hooks": {
"Shop/Cart": {
"AdditionalCheckoutButtons": "Module\\Hooks\\Shop\\Cart\\AdditionalCheckoutButtons"
}
}
},
"routes": {
"Admin": "Sites\\Admin\\Pages\\Home",
"Shop": {
"new-offers": "Sites\\Shop\\Pages\\NewOffers",
"account&coupons": "Sites\\Shop\\Pages\\Coupons"
}
}
}
Namespaces defined in the modules section are based from the Apps own namespace level - a namespace of Module\Payment\COD has a full namespace class of OSC\OM\Apps\VENDOR\APP\Module\Payment\COD.
Namespaces must also be escaped appropiately according to the JSON specification otherwise the metadata file will not be readable. This means the PHP namespace separator must consist of two backslash characters instead of one.
Metadata Schema
Parameter | Description |
---|---|
title | The public title of the App. |
app | The internal name of the App. This must be one word and match the APP directory name of the App. |
vendor | The vendor / company name of the App. This must be one word and match the VENDOR directory name of the App. |
version | The version of the App. This must be in X.Y.Z format. |
req_core_version | The minimum osCommerce Online Merchant version required for the App. This must be in X.y.Z format. |
license | The license the App is released under. Examples:
|
authors | A list of authors containing the following for each author:
|
modules | A list of modules the App makes available. Each module type has its own specification - please refer to the Modules section for more information. |
routes | A list of url based routes that load App Page controllers. Each Site has its own specification - please refer to the Routes section for more information. |
Modules that are installed and registered in the database are not stored with their full namespace class names, rather with an alias as defined in the metadata file.
For example, the core Cash on Delivery payment module is stored in the MODULE_PAYMENT_INSTALLED configuration parameter as osCommerce\Core\COD. The payment class knows that a payment module is being requested and looks up the COD alias defined in the metadata file to retrieve the class as Module\Payment\COD. The full class name reference and file location would be:
Namespace | Class Location |
---|---|
OSC\Apps\osCommerce\Core\Module\Payment\COD | includes/OSC/Apps/osCommerce/Core/Module/Payment/COD.php |
Modules that are to be made available to the framework must be defined in the Apps metadata file. Each module type has its own definition specification to be able to load the module class on request simply by referencing an alias.
Each module must implement a module type interface which dictates the functions the module must make available to the framework. Module Type Interfaces are located in the following namespace and directory:
Namespace | Directory |
---|---|
OSC\OM\Modules\ | includes/OSC/OM/Modules/ |
The following Module Types are available in the core:
Module Types | |
---|---|
|
Metadata JSON
Specification
Reference
|
|
Metadata JSON
Specification
Reference
|
|
Metadata JSON
Specification
Reference
|
|
Metadata JSON
Specification
Reference
|
|
Metadata JSON
Specification
Reference
|
|
Metadata JSON
Specification
Reference
The selected shipping method is added to the reference appending the ALIAS with an underscore and the code of the selected shipping method. For example:
|
|
Metadata JSON
Specification
Reference
|
The full namespace class name of a module can be retrieved via its alias using Apps::getModuleClass():
use OSC\OM\Apps;
$class = Apps::getModuleClass('osCommerce\Core\COD', 'Payment');
// $class = OSC\Apps\osCommerce\Core\Module\Payment\COD
Parameters
Apps::getModuleClass($module, $type)
Parameter | Value |
---|---|
$module | The alias of the module to retrieve the class name from. |
$type | The module interface type. |
A list of available App modules can be retrieved using Apps::getModules():
use OSC\OM\Apps;
$modules = Apps::getModules('Payment');
Parameters
Apps::getModules($type, $filter_vendor_app, $filter)
Parameter | Value |
---|---|
$type | The module type to retrieve. |
$filter_vendor_app | If an App is provided, only modules from that App are returned, otherwise all modules from all Apps are returned. This can be limited to VENDOR for all vendor Apps, or VENDOR\APP for a specific App. |
$filter | Pass a Module Type specific filter to filter the results with. |
Routes allow Apps to load Page controllers via the Sites route resolver method. The Shop Site allows Apps to load Page controllers depending on the url of the page requested, and the Admin Site allows one main Page controller to be loaded to administrate and configure the App on the Administration Dashboard.
"app": "Core",
"vendor": "osCommerce",
"routes": {
"Admin": "Sites\\Admin\\Pages\\Home",
"Shop": {
"new-offers": "Sites\\Shop\\Pages\\NewOffers",
"account&coupons": "Sites\\Shop\\Pages\\Coupons"
}
}