symfony Shopware 6插件:如何删除/迁移布尔配置到多选配置

ddhy6vgd  于 7个月前  发布在  PWA
关注(0)|答案(1)|浏览(90)

我有一个Shopware 6插件,目前使用布尔配置reviewSkipModeration值,自动发布通过插件提交的任何评论:

<input-field type="bool">
  <name>reviewSkipModeration</name>
  <label>Accept reviews automatically</label>
  <defaultValue>true</defaultValue>
</input-field>

我想将其迁移到具有以下选项的多选配置。:

  • 没有一
  • 0星
  • 1颗星星
  • 2星
  • 3星
  • 4星
  • 5星

在我的更新方法中,我如何正确迁移数据,以便:

  • 真实Map0星
  • 假Map到无
  • 和自动发布评论超过一定的星星评级阈值,例如,3星.但我需要这样做,而不破坏现有的功能,为用户谁已经安装了插件.

并删除旧的布尔配置值?
我的更新功能的插件看起来像:

public function update(UpdateContext $context): void {
        parent::update($context);
    }

但我不知道如何处理Map和删除。任何帮助是感激!

6tr1vspr

6tr1vspr1#

配置存储在数据库中,可以直接使用MySQL查询进行读/写,或者您可以使用SystemConfigService。

public function update(UpdateContext $context): void
{
    parent::update($context);

    // Get config service from the container
    $configService = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
    
    // Get the current value of the configuration
    $currentValue = $configService->getBool('YourPlugin.config.reviewSkipModeration');
    
    // Specify the new value
    $value = 'None'
    
    if($currentValue === true) {
        $value = '0 Stars'
    }
    
    // Set the specified value as default
    $configService->set('YourPlugin.config.reviewSkipModeration', $value);
}

下面是一个基本的示例,但请记住,您可能需要处理更新所有销售渠道配置和默认配置(saleschannelId = null)的问题

$configService->getBool('YourPlugin.config.reviewSkipModeration', $salesChannelId);
$configService->set('YourPlugin.config.reviewSkipModeration', $value, $salesChannelId);

相关问题