1

我正在用 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,但这里显示的 PHP 示例并没有真正帮助我。

任何输入将不胜感激。

先感谢您。

4

2 回答 2

1

你已经在那里了。我认为您的问题无法将 PHP 参数数组转换为 Python 键值对。如果是这样,这将对您有所帮助。以及需要在创建产品之前使用 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) 
于 2013-03-11T10:19:32.427 回答
0
suds.TypeNotFound: Type not found: 'productData'

Because the productData format is not right. You may want to change from
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]}]

to
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]}

It works for me.

于 2013-05-30T01:41:55.403 回答