Groovy RPC& Magento API:product_attribute.create&无效的请求参数

时间:2015-02-20 07:57:23

标签: xml magento grails groovy rpc

我想使用Magento(1.9)的XML-RPC API和Groovy,并能够连接和登录。

这很好用:

def api = new XMLRPCServerProxy("http://magentourl/api/xmlrpc", true)
api.login("user", "key")
return api.call(key, "catalog_product.list")

此活动有效:

api.call(key, "product_attribute.info", [132])

但我在添加新产品属性方面遇到了麻烦:

def code = "myattribute-unique"
def frontendInput = "text"
def scope = "global"
def defaultValue = "default-Value"
int unique = 1
int required = 1
String[] applyTo = ["simple", "grouped"].toArray()
int configurable = 1
int searchable = 1
int visibleAdvancedSearch = 1
int comparable = 1
int usedPromoRules = 1
int visibleOnFront = 1
int usedProductListing = 1
def additionalFields = ["frontend_class": "validate-email", "is_html_allowed_on_front": true, "used_for_sort_by": true]
def frontendLabel = [[0, "frontend-label1"], [1, "frontend-label2"]].toArray()    
def array = [code, frontendInput, scope, defaultValue, unique, required, applyTo, configurable, searchable, visibleAdvancedSearch, comparable, usedPromoRules, visibleOnFront, usedProductListing, additionalFields, frontendLabel]    

def result = api.call(key, "product_attribute.create", array)

我收到此错误:

Class uk.co.wilson.net.xmlrpc.XMLRPCFailException
Message Invalid request parameters.

我尝试将属性初始化为Array而不是Groovy-dynamic def-way,但没有运气。

我可以做些什么来帮助我调试?

感谢。

1 个答案:

答案 0 :(得分:0)

当继续使用地图和键时,它看起来很有效:

def code = "a_select_1"
def frontendInput = "select"

def array = [**attribute_code**: code, frontend_input: frontendInput, scope: scope, default_value: defaultValue, is_unique: unique, is_required: required, apply_to: applyTo, is_configurable: configurable, is_searchable: searchable, is_visible_in_advanced_search: visibleAdvancedSearch, is_comparable: comparable, is_used_for_promo_rules: usedPromoRules, is_visible_on_front: visibleOnFront, used_in_product_listing: usedProductListing, additional_fields: additionalFields, frontend_label: frontendLabel]