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

使用Prestapyt从Odoo更新PrestaShop产品价格时遇参数错误

解决PrestaShop API编辑产品时"Unsupported parameters"错误

问题原因

你遇到的错误是因为直接将prestashop.get获取的完整产品数据传回编辑接口,其中包含大量PrestaShop API不支持修改的字段(比如只读的date_add、date_upd,关联字段associations等),这些字段会被接口判定为非法参数。

解决方案

不要传递全量产品数据,只构造包含需要更新的字段(price)和产品ID的最小数据结构提交给编辑接口即可。

修改后的代码

def set_prestashop_price(self):
    prestashop_url = "https://myurl.com/api"
    prestashop_key = "KEY"

    prestashop = PrestaShopWebServiceDict(prestashop_url, prestashop_key)

    for template in self:
        response = prestashop.search('products', {'filter[reference]': template.default_code})
        if response:
            product_id = response[0]
            
            # 构造最小更新数据,仅包含必要字段
            update_product_data = {
                'id': product_id,
                'price': str(template.list_price)
            }
            
            try:
                response = prestashop.edit('products', product_id, update_product_data)
                template.message_post(body=f"Product template {template.default_code} updated on Prestashop")
            except Exception as e:
                template.message_post(body=f"Failed to update product template {template.default_code} on Prestashop. Error: {str(e)}")
        else:
            template.message_post(body=f"No product found on Prestashop for {template.default_code}")

额外注意事项

  • 确保price的格式符合PrestaShop要求:必须是字符串类型,小数部分使用英文点号(.)分隔,比如"19.99"
  • 如果你的PrestaShop是多店铺模式,可能需要在更新数据中添加id_shop字段指定目标店铺
  • 确认API密钥拥有产品编辑的权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 05:43:26