2

您好 Shopfiy 开发人员!

我通过 API 调用遇到了注释属性的问题。它曾经工作到一个月前,然后事情开始横向发展。有任何语法改变吗?这是我的代码片段,它在 for 循环中返回错误。

错误消息“未定义的索引:note_attribute 就在 foreach 行”

// Overwrite custom status field if it's defined in note-attributes
if(array_key_exists('note-attributes', $o))
{
    // For whatever reason, the note-attributes are formatted
    // differently if there's only one key => value pair
    // ( * see examples at end of this file )
    // If the note-attribute array has the key 'name' in it, it's just a single pair.
    // Otherwise, the note-attribute array would be numerically indexed with keys 0,1,2.. etc
    if(array_key_exists('name',$o['note-attributes']['note_attribute']))
    {
        if($o['note-attributes']['note_attribute']['name'] == "custom_status")
            $arr_tmp[7] = $o['note-attributes']['note_attribute']['value'] ;
    }
    else
    {
        foreach($o['note-attributes']['note_attribute'] as $na) //Fails here
        {
            if($na['name'] == "custom_status")
                $arr_tmp[7] = $na['value'] ;
        }
    }
}

非常感谢您的帮助。谢谢你。

4

1 回答 1

1

这里的问题是由于 XML 节点语法的变化;Shopify 有一个回归,在响应中更改note-attributesnote_attributes,然后又改回来了。

于 2012-09-16T14:36:18.163 回答