2013-03-11 304 views
1

我执行Python中的服务,通过SOAP V2与Magento的交互。到目前为止,我能够拿到的产品列表做这样的事情:Magento的产品创新通过SOAP V2

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示例并不能真正帮助我。

任何输入,将不胜感激。

预先感谢您。

回答

1

你在那里了。我认为你的问题是无法翻译参数的PHP数组传递到Python Key Value对。如果是这种情况,这将有助于你一点。在创建之前的产品

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) 
+0

非常感谢你,这实在是我的帮助。不过,我的服务电话后发现了以下错误:'suds.TypeNotFound:类型未找到:“productData'' – davids 2013-03-11 11:18:53

+0

欢迎您;-)没有十分的把握,进一步帮助你这个,因为我已经没有任何消耗使用python web服务......从根本上说,所有你需要检查是什么请求发送,什么你得到的回应...我希望下面的主题帮助您进一步在这一行http://stackoverflow.com/questions/7179888/suds -throwing-error-type-not-found-consume-soap-service和http://stackoverflow.com/questions/8982669/suds-typenotfound-type-not-found-merchantcode – Haijerome 2013-03-11 12:04:06

0
suds.TypeNotFound: Type not found: 'productData' 

因为productData格式是不正确的,以及需要设置的属性使用catalogProductAttributeSetList集。你可能想改变
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]}

这对我的作品。

相关问题