skip to Main Content

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

enter image description here

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?

2

Answers


  1. 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="ShopwareCoreContentImportExportDataAbstractionLayerSerializerEntityProductSerializer">
        <!-- ... -->
        <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.

    Login or Signup to reply.
  2. 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;
            }
        }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search