开发者

Magento add a product via SOAP from C# application

I am trying to develop an application to insert a product using C# into Magento. I have the code for connecting in here working: http://www.magentocommerce.com/wiki/5_-_modules_and_development/web_services/using_soap_api_in_c_sharp but I am new to c# and could do with a really simp开发者_Python百科le example of how I go about adding a product, the API code for doing this in PHP is here: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#example_2._product_createviewupdatedelete

Any help greatly appreciated.

John


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);

This is how it will work. But since I'm not a dotNet / C# developer, so I'll not be able to help you any further.

Hope it helps.


Here goes a simple product working sample..

First add the service reference to your project. http://yourdomain.com/index.php/api/v2_soap/?wsdl

Then add some code...

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;
}

Something along those lines.... and some extra

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 someone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜