我正在Python中实现一个服务,它通过SOAP v2与Magento交互。到目前为止,我能够获得这样的产品列表:
import suds
from suds.client import Client
wsdl_file = 'http://server/api/v2_soap?wsdl=1'
user = 'user'
password = 'password'
client = Client(wsdl_file) # load the wsdl file
session = client.service.login(user, password) # login and create a session
client.service.catalogProductList(session)
但是,我无法创建产品,因为我真的不知道应该发送什么数据以及如何发送它。我知道我必须使用的方法是catalogProductCreate,但显示here的PHP示例对我没有帮助。
任何意见都会受到赞赏。
提前谢谢。
答案 0 :(得分:1)
你已经在那里了。我认为你的问题是无法将PHP数组转换为传递给Python Key Value对。如果是这样的话,这会对你有所帮助。在创建产品之前,还需要使用catalogProductAttributeSetList设置属性集
attributeSets = client.service.catalogProductAttributeSetList(session)
#print attributeSets
# Not very sure how to get the current element from the attributeSets array. hope the below code will work
attributeSet = attributeSets[0]
product_details = [{'name':'Your Product Name'},{'description':'Product description'},{'short_description':'Product short description'},{'weight':'10'},{ 'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]
client.service.catalogProductCreate(session , 'simple', attributeSet.set_id, 'your_product_sku',product_details)
答案 1 :(得分:0)
suds.TypeNotFound: Type not found: 'productData'
因为productData格式不正确。您可能想要从更改
product_details = [{'name':'Your Product Name'},{'description':'Product description'}, {'short_description':'Product short description'},{'weight':'10'},{ 'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]
要
product_details = {'name':'Your Product Name','description':'Product description', 'short_description':'Product short description','weight':'10', 'status':'1','url_key':'product-url-key','url_path':'product-url-path','visibility' :4,'price':100,'tax_class_id':1,'categories': [2],'websites': [1]}
它对我有用。