Reputation: 15
In shopware it is possible to import/export data with a profile. See the following link. https://docs.shopware.com/en/shopware-en/settings/importexport
The only problem now is that I want to upload data of a custom entity. I can't find the custom entity in the profiles. So my question is of it is possible to upload this data in bulk via an CSV?
Upvotes: 1
Views: 462
Reputation: 11
@Update (Shopware 6.6.x)
const profileTypes = {
IMPORT: 'import',
EXPORT: 'export',
IMPORT_EXPORT: 'import-export',
};
Shopware.Component.override('sw-import-export-edit-profile-general', {
computed: {
supportedEntities() {
const supportedEntities = this.$super('supportedEntities');
supportedEntities.push(
{
value: 'your_entity',
label: "your_label",
type: profileTypes.IMPORT_EXPORT,
}
);
return supportedEntities;
}
}
});
Upvotes: 0
Reputation: 71
You have to add your entity to
vendor/shopware/administration/Resources/app/administration/src/module/sw-import-export/component/sw-import-export-edit-profile-general/index.js
to supportedEntieties() method
You can do it like this:
const { Component } = Shopware;
Component.override('sw-import-export-edit-profile-general', {
methods: {
supportedEntities() {
const supportedEntities = this.$super('supportedEntities');
supportedEntities.push({
value: 'your_entity_name',
label: "Entity Label",
type: profileTypes.IMPORT_EXPORT,
});
return supportedEntities;
}
}
});
Upvotes: 3
Reputation: 13161
You'll have to persist a import/export profile for your custom entity:
$container->get('import_export_profile.repository')->create([
[
'name' => 'My Custom Entity',
'label' => 'My Custom Entity',
'sourceEntity' => 'my_custom_entity',
'type' => ImportExportProfileEntity::TYPE_IMPORT_EXPORT,
'fileType' => 'text/csv',
'delimiter' => ';',
'enclosure' => '"',
'config' => [],
'mapping' => [
['key' => 'id', 'mappedKey' => 'id', 'position' => 1],
['key' => 'active', 'mappedKey' => 'active', 'position' => 2],
['key' => 'translations.DEFAULT.name', 'mappedKey' => 'name', 'position' => 3],
['key' => 'type', 'mappedKey' => 'type', 'position' => 0],
],
]
], $context);
There you have to map your entities fields to the columns of the CSV.
If you want to influence how fields are written or read you might want to register a serializer for your entity. For example the product entity has a serializer:
<service id="Shopware\Core\Content\ImportExport\DataAbstractionLayer\Serializer\Entity\ProductSerializer">
<!-- ... -->
<tag name="shopware.import_export.entity_serializer" priority="-400"/>
</service>
Maybe have a look at the serializer for reference if your entity has some fields that need special treatment.
Upvotes: 4