OXID eShop Component
Note
Watch a short video tutorial on YouTube: Components & Services.
OXID eShop component is a simple way for a project to add reusable code to the application via Composer packages. You can write classes that have new or extended functionality and you may wire these classes together in your Composer package by using the Service Container.
In contrast to modules, components do not need to be activated but just installed by Composer.
How it works
On installation the OXID Composer plugin will include your components services.yaml file in a file
named generated_services.yaml that is read when the DI container is assembled.
You will find this file in var/generated but you should not alter it manually.
Component type
It’s necessary that component would have oxideshop-component type in composer.json file:
{
"type": "oxideshop-component",
}
Installation
When requiring a package with Composer the OXID eShop Composer Plugin checks the package type. If the type is oxideshop-component then the package is installed as an OXID eShop component.
composer require vendor/package
During the installation the services.yaml file is imported into the Service Container. After that, the component is globally and permanent active.
Uninstallation
To uninstall a OXID eShop component, it’s necessary to execute Composer’s remove command:
composer remove vendor/package
Database Migration
Components can provide their own Doctrine database migrations by registering their migration
configuration through the Symfony service container using the oxid_esales.migration_path_provider
DI tag.
Configuration
Place the Doctrine migration configuration file inside a migration folder in your component:
├── migration
│ ├── migrations.yml
│ └── data
│ └── Version20240101000000.php
Example migrations.yml:
table_storage:
table_name: myvendor_mycomponent_migrations
migrations_paths:
'MyVendor\MyComponent\Migrations': data
Tip
To prevent database table name conflicts, include your component’s name in table_name.
Creating a migration version
To generate a blank migration class, call the Doctrine Migrations CLI directly with your component’s configuration (see also Calling Doctrine Migrations directly):
vendor/bin/doctrine-migrations migrations:generate \
--configuration=<path-to-component>/migration/migrations.yml
Migration path provider
Implement MigrationPathProviderInterface to point the executor at your configuration file:
<?php
use OxidEsales\EshopCommunity\Internal\Framework\Migration\MigrationPathProviderInterface;
class MyComponentMigrationPathProvider implements MigrationPathProviderInterface
{
public function getMigrationConfigPath(): string
{
return __DIR__ . '/../migration/migrations.yml';
}
}
Register the provider in your component’s services.yaml with the
oxid_esales.migration_path_provider tag:
services:
MyVendor\MyComponent\MyComponentMigrationPathProvider:
tags:
- { name: 'oxid_esales.migration_path_provider' }
Running migrations
All registered component migrations run together with the shop migrations via:
vendor/bin/oe-console oe:database:migrate