Files
oc_extension/README.md
T
2026-11-25 04:59:49 +02:00

925 lines
21 KiB
Markdown

# OpenCart Extension Template
A reusable template for developing, validating, packaging, and releasing OpenCart extensions through **Gitea Actions**.
This repository provides a standardized starting point for OpenCart 3 and OpenCart 4 extensions, with automated OCMOD package generation and Git-based release management.
---
## Table of Contents
- [Overview](#overview)
- [Supported OpenCart Versions](#supported-opencart-versions)
- [Repository Architecture](#repository-architecture)
- [Getting Started](#getting-started)
- [Extension Configuration](#extension-configuration)
- [OpenCart 3 Development](#opencart-3-development)
- [OpenCart 4 Development](#opencart-4-development)
- [Package Generation](#package-generation)
- [Automated Build and Release](#automated-build-and-release)
- [Versioning and Release Management](#versioning-and-release-management)
- [Validation and Quality Checks](#validation-and-quality-checks)
- [Gitea Configuration](#gitea-configuration)
- [Using This Template for New Extensions](#using-this-template-for-new-extensions)
- [Troubleshooting](#troubleshooting)
- [Development Guidelines](#development-guidelines)
---
## Overview
The purpose of this template is to standardize the development and distribution of OpenCart extensions.
Each extension repository must target **one OpenCart generation only**.
OpenCart 3 and OpenCart 4 have different internal architectures, extension structures, metadata formats, and development conventions. Therefore, a single repository must not attempt to generate both OC3 and OC4 packages.
### Key Features
- Dedicated support for OpenCart 3 and OpenCart 4 repositories.
- Automated extension packaging through Gitea Actions.
- Metadata-driven extension versioning.
- Automatic ZIP package generation.
- PHP syntax validation.
- XML and JSON metadata validation.
- ZIP integrity verification.
- SHA-256 checksum generation.
- Automated Gitea release creation.
- Existing release replacement when publishing the same version.
- Manual build and release execution.
- Consistent package naming conventions.
### Design Principles
1. One repository represents one OpenCart target generation.
2. Extension business logic remains independent of the build system.
3. Packaging includes only the files required to install the extension.
4. Optional installation resources are included only when present and supported by the target platform.
5. Releases are generated from validated source code.
6. The extension metadata is the source of truth for its version.
---
## Supported OpenCart Versions
The template supports the following targets:
| Platform | Supported versions | Metadata |
|---|---|---|
| OpenCart 3 | 3.0.3.x | `install.xml` |
| OpenCart 4 | 4.0.0 | `install.json` |
| OpenCart 4 | 4.0.1 | `install.json` |
| OpenCart 4 | 4.0.2.x | `install.json` |
| OpenCart 4 | 4.1.x | `install.json` |
**Important:** Declaring a minimum OpenCart version does not automatically guarantee runtime compatibility. Extension code must still be tested against the actual OpenCart versions it claims to support.
### OpenCart 3 vs OpenCart 4
| Feature | OpenCart 3 | OpenCart 4 |
|---|---|---|
| Extension metadata | `install.xml` | `install.json` |
| Main package directory | `upload/` | Root-level extension directories |
| Admin files | `upload/admin/` | `admin/` |
| Catalog files | `upload/catalog/` | `catalog/` |
| System files | `upload/system/` | `system/` |
| OCMOD XML | `install.xml` | Optional `ocmod/` for supported versions |
| Installation resources | Optional `install.php`, `install.sql` | According to the extension's implementation |
Do not mix these structures in one repository.
---
## Repository Architecture
The repository structure depends on the OpenCart target.
### OpenCart 3 Repository
```text
my-extension-oc3/
├── .gitea/
│ └── workflows/
│ └── release.yml
│
├── .oc-extension.json
│
├── install.xml
│
├── upload/
│ ├── admin/
│ │ ├── controller/
│ │ ├── language/
│ │ ├── model/
│ │ └── view/
│ │
│ ├── catalog/
│ │ ├── controller/
│ │ ├── language/
│ │ ├── model/
│ │ └── view/
│ │
│ └── system/
│
├── install.php # Optional
├── install.sql # Optional
│
└── README.md
```
### OpenCart 4 Repository
```text
my-extension-oc4/
├── .gitea/
│ └── workflows/
│ └── release.yml
│
├── .oc-extension.json
│
├── install.json
│
├── admin/
│ ├── controller/
│ ├── language/
│ ├── model/
│ └── view/
│
├── catalog/
│ ├── controller/
│ ├── language/
│ ├── model/
│ └── view/
│
├── system/
│
├── ocmod/ # Optional; for supported OC4 versions
│ └── example.ocmod.xml
│
└── README.md
```
The build workflow packages the relevant installation files without including development-only files or repository configuration.
---
## Getting Started
### 1. Create a Repository
Create a new repository using this template.
Choose the target OpenCart generation before starting development:
- OpenCart 3 extension repository.
- OpenCart 4 extension repository.
Do not use one repository to maintain both implementations.
Recommended naming conventions:
```text
my-extension-oc3
my-extension-oc4
```
The naming convention is optional, but clearly identifying the target platform is recommended.
### 2. Configure the Extension
Create `.oc-extension.json` in the repository root.
For OpenCart 3:
```json
{
"platform": "oc3",
"code": "my_extension"
}
```
For OpenCart 4:
```json
{
"platform": "oc4",
"code": "my_extension",
"minimum_version": "4.0.0"
}
```
The configuration identifies the target platform and extension code used during packaging.
### 3. Add Extension Files
Use the appropriate directory structure for your target platform.
### 4. Configure Metadata
Complete `install.xml` for OC3 or `install.json` for OC4.
### 5. Configure Gitea Actions
Ensure the repository contains the release workflow:
```text
.gitea/workflows/release.yml
```
Configure the required repository secret as described in the Gitea Configuration section.
### 6. Push to Main
Push your changes to the `main` branch.
The workflow will validate and build the extension package.
---
## Extension Configuration
The `.oc-extension.json` file defines the build target.
### Available Configuration Properties
| Property | Required | Description |
|---|---|---|
| `platform` | Yes | Target platform: `oc3` or `oc4` |
| `code` | Yes | Unique extension code |
| `minimum_version` | OC4 | Minimum OpenCart version supported by the extension |
### Extension Code Rules
The extension code must:
- Use lowercase letters.
- Support numbers and underscores.
- Contain no spaces.
- Be consistent with the extension metadata where applicable.
Valid examples:
```text
my_extension
product_tools
advanced_checkout
extension123
```
Invalid examples:
```text
My Extension
my-extension
My_Extension
```
The extension code is used when generating the release package filename.
---
## OpenCart 3 Development
OpenCart 3 extensions use `install.xml` as their OCMOD metadata file.
### Required Files
```text
.oc-extension.json
install.xml
upload/
```
### install.xml Example
```xml
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>My Extension</name>
<code>my_extension</code>
<author>MY-Dev</author>
<link>https://my-dev.pro</link>
<version>1.0.0</version>
<file path="catalog/controller/common/header.php">
<operation error="skip">
<search><![CDATA[
// Search target
]]></search>
<add position="after"><![CDATA[
// Modification code
]]></add>
</operation>
</file>
</modification>
```
Replace the example metadata and modification contents with the actual extension implementation.
### Optional Installation Files
The following files may be included when required:
```text
install.php
install.sql
```
They are optional and are copied into the generated package when present.
### Package Structure
The generated OC3 package should have this structure:
```text
my_extension_v1.0.0.ocmod.zip
│
├── install.xml
├── upload/
│ ├── admin/
│ ├── catalog/
│ └── system/
│
├── install.php # If present
└── install.sql # If present
```
The ZIP must contain `upload/` and `install.xml` at its root.
---
## OpenCart 4 Development
OpenCart 4 uses a different extension architecture and installation metadata format.
### Required Files
```text
.oc-extension.json
install.json
```
At least one appropriate extension directory must be provided.
### install.json Example
```json
{
"name": "My Extension",
"version": "1.0.0",
"author": "MY-Dev",
"link": "https://my-dev.pro"
}
```
### Extension Directories
OpenCart 4 extension files are placed at the package root.
Typical directories include:
```text
admin/
catalog/
system/
```
Only the directories required by the extension need to be included.
### OCMOD Compatibility
OpenCart 4.0.0 and 4.0.1 require special consideration because their OCMOD support differs from later releases.
For extensions targeting these versions, do not assume that XML OCMOD modifications will be applied.
For OpenCart 4.0.2 and later, an optional `ocmod/` directory can contain XML modification files where the target version supports the required functionality.
Example:
```text
ocmod/
└── my_extension.ocmod.xml
```
Configure the minimum version accordingly:
```json
{
"platform": "oc4",
"code": "my_extension",
"minimum_version": "4.0.2"
}
```
### Package Structure
A typical OC4 package:
```text
my_extension_v1.0.0.ocmod.zip
│
├── install.json
├── admin/
├── catalog/
├── system/
└── ocmod/
└── my_extension.ocmod.xml
```
The `ocmod/` directory is optional.
The package should not contain an additional `upload/` directory.
---
## Package Generation
The Gitea Actions workflow generates the installation ZIP automatically.
### Package Naming Convention
The generated package follows this naming pattern:
```text
{extension_code}_v{extension_version}.ocmod.zip
```
Examples:
```text
my_extension_v1.0.0.ocmod.zip
product_tools_v1.2.0.ocmod.zip
advanced_checkout_v2.5.1.ocmod.zip
```
### Checksum File
Each package also receives a SHA-256 checksum file:
```text
my_extension_v1.0.0.ocmod.zip.sha256
```
This can be used to verify that the downloaded package matches the generated artifact.
Verify locally with:
```bash
sha256sum -c my_extension_v1.0.0.ocmod.zip.sha256
```
### Files Excluded from Packages
The release package should contain installation files only.
The following development and repository files must not be included:
- `.git/`
- `.gitea/`
- `.github/`
- `.oc-extension.json`
- `README.md`
- Test directories.
- Development scripts.
- Temporary build files.
- Unrelated documentation.
---
## Automated Build and Release
The workflow is located at:
```text
.gitea/workflows/release.yml
```
It supports three execution methods.
### 1. Push to Main
When changes are pushed to `main`:
1. The repository is checked out.
2. Build dependencies are installed.
3. The target OpenCart platform is identified.
4. Metadata is validated.
5. Extension files are checked.
6. PHP syntax validation is performed.
7. The package is generated.
8. ZIP integrity is verified.
9. SHA-256 checksum is generated.
10. Build artifacts are uploaded.
**A push to `main` does not publish a release.**
### 2. Version Tag
When a version tag is pushed:
```bash
git tag v1.0.0
git push origin v1.0.0
```
The workflow performs the complete build and release process.
The tag must match the version declared in the extension metadata.
For example:
| Metadata version | Required tag |
|---|---|
| `1.0.0` | `v1.0.0` |
| `1.2.0` | `v1.2.0` |
| `2.0.1` | `v2.0.1` |
A mismatch causes the release workflow to fail.
### 3. Manual Execution
The workflow can also be executed manually from the Gitea Actions interface.
Manual execution supports:
- Build and validate without publishing.
- Build and publish a release.
- Replace an existing release when publishing the same version.
The publishing option must be explicitly enabled for a manual run.
---
## Versioning and Release Management
The extension metadata is the source of truth for the extension version.
### Version Sources
| Platform | Version source |
|---|---|
| OC3 | `install.xml` → `modification/version` |
| OC4 | `install.json` → `version` |
Use semantic versioning where possible:
```text
MAJOR.MINOR.PATCH
```
Examples:
```text
1.0.0
1.0.1
1.1.0
2.0.0
```
### Release Naming
The release tag uses:
```text
v{version}
```
The release title uses:
```text
{extension_code} v{version}
```
### Existing Release Replacement
If a release already exists for the same tag, the workflow updates the existing release and replaces its assets.
For example:
1. Publish `v1.0.0`.
2. Fix an issue in the extension.
3. Rebuild the package.
4. Publish `v1.0.0` again.
5. The existing release assets are replaced with the newly generated package and checksum.
This behavior allows correcting a release without creating another version tag.
**Important:** Replacing a release is a destructive operation on its existing assets. Use it only when intentionally republishing the same version.
---
## Validation and Quality Checks
The workflow performs automated checks before publishing.
### Metadata Validation
For OC3:
- `install.xml` must exist.
- XML syntax must be valid.
- Extension code must match `.oc-extension.json`.
- Version must be present and valid.
- Empty OCMOD file paths are rejected.
- Empty search and add operations are rejected.
For OC4:
- `install.json` must exist.
- JSON syntax must be valid.
- Required metadata fields must be populated.
- Version must be present and valid.
- The repository must have a valid OC4 structure.
- OCMOD XML files are checked when included.
### PHP Syntax Validation
PHP files in the generated package are checked using:
```bash
php -l
```
Invalid PHP syntax causes the build to fail.
### ZIP Validation
The generated package is tested using:
```bash
unzip -t package.ocmod.zip
```
### Checksum Generation
The workflow generates a SHA-256 checksum for the final ZIP.
### Validation Limitations
Automated packaging checks do not replace runtime testing.
Before publishing an extension, test it against the actual OpenCart versions and configurations it claims to support.
In particular, validate:
- Installation and uninstallation.
- Admin permissions.
- Database changes.
- Storefront functionality.
- Modification compatibility.
- Upgrade and rollback behavior.
---
## Gitea Configuration
### Required Repository Secret
Configure the following secret in the repository settings:
```text
OC3_EXTENSION_RELEASE_TOKEN
```
The workflow uses this token to communicate with the Gitea API.
The token must have the permissions required to:
- Read repository release information.
- Create releases.
- Update existing releases.
- Delete existing release assets.
- Upload new release assets.
Use the least-privilege token supported by your Gitea installation.
Never store the token directly in the workflow or repository files.
### Gitea Actions Runner
The runner must support:
- Linux execution.
- Bash.
- Git.
- PHP CLI.
- `jq`.
- `curl`.
- `zip`.
- `unzip`.
- `xmllint` / `libxml2-utils`.
The workflow installs the required operating-system dependencies during execution.
### Gitea API
Release management uses the Gitea REST API.
The workflow relies on the repository URL and token provided by the Gitea Actions environment.
Make sure the Gitea instance permits release creation and asset uploads for the configured token.
---
## Using This Template for New Extensions
Recommended workflow for creating a new extension:
1. Create a repository from this template.
2. Decide whether the extension targets OC3 or OC4.
3. Configure `.oc-extension.json`.
4. Remove the unused platform's example files.
5. Add the required extension directories.
6. Complete the platform-specific metadata.
7. Implement the extension functionality.
8. Push the initial implementation to `main`.
9. Review the generated package.
10. Test installation in a clean OpenCart environment.
11. Create a version tag.
12. Verify the published release and checksum.
### Example: First Release
Update the extension metadata to:
```text
1.0.0
```
Commit and push:
```bash
git add .
git commit -m "Initial extension release"
git push origin main
```
Create and push the release tag:
```bash
git tag v1.0.0
git push origin v1.0.0
```
The workflow builds and publishes:
```text
my_extension_v1.0.0.ocmod.zip
my_extension_v1.0.0.ocmod.zip.sha256
```
### Example: Publishing an Update
Update the metadata version:
```text
1.1.0
```
Commit and push the changes:
```bash
git add .
git commit -m "Release version 1.1.0"
git push origin main
```
Publish the new version:
```bash
git tag v1.1.0
git push origin v1.1.0
```
---
## Troubleshooting
### Missing `.oc-extension.json`
**Cause:** The platform configuration file is missing.
**Solution:** Add `.oc-extension.json` and specify the target platform and extension code.
### OC3 Metadata Validation Failed
**Cause:** `install.xml` is missing, invalid, or contains incomplete metadata.
**Solution:** Validate the XML and ensure the code and version are populated.
### OC4 Metadata Validation Failed
**Cause:** `install.json` is missing or contains invalid JSON or missing required metadata.
**Solution:** Validate the JSON and ensure `name`, `version`, `author`, and `link` are populated.
### Platform Mismatch
**Cause:** The repository contains metadata or directory structures belonging to the other OpenCart generation.
**Solution:** Remove the incompatible files and use the correct repository structure.
### PHP Syntax Error
**Cause:** One or more PHP files contain syntax errors.
**Solution:** Run the following locally:
```bash
find upload admin catalog system -type f -name '*.php' \
-exec php -l {} \;
```
Use only the directories relevant to your platform.
### Release Tag Does Not Match Metadata
**Cause:** The Git tag does not match the version declared in the metadata.
**Solution:** Ensure the tag uses the `v` prefix and exactly matches the metadata version.
### Release Publishing Failed
**Possible causes:**
- Missing or invalid Gitea token.
- Insufficient release permissions.
- Gitea API endpoint unavailable.
- Existing release asset deletion failed.
- Asset upload failed.
Review the Actions logs and verify the repository secret and token permissions.
### Package Does Not Install
**Possible causes:**
- Incorrect package directory structure.
- Missing installation metadata.
- Incorrect extension directory names.
- Incompatible OpenCart target version.
- Missing dependencies.
- Incorrect extension implementation.
Inspect the ZIP archive before publishing.
---
## Development Guidelines
### General Rules
- Keep extension code separate from build configuration.
- Do not add platform-specific files to the wrong repository.
- Keep extension metadata synchronized with the release version.
- Do not commit generated ZIP packages or temporary build artifacts.
- Test extensions before publishing releases.
- Use meaningful commit messages.
- Keep the README of each extension repository focused on that extension's installation and usage.
### Template Maintenance
Changes to this template affect new repositories created from it.
Repositories already created from the template do not automatically receive workflow or documentation updates. Existing repositories must be updated separately.
When modifying the release workflow:
1. Test OC3 packaging.
2. Test OC4 packaging.
3. Verify metadata validation.
4. Verify package contents.
5. Verify checksum generation.
6. Verify release creation.
7. Verify replacement of existing release assets.
### Suggested Commit Messages
```text
feat: add new extension functionality
fix: correct extension installation issue
refactor: improve extension architecture
docs: update installation documentation
build: improve release workflow
chore: update development dependencies
```
---
## License
Add the license applicable to your extension repository.
For proprietary or commercial extensions, clearly document the applicable distribution and usage terms.
---
## Maintainer
**MY-Dev**
Website: https://my-dev.pro
This repository is intended to provide a consistent development and release foundation for OpenCart extensions maintained by MY-Dev.