Shopware5.6.10升级至5.7.6后自定义console命令hpr:orders:export缺失
Shopware 5.6.10升级至5.7.6后第三方插件控制台命令丢失修复方案
问题背景
测试环境将Shopware 5系统从5.6.10版本升级到5.7.6版本后,控制台命令hpr:orders:export无法找到,该命令来自已停止官方支持的市场插件,可参考以下补丁方案修复。
复现现象
- 旧版本(Shopware 5.6.10 + PHP7.2)执行命令可正常匹配到对应命令:
php7.2 ./console |grep hpr hpr hpr:orders:export Starting the export (as defined in the plugin-config) of the orders. Options are mostly the same as the REST-API options.
- 升级后(Shopware 5.7.6 + PHP7.4)执行同样命令无输出:
php7.4 ./console |grep hpr (no output)
- 验证插件已正常启用:
php7.4 console sw:plugin:list|grep Order | HPrAutomaticOrderExport | Automatic XML Order-Export Standard | 3.7.1 | Windeit Software GmbH | Yes | Yes |
现有相关代码
命令类代码
namespace HPrAutomaticOrderExport\Components; use Exception; use Shopware\Commands\ShopwareCommand; use Shopware\Components\Plugin\ConfigReader; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class CLICommand extends ShopwareCommand { protected function configure() { $this->setName('hpr:orders:export'); $this->setDescription('Starting the export (as defined in the plugin-config) of the orders. Options are mostly the same as the REST-API options.'); $this->addOption('states', null, InputOption::VALUE_OPTIONAL, 'coma seperated list of order-states ids to filter output'); $this->addOption('statespayment', null, InputOption::VALUE_OPTIONAL, 'coma seperated list of payment-states ids to filter output'); $this->addOption('range', null, InputOption::VALUE_OPTIONAL, 'date range: startdate,enddate'); //TODO syntax for today - n days would be great!!!!!! $this->addOption('start', null, InputOption::VALUE_OPTIONAL, 'start index in list of orders (defaukt is 0, beginning of the list)'); $this->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'maximal count of orders to export (default is 100)'); $this->addOption('number', null, InputOption::VALUE_OPTIONAL, 'number of a single order'); $this->addOption('exportall', null, InputOption::VALUE_OPTIONAL, 'export all orders, ignore states'); } }
服务注册配置(services.xml)
<service id="hp_order_export_command" class="HPrAutomaticOrderExport\Components\CLICommand"> <tag name="console.command" /> <argument type="service" id="shopware.plugin.config_reader"/> <argument type="service" id="hp_order_export_service"/> </service>
修复方案
方案1(推荐,无配置修改)
在命令类CLICommand中添加静态默认命令名属性即可,无需修改其他代码:
class CLICommand extends ShopwareCommand { // 新增此行 public static $defaultName = 'hpr:orders:export'; protected function configure() { // 原有代码保持不变 } }
根因说明:Shopware 5.7升级了Symfony核心组件,新版控制台支持命令延迟加载,需要通过静态$defaultName属性识别命令名,仅在configure方法中调用setName无法被框架提前识别,导致命令列表中找不到对应命令。
方案2(兼容旧版,改配置)
如果不想修改插件代码,可在services.xml的命令标签中添加command属性显式指定命令名:
<tag name="console.command" command="hpr:orders:export" />
修改后清空Shopware缓存,即可正常调用命令。
补充说明:提问方因暂无使用需求已禁用该插件,本方案留存供其他遇到同类问题的开发者参考。
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

