public async Task <int> CreateCustomer( string email = "*****@*****.**", string firstname = "firstname", string lastname = "lastname", string password = "******", int websiteId = 0, int storeId = 0, int groupId = 0 ) { try { var sessionId = await this.GetSessionId().ConfigureAwait(false); var customerCustomerEntityToCreate = new customerCustomerEntityToCreate { email = email, firstname = firstname, lastname = lastname, password = password, website_id = websiteId, store_id = storeId, group_id = groupId }; var res = await this._magentoSoapService.customerCustomerCreateAsync(sessionId.SessionId, customerCustomerEntityToCreate).ConfigureAwait(false); return(res.result); } catch (Exception exc) { throw new MagentoSoapException(string.Format("An error occured during GetMagentoInfoAsync()"), exc); } }
static void Main(string[] args) { Navision_CustomerListService.CustomerList nv_Customer = new Navision_CustomerListService.CustomerList(); Navision_CustomerListService.CustomerList_PortClient client = new Navision_CustomerListService.CustomerList_PortClient(); Navision_CustomerListService.CustomerList[] nv_CustomerLists; client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; //client.ClientCredentials.Windows.ClientCredential.UserName = "******"; //client.ClientCredentials.Windows.ClientCredential.Password = "******"; //client.ClientCredentials.Windows.ClientCredential.Domain = "122.166.222.116"; nv_CustomerLists = client.ReadMultiple(null, null, 10000); MagentoConnectService.PortTypeClient mage_client = new MagentoConnectService.PortTypeClient(); DBConnect db = new DBConnect(); int newCustomerCreateID = 0; int createAddressID = 0; string token_id = ""; filters myfilter = new filters(); token_id = mage_client.login("webserviceuser", "apikey"); Hashtable hsc = db.fetch_CustomerMapping(); for (int i = 0; i < nv_CustomerLists.Length; i++) { // Create Customer customerCustomerEntityToCreate customerCreate = new customerCustomerEntityToCreate(); try { customerCreate.firstname = nv_CustomerLists[i].Name; customerCreate.lastname = "."; customerCreate.middlename = ""; customerCreate.password = "******"; customerCreate.store_id = 1; customerCreate.store_idSpecified = true; customerCreate.website_id = 1; customerCreate.website_idSpecified = true; customerCreate.group_id = 1; customerCreate.group_idSpecified = true; customerCreate.suffix = "P"; customerCreate.email = nv_CustomerLists[i].E_Mail; customerCreate.gender = 1; //1-Male;2-Female customerCreate.genderSpecified = true; //customer address customerAddressEntityCreate customerAddress = new customerAddressEntityCreate(); if (nv_CustomerLists[i].Location_Code == null) { customerAddress.city = "NA"; } else { customerAddress.city = nv_CustomerLists[i].Location_Code; } customerAddress.region_id = 2; //CountryID customerAddress.region_idSpecified = true; if (nv_CustomerLists[i].Country_Region_Code == null) { customerAddress.country_id = "NA"; } else { customerAddress.country_id = nv_CustomerLists[i].Country_Region_Code; } customerAddress.fax = nv_CustomerLists[i].Fax_No; customerAddress.firstname = nv_CustomerLists[i].Name; customerAddress.lastname = "."; customerAddress.middlename = ""; string[] streettxt = { nv_CustomerLists[i].Address }; customerAddress.street = streettxt; customerAddress.postcode = nv_CustomerLists[i].Post_Code; customerAddress.prefix = "M"; customerAddress.suffix = "P"; // customerAddress.street = nv_CustomerLists[i].Address.ToString(); if (nv_CustomerLists[i].Phone_No == null) { customerAddress.telephone = "NA"; } else { customerAddress.telephone = nv_CustomerLists[i].Phone_No; } //If you specify 'true' for is_default_billing and is_default_shipping. Then this address will be your default shipping and billing. Otherwise none. customerAddress.is_default_billing = true; customerAddress.is_default_shipping = true; if (db.fetch_Customer(nv_CustomerLists[i].No.ToString())) { mage_client.customerCustomerUpdate(token_id, Convert.ToInt16(hsc[nv_CustomerLists[i].No]), customerCreate); } else { newCustomerCreateID = mage_client.customerCustomerCreate(token_id, customerCreate); createAddressID = mage_client.customerAddressCreate(token_id, newCustomerCreateID, customerAddress); db.InsertCustomerMapping(nv_CustomerLists[i].No, newCustomerCreateID.ToString(), nv_CustomerLists[i].E_Mail); db.InsertLog("Customer", nv_CustomerLists[i].No, "Navision Customer Code", "SUCCESS"); } } catch (Exception ex) { MNC_Product_Sync.ErrorLog errLog = new MNC_Product_Sync.ErrorLog(); errLog.LogError("C:\\MNC_Logs", "Customer :" + ex.Message); db.InsertLog("Customer", nv_CustomerLists[i].No, ex.Message, "FAILED"); } finally { //mage_client.endSession(token_id); } } mage_client.endSession(token_id); }
public void create_customer(List <Models.csv_import> customer) { int i = 1; foreach (var item in customer) { try { MagentoService mservice = new MagentoService(); string mlogin = mservice.login("admin", "Interconnection123!"); customerCustomerEntityToCreate create_customer = new customerCustomerEntityToCreate(); create_customer.password = "******"; create_customer.email = item.EMail; create_customer.firstname = item.First_Name; create_customer.lastname = item.Last_Name; create_customer.website_id = 5; create_customer.website_idSpecified = true; create_customer.store_id = 5; create_customer.store_idSpecified = true; if (string.IsNullOrEmpty(item.EMail)) { create_customer.email = create_customer.firstname + create_customer.lastname + "@noemail.com"; } switch (item.Customer_Type) { case "Low Income": create_customer.group_id = 14; create_customer.group_idSpecified = true; break; case "NON-PROFIT": create_customer.group_id = 15; create_customer.group_idSpecified = true; break; default: create_customer.group_id = 13; create_customer.group_idSpecified = true; break; } int customer_id = mservice.customerCustomerCreate(mlogin, create_customer); if (!string.IsNullOrEmpty(item.Phone_1)) { customerAddressEntityCreate address = new customerAddressEntityCreate(); address.telephone = item.Phone_1; address.firstname = item.First_Name; address.lastname = item.Last_Name; address.company = item.Company; address.country_id = "US"; address.city = "Seattle"; address.postcode = "00000"; address.region = "62"; address.street = new string[] { "Defaul Address" }; address.is_default_shipping = true; address.is_default_shippingSpecified = true; address.is_default_billing = true; address.is_default_billingSpecified = true; mservice.customerAddressCreate(mlogin, customer_id, address); System.Diagnostics.Debug.WriteLine("complete " + i++); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } } }