Magento通过SOAP从c#应用程序添加产品
本文关键字:添加 应用程序 通过 SOAP Magento | 更新日期: 2023-09-27 18:03:22
我正在尝试开发一个应用程序,使用c#将产品插入Magento。我有连接在这里工作的代码:http://www.magentocommerce.com/wiki/5_-_modules_and_development/web_services/using_soap_api_in_c_sharp但是我是c#的新手,可以用一个非常简单的例子来说明我如何添加一个产品,在PHP中这样做的API代码在这里:http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product example_2._product_createviewupdatedelete
任何帮助都非常感谢。
约翰MagentoService mservice = new MagentoService();
String mlogin = mservice.login("YOUR_USERNAME", "YOUR_API_KEY");
Debug.WriteLine(mlogin);
String productType = "simple";
String attributeSetId = "4"; // This is the ID of the Catalog Product Attribute Set
String productSku = "PRODUCT_SKU";
catalogProductCreateEntity[] cpce = new catalogProductCreateEntity[1];
// Some Code blocks here will follow....
catalogProductCreate[] cpc = mservice.catalogProductCreate(mlogin, productType, attributeSetId, productSku, cpce);
这就是它的工作原理。但是因为我不是一个。net/c#开发人员,所以我不能再帮助你了。
希望能有所帮助。
下面是一个简单的产品工作示例。
首先将服务引用添加到项目中。http://yourdomain.com/index.php/api/v2_soap/?wsdl
然后添加一些代码…
static Mage_Api_Model_Server_Wsi_HandlerPortTypeClient mservice;
mservice = new Mage_Api_Model_Server_Wsi_HandlerPortTypeClient();
mlogin = mservice.login("username", "apikey");
catalogProductCreateEntity newProduct = new catalogProductCreateEntity();
newProduct.name = prodName;
newProduct.description = prodDesc;
newProduct.short_description = prodShort;
newProduct.status = "1";
newProduct.price = prodPrice;
newProduct.tax_class_id = "2";
try
{
mservice.catalogProductCreate(mlogin, "simple", "4", prodSku, newProduct, null);
}
catch (Exception merror)
{
lastError = merror.Message;
}
类似....和一些额外的
static bool createCustomer(string dob, string email, string firstname, string lastname, string middlename, string prefix)
{
customerCustomerEntityToCreate newCustomer = new customerCustomerEntityToCreate();
newCustomer.dob = dob;
newCustomer.email = email;
newCustomer.firstname = firstname;
newCustomer.gender = 0;
newCustomer.genderSpecified = false;
newCustomer.lastname = lastname;
newCustomer.middlename = middlename;
newCustomer.password = "P@55w0rd!";
newCustomer.prefix = prefix;
newCustomer.suffix = "";
newCustomer.taxvat = "";
newCustomer.website_id = 1;
newCustomer.store_idSpecified = true;
newCustomer.group_id = 1;
newCustomer.store_id = 1;
try
{
mservice.customerCustomerCreate(mlogin, newCustomer);
}
catch (Exception merror)
{
lastError = merror.Message;
return false;
}
return true;
}
static bool updateCustomer(string dob, string email, string firstname, string lastname, string middlename, string prefix, int id)
{
customerCustomerEntityToCreate newCustomer = new customerCustomerEntityToCreate();
newCustomer.dob = dob;
newCustomer.email = email;
newCustomer.firstname = firstname;
newCustomer.gender = 0;
newCustomer.genderSpecified = false;
newCustomer.lastname = lastname;
newCustomer.middlename = middlename;
newCustomer.password = "P@55w0rd!";
newCustomer.prefix = prefix;
newCustomer.suffix = "";
newCustomer.taxvat = "";
newCustomer.store_idSpecified = true;
newCustomer.website_id = 2;
newCustomer.group_id = 2;
newCustomer.store_id = 2;
try
{
mservice.customerCustomerUpdate(mlogin,id, newCustomer);
}
catch (Exception merror)
{
lastError = merror.Message;
return false;
}
return true;
}
static void GetOrders(string dob, string email, string firstname, string lastname, string middlename, string prefix, int id)
{
filters mf = new filters();
complexFilter[] cpf = new complexFilter[1];
complexFilter mcpf = new complexFilter();
mcpf.key = "increment_id";
associativeEntity mas = new associativeEntity();
mas.key = "gt";
mas.value = "1";
mcpf.value = mas;
cpf[0] = mcpf;
mf.complex_filter = cpf;
salesOrderListEntity[] soe = mservice.salesOrderList(mlogin, mf);
if (soe.Length > 0)
{
foreach (salesOrderListEntity msoe in soe)
{
try
{
Console.WriteLine("" + msoe.billing_firstname + " " + msoe.subtotal);
}
catch (Exception merror)
{
Console.WriteLine("" + msoe.order_id + "" + merror.ToString());
}
}
}
}
HTH有人