oxid-esales / examples-module
Module with solution examples
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Type:oxideshop-module
Requires
- php: ^8.2
- symfony/filesystem: ^6.4
Requires (Dev)
- codeception/codeception: ^5.1
- codeception/module-asserts: ^3.0
- codeception/module-db: ^3.1
- codeception/module-filesystem: ^3.0
- codeception/module-webdriver: ^4.0
- mikey179/vfsstream: ~1.6.8
- oxid-esales/codeception-modules: dev-b-7.3.x
- oxid-esales/codeception-page-objects: dev-b-7.3.x
- oxid-esales/developer-tools: dev-b-7.3.x
- oxid-esales/oxideshop-ce: dev-b-7.3.x
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.0.2
- phpunit/phpunit: ~10.5.17
- squizlabs/php_codesniffer: ^3.10
Conflicts
- oxid-esales/oxideshop-ce: <7.3
This package is auto-updated.
Last update: 2025-06-05 12:41:29 UTC
README
The examples module contains examples for the most common use cases (see below) like OXID suggests it could be implemented.
This module also comes with all the quality tools OXID recommends to use.
Table of contents
- Branch compatibility
- The Idea
- Goals
- Examples
- Install and try it out
- Development installation
- Development installation on OXID eShop SDK
- Things to be aware of
- Running tests and quality tools
- Additional info
Branch compatibility
- b-7.3.x branch and v1.x releases - compatible with OXID eShop compilation 7.3.x and the respective branch
The Idea
OXID eSales would like to provide a lightweight reusable example module incorporating our best practices recommendations to be used for developing own module solutions.
Story:
- Module will extend a block on shop start page to show a greeting message (visible when module is active).
- Module will have a setting to switch between generic greeting message for a logged in user and a personal custom greeting. The Admin's choice which way it will be.
- A logged in user will be able to set a custom greeting depending on module setting. Press the button on start page and be redirected to a module controller which handles the input.
- User custom greetings are saved via shop model save method. We subscribe to BeforeModelUpdate to track how often a user changed his personal greeting.
- Tracking of this information will be done in a new database table to serve as an example for module's own shop model.
- Module will extend the shop's basket model to add info to module specific log file when an item is added into basket. Logging can be enabled or disabled depending on module setting.
- Module will have console command
oeexamples:logger:read
to read log file.
./vendor/bin/oe-console oeexamples:logger:read
Goals
Install and try out the module with simple examples to most common development questions.
Examples
The repository contains examples of following cases and more:
-
Extending of shop controllers and models
- extending a shop model (
OxidEsales\ExamplesModule\Extension\Model\User
) / (OxidEsales\ExamplesModule\Extension\Model\Basket
) - extending a shop controller (
OxidEsales\ExamplesModule\Extension\Controller\StartController
)
- extending a shop model (
-
- own module controller (
oeem_greeting
with own template and own translations) - own module admin controller (
oeem_admin_greeting
with own template and own translations)
- own module controller (
-
- extending a shop database table (
oxuser
)
- extending a shop database table (
-
Accessing the database
- model with a database (
OxidEsales\ExamplesModule\Tracker\Model\GreetingTracker
) oxNew
object factory example (OxidEsales\ExamplesModule\Greeting\Infrastructure\UserModelFactory
)- DAO
- model with a database (
-
Templates
- creating templates for your module
- extending of oxid theme templates or blocks
- extending a shop admin template block (
admin_user_main_form
- only an extension of a block, without functionality) - extending a shop template block (
start_newest_articles
)
- extending a shop admin template block (
-
Using the translations for your module specific phrases
-
Events and listeners
-
Testing your module backend and frontend part
-
Using variables from .env file
- Access via
getenv()
function- Note: Changes to environment variables take effect immediately — no cache clearing is required.
- Access via DI container
- Note: After updating environment variables, you must clear the cache for changes to take effect.
- Access via
HINTS:
- Only extend the shop core if there is no other way like listen and handle shop events, decorate/replace some DI service.
- Your module might be one of many in the class chain and you should act accordingly (always ensure to call the parent method and return the result).
- When extending shop classes with additional methods, best prefix those methods in order to not end up with another module picking the same method name and wreacking havoc.
- In case there is no other way than to extend existing shop methods try the minimal invasion principle. Put module business logic to a service (which make it easier to test as well) and call the service in the extended shop class. If you need to extend the shop class chain by overwriting, try to stick to the public methods.
Not yet in here but might come later:
- example for payment gateway extension
- seo url for module controller
- to redirect or not to redirect from inside the shop core
- graphql query/mutation example
- extending the internal part
Install and try it out
Note: This installation method fits for trying out the module development basics, its not meant to be used as development base for your own module. Check further installation/usage methods.
This module is in working state and can be directly installed via composer:
composer require oxid-esales/examples-module
./vendor/bin/oe-eshop-doctrine_migration migrations:migrate oe_examples_module
and activate the module.
Development installation
To be able running the tests and other preconfigured quality tools, please install the module as a root package.
The next section shows how to install the module as a root package by using the OXID eShop SDK.
In case of different environment usage, please adjust by your own needs.
Development installation on OXID eShop SDK
The installation instructions below are shown for the current SDK for shop 7.3. Make sure your system meets the requirements of the SDK.
-
Ensure all docker containers are down to avoid port conflicts
-
Clone the SDK for the new project
echo MyProject && git clone https://github.com/OXID-eSales/docker-eshop-sdk.git $_ && cd $_
- Clone the repository to the source directory
git clone --recurse-submodules https://github.com/OXID-eSales/examples-module.git --branch=b-7.3.x ./source
- Run the recipe to setup the development environment, you can decide which shop edition to install. Omitting the flag installs EE.
./source/recipes/setup-development.sh -e CE
You should be able to access the shop with http://localhost.local and the admin panel with http://localhost.local/admin (credentials: noreply@oxid-esales.com / admin)
Things to be aware of
The examples module is intended to act as a tutorial module so keep your eyes open for comments in the code.
NOTES:
- Acceptance tests are way easier to write if you put an id on relevant fields and buttons in the templates.
- If you can, try to develop on OXID eShop Enterprise Edition to get shop aware stuff right from the start.
Module migrations
- migrations are intended to bump the database (and eventual existing data) to a new module version (this also goes for first time installation).
- ensure migrations are stable against rerun
Migrations have to be run via console command (./vendor/bin/oe-eshop-doctrine_migration
)
./vendor/bin/oe-eshop-doctrine_migration migrations:migrate oe_examples_module
NOTE: Existing migrations must not be changed. If the database needs a change, add a new migration file and change to your needs:
./vendor/bin/oe-eshop-doctrine_migration migrations:generate oe_examples_module
For more information, check the developer documentation.
Where the module namespace points to
As already mentioned above, in the 7.x versions of OXID eShop, the module code only resides in the vendor directory so the namespace needs to point there. In our case this looks like
"autoload": { "psr-4": { "OxidEsales\\ExamplesModule\\": "src/" } }, "autoload-dev": { "psr-4": { "OxidEsales\\ExamplesModule\\Tests\\": "tests/", "OxidEsales\\EshopCommunity\\Tests\\": "./vendor/oxid-esales/oxideshop-ce/tests" } },
Running tests and quality tools
Check the scripts
section in the composer.json of the module to get more insight of
preconfigured quality tools available. Example:
$ composer phpcs $ composer phpstan $ composer phpmd
Integration/Acceptance tests
- install this module into a running OXID eShop
- run
composer update
in module root directory
$ composer update
After this done, check the "scripts" section of module composer.json
file to see how we run tests.
$ composer tests-unit $ composer tests-integration $ composer tests-codeception
NOTE: From OXID eShop 7.0.x on database reset needs to be done with this command (please fill in your credentials)
$ bin/oe-console oe:database:reset --db-host=mysql --db-port=3306 --db-name=example --db-user=root --db-password=root --force
And just in case you need it, admin user can now also be created via commandline
$ bin/oe-console oe:admin:create-user --admin-email <admin-email> --admin-passowrd <admin-password>
for example
$ bin/oe-console oe:admin:create-user --admin-email admin@oxid-esales.com --admin-password admin
Writing Codeception tests
As a rule of thumb, use codeception tests to ensure the frontend is behaving as expected. Codeception tests take a while to run, so try to navigate the way between covering the relevant cases and overtesting.
We definitely need some acceptance tests if the module affects the frontend like in our example. If the module breaks the frontend, we need to see it asap.
In our case, we cover the reaction of the startpage to the different possibilities
- generic greeting mode (with/without logged in user)
- personal greeting mode (with/without logged in user)
- updating the greeting mode
- ensure module can be activated/deactivated without destroying the shop
- ensure edge case safety like not logged in user directly calling module controller
The great thing about codeception tests is - they can create screenshot and html
output in failure case, so you literally get a picture of the fail (tests/Coreception/_output/
).
Github Actions Workflow
The examples-module comes complete with a github actions workflow. No need to rig up some separate continuous integration
infrastructure to run tests, it's all there in github.
You will see three files in .github/workflow
directory. The workflow from
.github/workflow/trigger.yaml
starts on every push
and pull_request
to run the code quality checks and all the module tests.
In our experience it is useful to run the shop tests with the module installed and activated from time to time. For sure those shop tests have been written with only the shop itself in mind. Your module, depending on what it is doing, might completely change the shop behaviour. Which means those shop tests with a module might just explode in your face. Which is totally fine, as long as you can always explain WHY those tests are failing.
Real life example: There is one shop acceptance test case OxidEsales\EshopCommunity\Tests\Acceptance\Frontend\ShopSetUpTest:
which is testing the frontend shop setup. Very good chance this test will fail if a module is around which extends
the class chain. That test is for setting up a shop from scratch so it will simply not expect a module to be around.
And we only need our module to safely work with a working shop. We definitely will decide to skip that ShopSetUpTest
as we have a good explanation as to why it will not work. And having this special test case work with our module will give no benefit.
This is only one example, there might be other tests that fail with your module but fail because your module is changing the shop. In that case the suggestion would be to exclude the original test from the github actions run, copy that test case to your module tests and update to work with your module. This was for example the strategy used for our reverse proxy modules which are mandatory to not make the shop's acceptance tests fail. Unless those test cases that somehow bypass reverse proxy cache invalidation. To be on the safe side, we took over those few test cases to the module and plan to improve the shop tests as soon as possible. We'll gladly also take your PR with improved shop tests ;)
And then there are some few shop tests marked as @group quarantine
in the doc block. Test in that group have stability issues so they'd better
be excluded as well.
Ps: a failing shop test might also turn up issues in your module, in that case fix the module and let the test live ;)
Additional info
Useful links
- Vendor home page - https://www.oxid-esales.com
- Bug tracker - https://bugs.oxid-esales.com
- Developer Documentation - https://docs.oxid-esales.com/developer/en/latest/
- Quality Tools and Requirements - https://docs.oxid-esales.com/developer/en/latest/development/modules_components_themes/quality.html
- Docker SDK - https://github.com/OXID-eSales/docker-eshop-sdk
Contact us
- In case of issues / bugs, use "Issues" section on github, to report the problem.
- Join our community forum
- Use the contact form
In case you have any complaints, suggestions, business cases you'd like an example for please contact us. Pull request are also welcome. Every feedback we get will help us improve.