【问题标题】:Ez.Newsletter.MagentoApi product_attribute.addOptionEz.Newsletter.MagentoApi product_attribute.addOption
【发布时间】:2017-05-16 15:48:22
【问题描述】:

我在 Internet 上找到了 Ez.Newsletter.MagentoApi C# 项目。 我认为它是测试 Magento SOAP API 的好工具。

但是在为 WEEKS 编写了一些代码后,我决定问一个问题。

在项目中,AddOption 中没有ProductAttributeOption 的示例(Link)。

这是我添加到 Api 解决方案中的公共方法:

public static bool addOption(string apiUrl, string sessionId, object[] args)
    {
        IProductAttributeOption prox = (IProductAttributeOption)XmlRpcProxyGen.Create(typeof(IProductAttributeOption));
        prox.Url = apiUrl;
        return prox.addOption(sessionId, _catalog_product_attribute_add_option, args);
    }

这是添加选项的代码:

bool OptionAdded = ProductAttributeOption.addOption(apiUrl, sessionId, new object[] {
             attributeCode,
             new object[] {
                 new object[] {
                     "0", //store_id
                     "New Label Name" //value
                 },
                 "0", //orderid
                 "0"  //is_default
             }
         });

但是服务器的错误是这样的:

An unhandled exception of type 'CookComputing.XmlRpc.XmlRpcFaultException' occurred in CookComputing.XmlRpcV2.dll Additional information: Server returned a fault exception: [108] Default option value is not defined

【问题讨论】:

  • 它与 'is_default' 选项有关。我做错了什么?
  • 有谁知道如何转换这段代码: $label = array ( array( "store_id" => array("0"), "value" => "some random data" ) ); $data = array( "label" => $label, "order" => "10", "is_default" => "1" );转 C#

标签: c# magento soap xml-rpc


【解决方案1】:

我自己也遇到过这个问题。我们使用 Python 和 Magento1.9 Xml-RPC

您当前的格式与我最初所做的非常相似:

    {'label': {'store_id': '0','value':'Purple'}, 'is_default': 0, 'order': 0}

经过一番尝试,将标签值包装在另一个列表中就可以了:

    {'label': [{'store_id': '0','value':'Purple'}], 'is_default': 0, 'order': 0}

这是我的 5 美分。希望对你有所帮助。

【讨论】: