我想将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,但是没有运气。
我该怎么做才能继续进行调试?
谢谢。
最佳答案
在处理 map 和按键时,它看起来像在工作:
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]
关于xml - Groovy RPC和Magento API:product_attribute.create和无效的请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28624094/