You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento 2.4.3-p2批量更新API修复无效,寻求技术帮助

Magento 2.4.3-p2 批量异步更新商品 TypeError 问题解决建议

问题概述

调用rest/default/async/bulk/V1/products/bySku异步批量更新商品时触发类型错误:

TypeError: Argument 3 passed to Magento\Framework\Webapi\ServiceInputProcessor::process() must be of the type array, string given, called in .../vendor/magento/module-webapi-async/Controller/Rest/Asynchronous/InputParamsResolver.php on line 156 and defined in .../vendor/magento/framework/Webapi/ServiceInputProcessor.php:172

已应用官方修复PR但问题仍存在,以下是针对性解决步骤:


1. 补全请求头关键配置

确保请求头包含Content-Type: application/json,且$headers变量正确初始化。缺失该头会导致Magento无法将JSON字符串解析为数组,示例配置:

$headers = [
    'Authorization: Bearer YOUR_ACCESS_TOKEN',
    'Content-Type: application/json',
    'Content-Length: ' . strlen($samplePayload)
];

2. 修正请求体格式

异步批量接口要求请求体包裹在bulkItems字段中,而非直接传递数组。调整后的请求体格式:

$samplePayload = json_encode([
    'bulkItems' => [
        [
            'sku' => 'test123',
            'product' => [
                'price' => 1049.24
            ]
        ]
    ]
]);

3. 验证PR代码的完整应用

确认InputParamsResolver.php的修改逻辑是否正确:

  • 需确保在调用ServiceInputProcessor::process()前,已将原始请求体通过json_decode($rawBody, true)转换为数组
  • 检查156行附近代码,避免直接将字符串类型的请求体传入process方法

4. 清理Magento缓存

代码修改后必须清理缓存,确保修改生效:

bin/magento cache:clean
bin/magento cache:flush

5. 调试参数类型

在InputParamsResolver.php的156行前添加调试代码,确认传入参数类型:

// 临时调试代码
var_dump($inputParams);
die;

若输出为字符串,说明JSON解码逻辑未执行,需重新检查PR修改的代码实现。

内容的提问来源于stack exchange,提问作者user2029890

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 03:25:14