static void Main(string[] args) { var siteUrl = "http://test.rainstormstudio.com.au/maghelpdesk"; var username = "******"; var password = "******"; var service = new MagentoService(); var isconnected = service.IsConnected(siteUrl, username, password); Console.WriteLine("MagentoService Connected : " + isconnected.ToString()); var token = service.GetToken(siteUrl, username, password).Result; Console.WriteLine("GetToken : " + isconnected.ToString()); var ticketId = CreateTicket(service, siteUrl, token); UpdateTicket(service, siteUrl, token, ticketId); GetTickets(service, siteUrl, token); var messageId = SendMessage(service, siteUrl, token, ticketId); UpdateMessange(service, siteUrl, token, messageId); GetMessages(service, siteUrl, token); }
static int CreateTicket(MagentoService service, string siteUrl, string token) { var createTicketRequest = new CreateTicketRequest() { connection_id = "1", store_id = "1", department_id = "1", agent_id = "1", status = "unread", type = "messsage", item_id = "listing123", subject = "listing", creator_id = "", creator_name = "TESTUSER_smarthub", creator_email = "*****@*****.**", recipient_id = "daolavi", created_at = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), last_modified_at = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), note = "", }; var result = service.CreateTicket(siteUrl, token, createTicketRequest); if (result.HasError) { Console.WriteLine("CreateTicket " + result.Error); } else { Console.WriteLine("CreateTicket " + result.Result.ToString()); } return(result.Result); }
static int SendMessage(MagentoService service, string siteUrl, string token, int ticketId) { var sendMessageRequest = new SendMessageRequest() { message = "message", type = "cutomer message", sender_id = "", sender_name = "daolavi", sender_email = "*****@*****.**", ticket_id = ticketId.ToString(), created_at = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), last_modified_at = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), note = "sendMessageRequest", }; var result = service.SendMessage(siteUrl, token, sendMessageRequest); if (result.HasError) { Console.WriteLine("SendMessage " + result.Error); } else { Console.WriteLine("SendMessage " + result.Result.ToString()); } return(result.Result); }
public void GetProductList() { MagentoService _magento = new MagentoService(); string session = _magento.login("sarath", "qwerty"); catalogProductLinkEntity[] relatedProduct = _magento.catalogProductLinkList(session, "grouped", "Bags, Belts and Wallets", null); }
public salesOrderEntity get_order_detail(string order_id) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); var result = mservice.salesOrderInfo(mlogin, order_id); return(result); }
public catalogProductEntity[] get_all_product() { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); var result = mservice.catalogProductList(mlogin, null, ""); return(result); }
protected void upsell_sale(MagentoService mservice, string mlogin, string brand_sql, string search_family, string source_sku) { string storeview = "1"; if (search_family.Contains("OEM")) { storeview = "3"; } string sku_family = search_family; if (sku_family.Contains("DK")) { search_family = "DK"; } else if (sku_family.Contains("LP")) { search_family = "LP"; } filters filter = new filters(); filter = addFilter(filter, "sku_family", "like", "%" + search_family + "%"); filter = addFilter(filter, "status", "eq", "1"); var result = mservice.catalogProductList(mlogin, filter, storeview); string[] sku_arr = new string[result.Length]; int i = 0; //get result sku foreach (catalogProductEntity product in result) { sku_arr[i] = product.sku; i += 1; } //get stock level var result2 = mservice.catalogInventoryStockItemList(mlogin, sku_arr); foreach (catalogInventoryStockItemEntity product in result2) { string qty_sku = product.sku; Double qty = double.Parse(product.qty); if (qty > 0) { catalogProductLinkEntity assign = new catalogProductLinkEntity(); assign.position = "1"; // inject related listing mservice.catalogProductLinkUpdate(mlogin, "up_sell", source_sku, qty_sku, assign, "sku"); } } mservice.Dispose(); }
public salesOrderListEntity[] get_open_orders() { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); filters mf = new filters(); complexFilter[] cpf = new complexFilter[1]; complexFilter mcpf = new complexFilter(); mcpf.key = "status"; associativeEntity mas = new associativeEntity(); mas.key = "in"; mas.value = "pending,processing,approved_clearsale,analysing_clearsale,pending_clearsale"; mcpf.value = mas; cpf[0] = mcpf; //mcpf = new complexFilter(); //mcpf.key = "status"; //mas = new associativeEntity(); //mas.key = "eq"; //mas.value = "processing"; //mcpf.value = mas; //cpf[1] = mcpf; //mcpf = new complexFilter(); //mcpf.key = "status"; //mas = new associativeEntity(); //mas.key = "eq"; //mas.value = "approved_clearsale"; //mcpf.value = mas; //cpf[2] = mcpf; //mcpf = new complexFilter(); //mcpf.key = "status"; //mas = new associativeEntity(); //mas.key = "eq"; //mas.value = "analysing_clearsale"; //mcpf.value = mas; //cpf[3] = mcpf; //mcpf = new complexFilter(); //mcpf.key = "status"; //mas = new associativeEntity(); //mas.key = "eq"; //mas.value = "pending_clearsale"; //mcpf.value = mas; //cpf[4] = mcpf; mf.complex_filter = cpf; var soe = mservice.salesOrderList(mlogin, mf); return(soe); }
public void GetOrdersAsync_ExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, null) { MagentoServiceLowLevelRest = this._magentoServiceLowLevelRestThrowExceptionStub, MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; Assert.Throws <MagentoCommonException>(async() => await magentoService.GetOrdersAsync().ConfigureAwait(false)); }
void Awake() { if (mInstance == null) { mInstance = this; } else { Debug.Log("Should not reach here"); } }
public void PopulateAccessTokenAndAccessTokenSecret_ExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, null) { MagentoServiceLowLevelRest = this._magentoServiceLowLevelRestThrowExceptionStub, MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; //------------ Act //------------ Assert Assert.Throws <MagentoCommonException>(() => magentoService.PopulateAccessTokenAndAccessTokenSecret("qwe", "qwe", "qwe")); }
public void InitiateDesktopAuthentication_ExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, null) { MagentoServiceLowLevelRest = this._magentoServiceLowLevelRestThrowExceptionStub, MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; //------------ Act //------------ Assert Assert.Throws <MagentoCommonException>(() => magentoService.InitiateDesktopAuthentication()); }
public void RequestVerificationUri_ByDateExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, null) { MagentoServiceLowLevelRest = this._magentoServiceLowLevelRestThrowExceptionStub, MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; //------------ Act //------------ Assert Assert.Throws <MagentoCommonException>(() => magentoService.RequestVerificationUri()); }
public void PingSoapAsync_ByDateExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, new MagentoConfig()) { MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; //------------ Act //------------ Assert Assert.ThrowsAsync <MagentoCommonException>(async() => await magentoService.PingSoapAsync().ConfigureAwait(false)); }
public void Setup() { this._magentoServiceNotAuth = new MagentoService(new MagentoNonAuthenticatedUserCredentials( this._consumer.Key, this._consumer.Secret, this._authorityUrls.MagentoBaseUrl )); NetcoLogger.LoggerFactory = new NLogLoggerFactory(); this._magentoServiceNotAuth.AfterGettingToken += this._testData.CreateAccessTokenFile; }
public Boolean cancel_order(string orderID, string status) { bool sucess = false; MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); // sucess = mservice.salesOrderCancel(mlogin, orderID); sucess = mservice.salesOrderAddComment(mlogin, orderID, status, null, null); return(sucess); }
public void UpdateInventoryAsync_ByDateExceptionOccured_ExceptionThrown() { //------------ Arrange var magentoService = new MagentoService(this._magentoAuthenticatedUserCredentials, null) { MagentoServiceLowLevelSoap = this._magentoServiceLowLevelSoapThrowExceptionsStub }; //------------ Act //------------ Assert Assert.ThrowsAsync <MagentoCommonException>(async() => await magentoService.UpdateInventoryAsync(new List <Inventory> { new Inventory() }).ConfigureAwait(false)); }
protected void get_magento_list(string source_sku) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("chisan", "uwoqyx4y87ymx47jcwswgy7alkzpeub8"); //retriving list of product from storeview //para @sessionid = login info //@ filter = searchfilter @store id = see below //store id : 1 = Main Website Store, 2= Low Income Store, 3 = Retail Store string search_family = ""; string brand_sql = ""; string temp_serial = ""; //************************ //filter server selection* //************************ MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new MySql.Data.MySqlClient.MySqlConnection(); mySqlConnection.ConnectionString = "server=us-cdbr-azure-west-c.cloudapp.net;uid=b9067d3066d876;pwd=4d1a509d;database=ic_database"; MySqlCommand cmd2 = new MySqlCommand("select (select pallet from rediscovery where ictag='" + asset_tag_text.Text + "') as pallet,(select serial from rediscovery where ictag='" + asset_tag_text.Text + "') as serial,(select Manufacture from production_log where serial='" + temp_serial + "') as Manufacture ", mySqlConnection); mySqlConnection.Open(); MySqlDataReader reader = cmd2.ExecuteReader(); while (reader.Read()) { search_family = reader["pallet"].ToString(); temp_serial = reader["serial"].ToString(); brand_sql = reader["Manufacture"].ToString(); } mySqlConnection.Close(); search_family = search_family.Substring(0, search_family.IndexOf("/") + 1); if (brand_sql == "Hewlett-Packard") { brand_sql = "HP "; } brand_sql = brand_sql.Substring(0, brand_sql.IndexOf(" ") + 1); brand_sql = brand_sql.Replace(" ", ""); related_sale(mservice, mlogin, brand_sql, search_family, source_sku); cross_sale(mservice, mlogin, search_family, source_sku); upsell_sale(mservice, mlogin, brand_sql, search_family, source_sku); related_text.Text = ""; }
//use for retail picklist public int retail_quick_import(Models.retail_quick_import retail) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); catalogProductCreateEntity create = new catalogProductCreateEntity(); catalogCategoryEntity add_cat = new catalogCategoryEntity(); catalogInventoryStockItemUpdateEntity stock_data = new catalogInventoryStockItemUpdateEntity(); stock_data.qty = "1"; stock_data.manage_stock = 1; stock_data.use_config_manage_stock = 0; stock_data.is_in_stock = 1; create.description = retail.desc; create.name = retail.name; create.price = retail.price; create.short_description = retail.short_desc; create.status = retail.status; create.visibility = retail.visible; create.weight = retail.weight; create.website_ids = retail.webistes; create.tax_class_id = retail.tax_id; create.stock_data = stock_data; associativeEntity[] attributes = new associativeEntity[3]; attributes[0] = new associativeEntity(); attributes[0].key = "vendor_id"; attributes[0].value = "11"; attributes[1] = new associativeEntity(); attributes[1].key = "approval"; attributes[1].value = "2"; attributes[2] = new associativeEntity(); attributes[2].key = "vendor_sku"; attributes[2].value = retail.sku + "_vendor"; catalogProductAdditionalAttributesEntity additionalAttributes = new catalogProductAdditionalAttributesEntity(); additionalAttributes.single_data = attributes; create.additional_attributes = additionalAttributes; int p_id = mservice.catalogProductCreate( mlogin, retail.type, retail.attr, retail.sku, create, "5"); mservice.catalogCategoryAssignProduct(mlogin, 2, retail.sku, "0", "SKU"); return(p_id); }
//login to magento with soap_api protected void get_magento_detail() { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123"); //retriving list of product from storeview //para @sessionid = login info //@ filter = searchfilter @store id = see below //store id : 1 = Main Website Store, 2= Low Income Store, 3 = Retail Store var result = mservice.catalogProductInfo(mlogin, "ICL1296", "1", null, null); mservice.Dispose(); }
public bool enable_product(string sku) { bool result; try { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); var item_to_edit = new catalogProductCreateEntity(); item_to_edit.status = "1"; result = mservice.catalogProductUpdate(mlogin, sku, item_to_edit, "", "SKU"); } catch { result = false; } return(result); }
static void GetMessages(MagentoService service, string siteUrl, string token) { var getMesssagesRequest = new GetMessagesRequest() { connection_id = "1", from = new DateTime(2017, 7, 1).ToString("yyyy-MM-dd hh:mm:ss"), to = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), }; var result = service.GetMessages(siteUrl, token, getMesssagesRequest); if (result.HasError) { Console.WriteLine("GetMessages " + result.Error); } else { Console.WriteLine("GetMessages " + result.Result.Count); } }
public catalogInventoryStockItemEntity[] check_product(string sku) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); string[] sku_arr = { sku }; catalogInventoryStockItemEntity[] result = null; try { result = mservice.catalogInventoryStockItemList(mlogin, sku_arr); return(result); } catch { } return(result); }
//this is currently connect to the dev site's SOAP Api //*** remeber to change it back to connect all SOAP API after live*** public void quick_update(string qty, string sku, string path) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); catalogInventoryStockItemUpdateEntity qty_update = new catalogInventoryStockItemUpdateEntity(); qty_update.manage_stockSpecified = true; qty_update.is_in_stockSpecified = true; qty_update.use_config_manage_stockSpecified = true; qty_update.manage_stock = 1; qty_update.qty = qty; if (qty == "0") { qty_update.is_in_stock = 0; } else { qty_update.is_in_stock = 1; } qty_update.use_config_manage_stock = 1; mservice.catalogInventoryStockItemUpdate( mlogin, sku, qty_update); //catalogProductAttributeMediaCreateEntity photo = new catalogProductAttributeMediaCreateEntity(); //string image64 = image_to_64(path); //var imageEntity = new catalogProductImageFileEntity(); //imageEntity.content = image64; //imageEntity.name = "photo1"; //imageEntity.mime = "image/jpeg"; //photo.file = imageEntity; //photo.label = "label"; //photo.position = "0"; //photo.exclude = "0"; //photo.types = new[] { "image", "small_image", "thumbnail" }; //mservice.catalogProductAttributeMediaCreate(mlogin, retail.p_id, photo, "", "ID"); }
protected IMagentoService CreateMagentoService(string apiUser, string apiKey, string accessToken, string accessTokenSecret, string consumerKey, string consumerSecret, string magentoBaseUrl, string requestTokenUrl, string authorizeUrl, string accessTokenUrl, string magentoVersionByDefault, int getProductsMaxThreads, int sessionLifeTime, bool supressExc, ThrowExceptionIfFailed onUpdateInventory = ThrowExceptionIfFailed.OneItem) { var magentoService = new MagentoService(new MagentoAuthenticatedUserCredentials( accessToken, accessTokenSecret, magentoBaseUrl, consumerSecret, consumerKey, apiUser, apiKey, getProductsMaxThreads, sessionLifeTime, true ), string.IsNullOrWhiteSpace(magentoVersionByDefault) ? null : new MagentoConfig() { VersionByDefault = magentoVersionByDefault, OnUpdateInventory = onUpdateInventory }); magentoService.InitAsync(supressExc).Wait(); return(magentoService); }
public bool update_price(string sku, string price) { bool success; try { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); catalogProductCreateEntity create = new catalogProductCreateEntity(); create.price = price; mservice.catalogProductUpdate(mlogin, sku, create, null, null); success = true; return(success); } catch { success = false; return(success); } }
public bool FulfillOrder(UserAccount userAccount, string orderID, string trackingNumber, string carrier) { try { DataModelEntities context = new DataModelEntities(); MagentoService service = new MagentoService(); service.Url = userAccount.Application_Name; string sessionID = service.login(userAccount.Config_Value1, userAccount.Config_Value2); string result = service.salesOrderShipmentCreate(sessionID, orderID, null, null, 0, 0); int trackingResult = service.salesOrderShipmentAddTrack(sessionID, orderID, carrier, "Tracking", trackingNumber); return true; } catch (Exception ex) { Logging.WriteLog(LogType.Error, "Magento Fulfill Order - OrderID : " + orderID + ": " + ex.Message); return false; } }
static void UpdateMessange(MagentoService service, string siteUrl, string token, int messageId) { var updateMessageRequest = new UpdateMessageRequest() { message_id = messageId.ToString(), message = "updating message", type = "customer message", modified_date = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), note = "updateMessageRequest", }; var result = service.UpdateMessage(siteUrl, token, updateMessageRequest); if (result.HasError) { Console.WriteLine("UpdateMessange " + result.Error); } else { Console.WriteLine("UpdateMessange " + result.Result.ToString()); } }
public void PingRestAsync_IncorrectConsumerKey_ThrowException() { //------------ Arrange //------------ Act Action act = () => { var service = new MagentoService(new MagentoAuthenticatedUserCredentials( this._testData.GetMagentoAccessToken().AccessToken, this._testData.GetMagentoAccessToken().AccessTokenSecret, this._testData.GetMagentoUrls().MagentoBaseUrl, this._testData.GetMagentoConsumerCredentials().Secret, "incorrect consumer key", this._testData.GetMagentoSoapUser().ApiUser, this._testData.GetMagentoSoapUser().ApiKey), null); var magentoInfoAsyncTask = service.PingRestAsync(); magentoInfoAsyncTask.Wait(); }; //------------ Assert act.ShouldThrow <Exception>(); }
public int update_qty(string sku, string qty, string pid) { MagentoService mservice = new MagentoService(); String mlogin = mservice.login("admin", "Interconnection123!"); var item_to_update = new catalogInventoryStockItemUpdateEntity(); item_to_update.qty = qty; var result = mservice.catalogInventoryStockItemUpdate(mlogin, sku, item_to_update); try { HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://connectall.org/update.php?product_id=" + pid + "&qty=" + qty); myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; myHttpWebRequest.UserAgent = ".NET Framework Test Client"; WebResponse wr = myHttpWebRequest.GetResponse(); } catch (WebException wex) { var pageContent = new StreamReader(wex.Response.GetResponseStream()) .ReadToEnd(); } return(result); }
static void UpdateTicket(MagentoService service, string siteUrl, string token, int ticketId) { var updateTicketRequest = new UpdateTicketRequest() { ticket_id = ticketId.ToString(), status = "read", type = "dispute", item_id = "listing124", subject = "listing", updated_by_id = "daolam", last_modified_at = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), note = "updated note", }; var result = service.UpdateTicket(siteUrl, token, updateTicketRequest); if (result.HasError) { Console.WriteLine("UpdateTicket " + result.Error); } else { Console.WriteLine("UpdateTicket " + result.Result.ToString()); } }
public bool TestMagentoCredentials(string url, string apiUserID, string apiKey) { try { MagentoService service = new MagentoService(); service.Url = url; string sessionID = service.login(apiUserID, apiKey); salesOrderListEntity[] orders = service.salesOrderList(sessionID, null); return true; } catch (Exception) { return false; } }
protected string ApiTest() { string result = "\n" + CatalogFilename + ": "; string tempDisplay = ProgressText; ProgressText += result + "Rows to export..."; StopWatch exportWatch = new StopWatch(true); #if MAGENTO_API_AVAILABLE #region Static Trevor if (static_proxy && m_alias.Equals("Trevor")) { MagentoService Mclient = new MagentoService(); string MsessionId = ""; //---------------------CATALOG EXPORT---------------------------- try { MsessionId = Mclient.login(m_apiUserName, m_apiKey); catalogProductEntity[] plist = Mclient.catalogProductList(MsessionId, null, ""); if (plist.Length < 1) throw new Exception("No products available"); //TODO: create catalog file header string type = ""; foreach (catalogProductEntity p in plist) { string pid = p.product_id; if (p.type.Equals("simple")) //only export combined items or else simple items with no parents { bool isChild = false; catalogProductLinkEntity[] plinks = Mclient.catalogProductLinkList(MsessionId, "grouped", pid, "id"); foreach (catalogProductLinkEntity pl in plinks) if (pl.type.Equals("configurable")) { isChild = true; break; } if (isChild) continue; } else type += p.type + " "; string pname = p.name; string patt1 = ""; bool first = true; foreach (string cid in p.category_ids) { if (first) first = false; else patt1 += ","; patt1 += cid; } catalogProductReturnEntity pinfo = Mclient.catalogProductInfo(MsessionId, pid, "", null, "id"); catalogProductReturnEntity pPriceInfo = Mclient.catalogProductGetSpecialPrice(MsessionId, pid, "", "id"); string patt2 = ""; string pprice = pPriceInfo.price; ; if ((pPriceInfo.special_from_date != null) && (pinfo.special_to_date != null)) { DateTime saleStart = DateTime.Parse(pPriceInfo.special_from_date); DateTime saleEnd = DateTime.Parse(pPriceInfo.special_to_date); DateTime now = DateTime.Now; if (now >= saleStart && now <= saleEnd) pprice = pPriceInfo.special_price; } string pfilter = ""; string plink = pinfo.url_key; string pimage = ""; string psku = pinfo.sku; catalogProductImageEntity pimageinfo = null; try { pimageinfo = Mclient.catalogProductAttributeMediaInfo(MsessionId, pid, "", "", "id"); } catch { } if (pimageinfo != null) { pimage = pimageinfo.url; } } } catch { } //---------------------SALES EXPORT---------------------------- try { //salesOrderEntity[] sorders = Mclient.salesOrderList(MsessionId, null); salesOrderEntity[] sorders = Mclient.salesOrderList(MsessionId, null); if (sorders.Length > 0) { //TODO: create header line for sales export foreach (salesOrderEntity s in sorders) { string customerid = s.customer_id; if (s.customer_is_guest.Equals("1")) { customerid = s.customer_email; if (customerid == null || customerid.Length < 1) customerid = s.increment_id; } string date = s.created_at; salesOrderEntity sinfo = Mclient.salesOrderInfo(MsessionId, s.increment_id); foreach (salesOrderItemEntity item in sinfo.items) { string productid = item.product_id; string quantity = item.qty_ordered; int len = quantity.IndexOf("."); if (len > 0) quantity = quantity.Substring(0, len); //remove fractional part //TODO: add line to sales data here } } //TODO: upload sales data } } catch { } } #endregion #endif #region Static GoStore Mage_Api_Model_Server_V2_HandlerPortTypeClient Mclient = new Mage_Api_Model_Server_V2_HandlerPortTypeClient(); string MsessionId = ""; //---------------------CATALOG EXPORT---------------------------- try { //login //MsessionId = Mclient.login(m_apiUserName, m_apiKey); MsessionId = Mclient.login("4Tell", "4tellsoftware"); //condomania //Get API calls available apiEntity[] resources = Mclient.resources(MsessionId); //resultObj = proxy.CallMethod("resources", sessionID); //Type t = resultObj.GetType(); //XmlSerializer xs = new XmlSerializer(t); //XElement resources = xs.SerializeAsXElement(resultObj); //TODO: check each CallMethod to make sure it is in this list... //Set product attributes to fetch catalogProductRequestAttributes prodAttributes = new catalogProductRequestAttributes(); string[] attributes = { "sku", "url_key", "price", "special_price", "special_from_date", "special_to_date", "parent_item_id" }; prodAttributes.attributes = attributes; //filters prodFilters = new filters(); //associativeEntity[] filterList = new associativeEntity[1]; //filterList[0].key = ""; //filterList[0].value = ""; //loop through all products StringBuilder data = new StringBuilder(CommonHeader + ProductRecord.Header()); catalogProductEntity[] plist; Mclient.catalogProductList(out plist, MsessionId, null, ""); string type = ""; int maxCid = 0; foreach (catalogProductEntity p in plist) { string pid = p.product_id; if (p.type.Equals("simple")) //only export combined items or else simple items with no parents { //bool isChild = false; //catalogProductLinkEntity[] plinks = Mclient.catalogProductLinkList(MsessionId, "grouped", pid, "id"); //foreach (catalogProductLinkEntity pl in plinks) // if (pl.type.Equals("configurable")) // { // isChild = true; // break; // } //if (isChild) continue; } else type += p.type + " "; string pname = p.name; string patt1 = ""; bool first = true; foreach (string cid in p.category_ids) { if (first) first = false; else patt1 += ","; patt1 += cid; int id = Convert.ToInt32(cid); if (id > maxCid) maxCid = id; } string patt2 = ""; catalogProductReturnEntity pinfo = Mclient.catalogProductInfo(MsessionId, pid, "", prodAttributes, "id"); string pprice = pinfo.price; ; if ((pinfo.special_from_date != null) && (pinfo.special_to_date != null)) { DateTime saleStart = DateTime.Parse(pinfo.special_from_date); DateTime saleEnd = DateTime.Parse(pinfo.special_to_date); DateTime now = DateTime.Now; if (now >= saleStart && now <= saleEnd) pprice = pinfo.special_price; } string pfilter = ""; string plink = pinfo.url_key; string pimage = ""; string psku = pinfo.sku; catalogProductImageEntity pimageinfo = null; try { pimageinfo = Mclient.catalogProductAttributeMediaInfo(MsessionId, pid, "", "", "id"); } catch { try { pimageinfo = Mclient.catalogProductAttributeMediaInfo(MsessionId, psku, "", "", "sku"); } catch { } } if (pimageinfo != null) { pimage = pimageinfo.url; } data.Append(pid + "\t" + pname + "\t" + patt1 + "\t" + patt2 + "\t" + pprice + "\t" + pfilter + "\t" + plink + "\t" + pimage + "\t" + psku + "\r\n"); } result += m_boostService.WriteTable(m_alias, CatalogFilename, data); //get cat info result += "\n" + Att1Filename + ": "; ProgressText = tempDisplay + result + "Exporting..."; catalogCategoryInfo cinfo; StringBuilder csb = new StringBuilder(CommonHeader + AttributeRecord.Header()); for (int cid = 1; cid <= maxCid; cid++) { try { cinfo = Mclient.catalogCategoryInfo(MsessionId, cid, "", null); csb.Append(cid.ToString() + "\t" + cinfo.name + "\r\n"); } catch { csb.Append(cid.ToString() + "\t" + cid.ToString() + "\r\n"); } } result += m_boostService.WriteTable(m_alias, Att1Filename, csb); ProgressText = tempDisplay + result; } catch { } //try //{ // //catalogCategoryTree ctree = Mclient.catalogCategoryTree(MsessionId, "", ""); // catalogCategoryTree ctree = Mclient.catalogCategoryTree(MsessionId, "0", ""); //} //catch { } //try //{ // //catalogCategoryEntityNoChildren[] clist = Mclient.catalogCategoryLevel(MsessionId, "", "", ""); // catalogCategoryEntityNoChildren[] clist = Mclient.catalogCategoryLevel(MsessionId, "", "", ""); //} //catch { } //try //{ // //catalogCategoryEntityNoChildren[] clist = Mclient.catalogCategoryLevel(MsessionId, "", "", ""); // catalogCategoryEntityNoChildren[] clist = Mclient.catalogCategoryLevel(MsessionId, "", "", ""); //} //catch { } //try //{ // //catalogCategoryInfo cinfo = Mclient.catalogCategoryInfo(MsessionId, 0, "CurrentView", null); // catalogCategoryInfo cinfo = Mclient.catalogCategoryInfo(MsessionId, 4, "", null); //} //catch { } //try //{ // //catalogProductAttributeSetEntity[] pasList = Mclient.catalogProductAttributeSetList(MsessionId); // //...this one works! // catalogProductAttributeSetEntity[] pasList = Mclient.catalogProductAttributeSetList(MsessionId); //} //catch { } //---------------------SALES EXPORT---------------------------- try { DateTime exportDate = DateTime.Now; //pass this date in string salesFileName = string.Format(SalesFilenameFormat, exportDate.ToString("yyyy-MM")); result += "\n" + salesFileName + ": "; StringBuilder salesData = new StringBuilder(CommonHeader + SalesRecord.Header()); //create filter to get sales for this month only string fromDate = string.Format("{0:0000}-{1:00}-01 00:00:00", exportDate.Year, exportDate.Month); string toDate = string.Format("{0:0000}-{1:00}-01 00:00:00", exportDate.Year, exportDate.Month + 1); filters monthFilter = new filters(); monthFilter.complex_filter = new complexFilter[2]; monthFilter.complex_filter[0] = new complexFilter(); monthFilter.complex_filter[0].key = "created_at"; monthFilter.complex_filter[0].value = new associativeEntity(); monthFilter.complex_filter[0].value.key = "from"; monthFilter.complex_filter[0].value.value = fromDate; monthFilter.complex_filter[1] = new complexFilter(); monthFilter.complex_filter[1].key = "created_at"; monthFilter.complex_filter[1].value = new associativeEntity(); monthFilter.complex_filter[1].value.key = "to"; monthFilter.complex_filter[1].value.value = toDate; //get list of sales orders salesOrderEntity[] sorders = Mclient.salesOrderList(MsessionId, monthFilter); if (sorders.Length > 0) { //TODO: create header line for sales export foreach (salesOrderEntity s in sorders) { string customerid = s.customer_id; if (s.customer_is_guest.Equals("1")) { customerid = s.customer_email; if (customerid == null || customerid.Length < 1) customerid = s.increment_id; } string date = s.created_at; //get list of items purchased on each sales order salesOrderEntity sinfo = Mclient.salesOrderInfo(MsessionId, s.increment_id); foreach (salesOrderItemEntity item in sinfo.items) { string productid = item.product_id; string quantity = item.qty_ordered; int len = quantity.IndexOf("."); if (len > 0) quantity = quantity.Substring(0, len); //remove fractional part //add line to sales data salesData.Append(customerid + "\t" + productid + "\t" + quantity + "\t" + date + "\r\n"); } } //upload sales data result += m_boostService.WriteTable(m_alias, salesFileName, salesData); } } catch { } #endregion return result; }
public List<ParcelItem> GetPendingOrders() { try { if (UserAccountCode != 0) { List<ParcelItem> items = new List<ParcelItem>(); DataModelEntities context = new DataModelEntities(); UserAccount userAccount = context.UserAccounts.First(u => u.User_Account_Code == UserAccountCode); MagentoService service = new MagentoService(); service.Url = userAccount.Application_Name; string sessionID = service.login(userAccount.Config_Value1, userAccount.Config_Value2); List<associativeEntity> listAssociatedEntity = new List<associativeEntity>(); listAssociatedEntity.Add(new associativeEntity() { key = "status", value = "pending" }); filters filters = new filters(); filters.filter = listAssociatedEntity.ToArray(); salesOrderListEntity[] orders = service.salesOrderList(sessionID, filters); List<ChargeCode> chargeCodes = context.ChargeCodes.Where(u => u.Is_Active == true && u.User_Code == UserCode).ToList(); foreach (salesOrderListEntity order in orders) { salesOrderEntity orderDetail = service.salesOrderInfo(sessionID, order.increment_id); foreach (salesOrderItemEntity lineItem in orderDetail.items) { ParcelItem item = new ParcelItem(); item.Type = "MAGENTO"; item.AccountID = userAccount.User_Account_Code.ToString(); item.RecordNumber = orderDetail.order_id; item.ItemID = lineItem.item_id; item.TransactionID = orderDetail.increment_id; item.ItemName = lineItem.name; item.CustomLabel = lineItem.sku; item.CustomLabelText = lineItem.sku; string state = orderDetail.shipping_address.region; string stateCode = orderDetail.shipping_address.region_id; if (StateHelper.States.Where(s => s.Key == stateCode).Count() > 0) item.State = StateHelper.States[stateCode]; else item.State = state; item.BuyerName = orderDetail.customer_firstname + " " + orderDetail.customer_lastname; item.EmailAddress = orderDetail.customer_email; item.BuyerID = orderDetail.customer_id; item.Street2 = orderDetail.shipping_address.street; item.Street3 = string.Empty; item.City = orderDetail.shipping_address.city; item.PostalCode = orderDetail.shipping_address.postcode; item.Country = orderDetail.shipping_address.country_id; item.Phone = orderDetail.shipping_address.telephone; item.Quantity = lineItem.qty_ordered == string.Empty ? 0 : (int)decimal.Parse(lineItem.qty_ordered); if (orderDetail.shipping_amount != string.Empty) item.ShippingCost = double.Parse(orderDetail.shipping_amount); item.SaleRecordId = orderDetail.increment_id; // insurance details // item.Currency = orderDetail.order_currency_code; item.Price = double.Parse(lineItem.price); item.ShippingMethod = orderDetail.shipping_description; string shippingCode = orderDetail.shipping_description; ChargeCode code = chargeCodes.FirstOrDefault(u => shippingCode.ToLower().Contains(u.Ebay_Code.ToLower()) == true); if (code != null && code.Charge_Code_Name.ToLower() == "ignore") { continue; // ignore the item } bool IspostCodeOK = Common.VerifyPostCode(orderDetail.shipping_address.postcode, orderDetail.shipping_address.city); if (IspostCodeOK) item.PostCodeImageURL = Constant.tickURL; else item.PostCodeImageURL = Constant.crossURL; items.Add(item); } } return items; } else { return null; } } catch (Exception ex) { return null; } }
protected override string GetCatalog() { string h2 = ""; StringBuilder data = null; string filename = "Catalog.txt"; string result = "\n" + filename + ": "; string tempDisplay = ProgressText; ProgressText += result + "Rows to export..."; StopWatch exportWatch = new StopWatch(true); //--------DEBUG USING STATIC------ bool static_proxy = false; //-------------------------------- #if MAGENTO_API_AVAILABLE #region Static Trevor if (static_proxy && m_alias.Equals("Trevor")) { MagentoService Mclient = new MagentoService(); string MsessionId = ""; //---------------------CATALOG EXPORT---------------------------- try { MsessionId = Mclient.login(m_apiUserName, m_apiKey); catalogProductEntity[] plist = Mclient.catalogProductList(MsessionId, null, ""); if (plist.Length < 1) throw new Exception("No products available"); //TODO: create catalog file header string type = ""; foreach (catalogProductEntity p in plist) { string pid = p.product_id; if (p.type.Equals("simple")) //only export combined items or else simple items with no parents { bool isChild = false; catalogProductLinkEntity[] plinks = Mclient.catalogProductLinkList(MsessionId, "grouped", pid, "id"); foreach (catalogProductLinkEntity pl in plinks) if (pl.type.Equals("configurable")) { isChild = true; break; } if (isChild) continue; } else type += p.type + " "; string pname = p.name; string patt1 = ""; bool first = true; foreach (string cid in p.category_ids) { if (first) first = false; else patt1 += ","; patt1 += cid; } catalogProductReturnEntity pinfo = Mclient.catalogProductInfo(MsessionId, pid, "", null, "id"); catalogProductReturnEntity pPriceInfo = Mclient.catalogProductGetSpecialPrice(MsessionId, pid, "", "id"); string patt2 = ""; string pprice = pPriceInfo.price; ; if ((pPriceInfo.special_from_date != null) && (pinfo.special_to_date != null)) { DateTime saleStart = DateTime.Parse(pPriceInfo.special_from_date); DateTime saleEnd = DateTime.Parse(pPriceInfo.special_to_date); DateTime now = DateTime.Now; if (now >= saleStart && now <= saleEnd) pprice = pPriceInfo.special_price; } string pfilter = ""; string plink = pinfo.url_key; string pimage = ""; string psku = pinfo.sku; catalogProductImageEntity pimageinfo = null; try { pimageinfo = Mclient.catalogProductAttributeMediaInfo(MsessionId, pid, "", "", "id"); } catch { } if (pimageinfo != null) { pimage = pimageinfo.url; } } } catch { } //---------------------SALES EXPORT---------------------------- try { //salesOrderEntity[] sorders = Mclient.salesOrderList(MsessionId, null); salesOrderEntity[] sorders = Mclient.salesOrderList(MsessionId, null); if (sorders.Length > 0) { //TODO: create header line for sales export foreach (salesOrderEntity s in sorders) { string customerid = s.customer_id; if (s.customer_is_guest.Equals("1")) { customerid = s.customer_email; if (customerid == null || customerid.Length < 1) customerid = s.increment_id; } string date = s.created_at; salesOrderEntity sinfo = Mclient.salesOrderInfo(MsessionId, s.increment_id); foreach (salesOrderItemEntity item in sinfo.items) { string productid = item.product_id; string quantity = item.qty_ordered; int len = quantity.IndexOf("."); if (len > 0) quantity = quantity.Substring(0, len); //remove fractional part //TODO: add line to sales data here } } //TODO: upload sales data } } catch { } } #endregion #endif #region Static GoStore if (static_proxy && m_alias.Equals("WSTea")) { Mage_Api_Model_Server_V2_HandlerPortTypeClient Mclient = new Mage_Api_Model_Server_V2_HandlerPortTypeClient(); string MsessionId = ""; //---------------------CATALOG EXPORT---------------------------- try { //login MsessionId = Mclient.login(m_apiUserName, m_apiKey); //Set product attributes to fetch catalogProductRequestAttributes prodAttributes = new catalogProductRequestAttributes(); string[] attributes = { "sku", "url_key", "price", "special_price", "special_from_date", "special_to_date", "parent_item_id" }; prodAttributes.attributes = attributes; //filters prodFilters = new filters(); //associativeEntity[] filterList = new associativeEntity[1]; //filterList[0].key = ""; //filterList[0].value = ""; //loop through all products h2 = "Product ID\tName\tAtt1 ID\tAtt2 ID\tPrice\tFilter\tLink\tImage Link\tStandard Code\r\n"; //product catalog second header line data = new StringBuilder(CommonHeader + h2); catalogProductEntity[] plist; Mclient.catalogProductList(out plist, MsessionId, null, ""); //string type = ""; int maxCid = 0; foreach (catalogProductEntity p in plist) { string pid = p.product_id; catalogProductLinkEntity[] plinks = Mclient.catalogProductLinkList(MsessionId, "parent", pid, "id"); if (plinks != null) continue; //is a child //if (p.type.Equals("simple")) //only export combined items or else simple items with no parents //{ // bool isChild = false; // catalogProductLinkEntity[] plinks = Mclient.catalogProductLinkList(MsessionId, "grouped", pid, "id"); // foreach (catalogProductLinkEntity pl in plinks) // if (pl.type.Equals("configurable")) // { // isChild = true; // break; // } // if (isChild) continue; //} //else // type += p.type + " "; string pname = p.name; string patt1 = ""; bool first = true; foreach (string cid in p.category_ids) { if (first) first = false; else patt1 += ","; patt1 += cid; int id = Convert.ToInt32(cid); if (id > maxCid) maxCid = id; } string patt2 = ""; catalogProductReturnEntity pinfo = Mclient.catalogProductInfo(MsessionId, pid, "", prodAttributes, "id"); string pprice = pinfo.price; ; if ((pinfo.special_from_date != null) && (pinfo.special_to_date != null)) { DateTime saleStart = DateTime.Parse(pinfo.special_from_date); DateTime saleEnd = DateTime.Parse(pinfo.special_to_date); DateTime now = DateTime.Now; if (now >= saleStart && now <= saleEnd) pprice = pinfo.special_price; } string pfilter = ""; string plink = pinfo.url_key; string pimage = ""; string psku = pinfo.sku; catalogProductImageEntity pimageinfo = null; try { pimageinfo = Mclient.catalogProductAttributeMediaInfo(MsessionId, pid, "", "", "id"); } catch { } if (pimageinfo != null) { pimage = pimageinfo.url; } data.Append(pid + "\t" + pname + "\t" + patt1 + "\t" + patt2 + "\t" + pprice + "\t" + pfilter + "\t" + plink + "\t" + pimage + "\t" + psku + "\r\n"); } result += m_boostService.WriteTable(m_alias, filename, data); //get cat info filename = "Attribute1Names.txt"; result += "\n" + filename + ": "; ProgressText = tempDisplay + result + "Exporting..."; catalogCategoryInfo cinfo; h2 = "Att ID\tName\r\n"; StringBuilder csb = new StringBuilder(CommonHeader + h2); for (int cid = 1; cid <= maxCid; cid++) { try { cinfo = Mclient.catalogCategoryInfo(MsessionId, cid, "", null); csb.Append(cid.ToString() + "\t" + cinfo.name + "\r\n"); } catch { csb.Append(cid.ToString() + "\t" + cid.ToString() + "\r\n"); } } result += m_boostService.WriteTable(m_alias, filename, csb); ProgressText = tempDisplay + result; } catch { } } #endregion #region Dynamic GoStore if (!static_proxy) { //http://whitesalmontea.gostorego.com/api/v2_soap/?wsdl DynamicProxy proxy = GetSoapProxy(m_wsdlUrl, "Mage_Api_Model_Server_V2_HandlerPortType"); if (proxy == null) throw new Exception("Unable to create SOAP proxy for Magento"); //login to get a session id object resultObj = proxy.CallMethod("login", m_apiUserName, m_apiKey); string sessionID = resultObj.ToString(); //Type t; //XmlSerializer xs; //---------------------CATALOG EXPORT---------------------------- try { //Get catalog details resultObj = proxy.CallMethod("resources", sessionID); XElement resources = XmlSerializerExtension.SerializeAsXElement(resultObj); //t = resultObj.GetType(); //xs = new XmlSerializer(t); //XElement resources = xs.SerializeAsXElement(resultObj); //TODO: check each CallMethod to make sure it is in this list... //catalog_product.list catalogProductList resultObj = proxy.CallMethod("catalog_product.list", sessionID); XElement products = XmlSerializerExtension.SerializeAsXElement(resultObj); //catalogProductEntity[] //t = resultObj.GetType(); //xs = new XmlSerializer(t); //XElement products = xs.SerializeAsXElement(resultObj); //catalogProductEntity[] foreach (XElement product in products.Elements("catalogProductEntity")) { string pid = ""; string pname = ""; string patt1 = ""; try { pid = Client.GetValue(product, "product_id"); pname = Client.GetValue(product, "name"); } catch (Exception ex) { } try { bool first = true; foreach (XElement cat in product.Elements("category_ids")) { if (first) first = false; else patt1 += ","; patt1 += Client.GetValue(cat, "id"); } } catch (Exception ex) { } XElement pinfo = null; //#if MAGENTO_API_AVAILABLE catalogProductRequestAttributes a = new catalogProductRequestAttributes(); string[] attributes = { "sku", "url_key", "price", "special_price", "special_from_date", "special_to_date" }; a.attributes = attributes; XElement request = XmlSerializerExtension.SerializeAsXElement(a); //t = a.GetType(); //xs = new XmlSerializer(t); //XElement request = xs.SerializeAsXElement(a); string patt2 = ""; string pprice = ""; try { //catalog_product.info catalogProductInfo resultObj = proxy.CallMethod("catalog_product.info", sessionID, pid, a, "id"); pinfo = XmlSerializerExtension.SerializeAsXElement(resultObj); //catalogProductReturnEntity //t = resultObj.GetType(); //xs = new XmlSerializer(t); //pinfo = xs.SerializeAsXElement(resultObj); //catalogProductReturnEntity pprice = Client.GetValue(pinfo, "price"); XElement xFromDate = pinfo.Element("special_from_date"); XElement xToDate = pinfo.Element("special_from_date"); if ((xFromDate != null) && (xToDate != null)) { DateTime saleStart = DateTime.Parse(xFromDate.Value); DateTime saleEnd = DateTime.Parse(xToDate.Value); DateTime now = DateTime.Now; if (now >= saleStart && now <= saleEnd) pprice = Client.GetValue(pinfo, "special_price"); } } catch (Exception ex) { } //#endif string pfilter = ""; string plink = ""; string psku = ""; string pimage = ""; try { plink = Client.GetValue(pinfo, "url_key"); psku = Client.GetValue(pinfo, "sku"); XElement pimageinfo = null; //catalog_product_attribute_media.info catalogProductAttributeMediaInfo resultObj = proxy.CallMethod("catalog_product_attribute_media.info", sessionID, pid, "", "", "id"); pimageinfo = XmlSerializerExtension.SerializeAsXElement(resultObj); //catalogProductImageEntity //t = resultObj.GetType(); //xs = new XmlSerializer(t); //pimageinfo = xs.SerializeAsXElement(resultObj); //catalogProductImageEntity if (pimageinfo != null) { pimage = Client.GetValue(pimageinfo, "url"); } } catch { } } } catch (Exception ex) { string errMsg = "Error extracting catalog: " + ex.Message; if (ex.InnerException != null) errMsg += "\nInner Exception" + ex.InnerException.Message; result += "\n" + errMsg; } } #endregion return result; }