Register a new adapter
Create the adapter
info
New adapters must inherit from the following abstract class: Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ArrayAdapterAbstract
use Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ArrayAdapterAbstract;
class ExampleAdapter extends ArrayAdapterAbstract
{
public static function getPackageName(): string
{
return 'example';
}
public function getTargetClassName(): string
{
return 'ExampleClassName';
}
protected function prepare($object): array
{
return [
'id' => $object->getId(),
'uuid' => md5($object->getId()),
'active-websites' => $object->getActiveWebsites(),
'texts' => $this->translationHelper()->mapTranslations(
$object->getLocalizedfields(),
['downloadTitle', 'downloadDescription'],
[
'downloadTitle' => 'title',
'downloadDescription' => 'description'
]
),
'custom-fields' => [
'position' => $object->getPosition(),
]
];
}
}
Explanation of various methods
Name | Description |
---|---|
getPackageName(): string | Unique package name, e.g., "product" |
getTargetClassName(): string | Corresponding object class name, e.g., "Product" |
prepare($object): array | Content-related processing of data intended for export |
Optional | |
initialize(): void | Performs preparatory processes, e.g., determination of product positions |
getDependentAdapters(): array | Defines the processing order of dependent adapters, see "Dependencies between export adapters" |
getThumbnailMapping(): array | Defines adapter-relevant thumbnails to be considered during image transfer |
Registering the adapter
New adapters must be registered in a service configuration file. The service tag twocream.shopware_connector.adapter
must be used obligatorily.
After that, the following CLI command must be executed: twocream:shopware-connector:reload-permissions
.
Best Practice
For structured configuration, it is recommended to create the file config/services/shopware_connector_adapter.yaml
.
This can then be included via an import into the central services.yaml
.
services:
_defaults:
autowire: true
autoconfigure: true
public: false
twocream.shopware_connector.adapter_example:
public: true
class: App\Components\Export\Adapters\ExampleAdapter
tags: [ 'twocream.shopware_connector.adapter' ]