簡體   English   中英

裝飾 Shopware6 api controller 用於將插件閱讀器數據保存到實體

[英]Decorating Shopware6 api controller for saves pluginreader data to entity

安裝插件並編輯配置中的可用字段后,我想將這些字段保存到我的實體中。

所以我創建了 Config class 以從插件配置中獲取字段,例如:

class Config
{
    public const SYSTEM_CONFIG_DOMAIN = 'myEntity.config.';

    /** @var SystemConfigService $systemConfigService */
    protected static $systemConfigService;

    public function __construct(SystemConfigService $systemConfigService)
    {
        self::$systemConfigService = $systemConfigService;
    }
}

public static function message(): string
{
    return (string)self::$systemConfigService->get(self::SYSTEM_CONFIG_DOMAIN . 'message');
}

我在平台上發現了這樣一個 controller:

/**
 * @Route("/api/v{version}/_action/system-config/batch", name="api.action.core.save.system-config.batch", methods={"POST"})
 */
public function batchSaveConfiguration(Request $request): JsonResponse
{
    foreach ($request->request->all() as $salesChannelId => $kvs) {
        if ($salesChannelId === 'null') {
            $salesChannelId = null;
        }
        $this->saveKeyValues($salesChannelId, $kvs);
    }

    //save to my entity here
    return new JsonResponse([$request->request->all()]);
}

在這個 controller 中,我想將來自 pluginConfig 的消息添加到我的實體中。 這是個好主意嗎?我該如何感謝它? 因為我只是在學習 sw6,我可以要求比平時更多的代碼嗎?

如果您只想將數據添加到插件配置中,您應該使用配置安裝程序而不是 controller。

暫無
暫無

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

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