簡體   English   中英

是否可以為自定義實體創建配置文件以使用 CSV 導入/導出數據?

[英]Is it possible to make a profile for a custom entity to import/export data with a CSV?

在 shopware 中,可以使用配置文件導入/導出數據。 請參閱以下鏈接。 https://docs.shopware.com/en/shopware-en/settings/importexport

在此處輸入圖像描述

現在唯一的問題是我想上傳自定義實體的數據。 我在配置文件中找不到自定義實體。 所以我的問題是可以通過 CSV 批量上傳這些數據嗎?

您必須保留自定義實體的導入/導出配置文件:

$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);

在那里你必須將你的實體字段 map 到 CSV 的列。

如果您想影響字段的寫入或讀取方式,您可能需要為您的實體注冊一個序列化程序。 例如產品實體有一個序列化器:

<service id="Shopware\Core\Content\ImportExport\DataAbstractionLayer\Serializer\Entity\ProductSerializer">
    <!-- ... -->
    <tag name="shopware.import_export.entity_serializer" priority="-400"/>
</service>

如果您的實體有一些需要特殊處理的字段,也許可以查看序列化程序以供參考。

您必須將您的實體添加到

供應商/shopware/administration/Resources/app/administration/src/module/sw-import-export/component/sw-import-export-edit-profile-general/index.js

supportedEntieties()方法

你可以這樣做:

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;
        }
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM