public void Add_Product_Meta_Seo(string product_id, DataLoad data) { var dbCon = DBConnection.Instance(); if (dbCon.IsConnect()) { MySqlCommand comm = dbCon.Connection.CreateCommand(); comm.CommandText = @"INSERT INTO wp_slov_postmeta ( post_id, meta_key, meta_value) VALUES (@id, '_yoast_wpseo_focuskw', @title), (@id, '_yoast_wpseo_focuskw_text_input', @title), (@id, '_yoast_wpseo_metadesc', @description), (@id, '_yoast_wpseo_metakeywords', @keywords), (@id, '_yoast_wpseo_primary_product_cat', ''), (@id, '_yoast_wpseo_linkdex', '41')"; comm.Parameters.AddWithValue("@id", String.Format("{0}", product_id)); comm.Parameters.AddWithValue("@title", String.Format("{0}", data.Title)); comm.Parameters.AddWithValue("@description", String.Format("{0}", data.Description)); comm.Parameters.AddWithValue("@keywords", String.Format("{0}", data.Keywords)); comm.ExecuteNonQuery(); } }
public bool Is_Exist_Server(DataLoad data) { bool result = false; Logs log = new Logs(); Query server = new Query(); var product_id = server.Check_Product_By_Id(data.Sku); if (!string.IsNullOrEmpty(product_id)) { if (string.IsNullOrEmpty(server.Select_SEO(product_id))) { server.Add_Product_Meta_Seo(product_id, data); } string[] types = { "product_cat", "product_tag" }; string cat = data.CategorySearch; foreach (var type in types) { if (type == "product_tag") { cat = data.Tag; } //else // if (cat != data.Category) // Update_New_Cat_Tag_Exist_Product(product_id, data.Category, type, 1); Update_New_Cat_Tag_Exist_Product(product_id, cat, type, 1); } result = true; } return(result); }
public int execute(DataLoad data) { int status = 0; Logs log = new Logs(); try { QueryLocal local = new QueryLocal(); if (!Is_Exist_Server(data)) { string id = NewProduct(data); local.Insert_Posting(data.CateProdId, Int32.Parse(id)); status = 1; } else { status = 2; } var db = DBConnection.Instance(); db.Close(); return(status); } catch (Exception ex) { log.IErrors("Logic - Execute: " + ex.Message); return(status); } }
public string AddNewProduct(DataLoad data) { string result = ""; var dbCon = DBConnection.Instance(); if (dbCon.IsConnect()) { MySqlCommand comm = dbCon.Connection.CreateCommand(); comm.CommandText = @"INSERT INTO wp_slov_posts ( post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_type, post_modified, post_modified_gmt, guid, post_content_filtered ) VALUES (1, @datetime, @datetime, @url, @title, @description, 'publish', 'closed', 'closed', @url_name, 'product', @datetime, @datetime, @url_name, @sku )"; string url_name = data.UrlName; comm.Parameters.AddWithValue("@datetime", String.Format("{0}", DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"))); comm.Parameters.AddWithValue("@title", String.Format("{0}", data.Title)); comm.Parameters.AddWithValue("@description", String.Format("{0}", data.Description)); comm.Parameters.AddWithValue("@url", String.Format("{0}", data.Url)); comm.Parameters.AddWithValue("@url_name", String.Format("{0}", url_name)); comm.Parameters.AddWithValue("@sku", String.Format("{0}", data.Sku)); comm.ExecuteNonQuery(); result = comm.LastInsertedId.ToString(); } return(result); }
public string Update_Product(string id, DataLoad data) { string result = ""; var dbCon = DBConnection.Instance(); if (dbCon.IsConnect()) { MySqlCommand comm = dbCon.Connection.CreateCommand(); comm.CommandText = @"UPDATE wp_slov_posts SET post_excerpt = @description, post_name = @url_name, guid = @url WHERE ID = @id"; string url_name = data.UrlName; comm.Parameters.AddWithValue("@id", String.Format("{0}", id)); comm.Parameters.AddWithValue("@description", String.Format("{0}", data.Description)); comm.Parameters.AddWithValue("@url_name", String.Format("{0}", url_name)); comm.Parameters.AddWithValue("@url", String.Format("{0}", url_name)); comm.ExecuteNonQuery(); } return(result); }
public string NewProduct(DataLoad data) { string result = null; Logs log = new Logs(); try { Query server = new Query(); if (data.Sku != null) { var product_id = server.AddNewProduct(data); if (product_id != "") { server.AddNewProductMeta(product_id, data); var category_id = server.Select_Category(data.CategorySearch, "product_cat"); var tag_id = server.Select_Category(data.TypeName, "product_tag"); var tax_cat = server.Select_Taxonomy(category_id); var tax_tag = server.Select_Taxonomy(tag_id); server.Update_Taxonomy_By_Term_Id(tax_cat[0]); server.Update_Taxonomy_By_Term_Id(tax_cat[3]); server.Update_Taxonomy_By_Term_Id(tag_id); server.Add_Relationships(product_id, tax_cat[0], tax_tag[0]); //server.Add_Tag_Relationships(product_id, tax_cat[0]); //server.Add_Tag_Relationships(product_id, tax_tag[0]); Update_New_Cat_Tag_Exist_Product(product_id, data.Tag, "product_tag", 0); log.ILogs("NewProduct: " + product_id + " - " + data.CategorySearch + " - " + data.Tag + " - " + data.TypeName); } result = product_id; } } catch (Exception ex) { log.IErrors("Logic - NewProduct: " + ex.Message); } return(result); }
public IEnumerable <DataLoad> GetProduct() { List <DataLoad> datas = new List <DataLoad>(); mmoDataContext context = new mmoDataContext(); var query = from prod in context.Products join catProd in context.ProductCategoryDetails on prod.Id equals catProd.Product_Id join cat in context.Categories on catProd.Category_Id equals cat.Id where !(from post in context.Postings select post.Product_Id).Contains(cat.Id) && prod.Sku != null select new { prod, cat }; if (query != null) { foreach (var i in query) { string parent_category = (from a in context.Categories where a.Id == i.cat.Parent_Id select a).FirstOrDefault().Name; DataLoad data = new DataLoad(); data.Sku = i.prod.Sku; data.Title = i.prod.Name; data.Description = i.prod.Description; data.Image = i.prod.Image; data.Price = decimal.Parse(i.prod.Price.ToString()); data.Keywords = i.prod.Keywords; data.GroupId = i.prod.Group_Id; data.Tag = i.cat.Name; data.Type = Int32.Parse(i.prod.ProductTypeId.ToString()); data.TypeName = i.prod.ProductType.Name; data.Url = i.prod.Url_Source; data.UrlName = i.prod.Url_Name.Split('/')[2]; data.Category = parent_category; data.CategorySearch = parent_category; data.CateProdId = i.cat.Id; datas.Add(data); } } return(datas); }
public string AddNewProductMeta(string product_id, DataLoad data) { string result = ""; var dbCon = DBConnection.Instance(); if (dbCon.IsConnect()) { MySqlCommand comm = dbCon.Connection.CreateCommand(); comm.CommandText = @"INSERT INTO wp_slov_postmeta ( post_id, meta_key, meta_value) VALUES (@id, '_wpb_vc_js_status', 'false'), (@id, '_price', @price), (@id, '_stock_status', 'instock'), (@id, '_download_expiry', -1), (@id, '_download_limit', -1), (@id, '_product_image_gallery', ''), (@id, '_downloadable', 'no'), (@id, '_virtual', 'no'), (@id, '_default_attributes', 'a:0:{}'), (@id, '_purchase_note', 'a:0:{}'), (@id, '_crosssell_ids', 'a:0:{}'), (@id, '_upsell_ids', 'a:0:{}'), (@id, '_height', ''), (@id, '_width', ''), (@id, '_length', ''), (@id, '_weight', ''), (@id, '_sold_individually', 'no'), (@id, '_backorders', 'no'), (@id, '_manage_stock', 'no'), (@id, '_tax_class', ''), (@id, '_tax_status', 'taxable'), (@id, 'total_sales', '0'), (@id, '_sale_price_dates_to', ''), (@id, '_sale_price_dates_from', ''), (@id, '_sale_price', @price), (@id, '_regular_price', ''), (@id, '_sku', @sku), (@id, 'fifu_image_url', @image), (@id, 'fifu_image_alt', @title), (@id, '_yoast_wpseo_focuskw', @title), (@id, '_yoast_wpseo_focuskw_text_input', @title), (@id, '_yoast_wpseo_metadesc', @description), (@id, '_yoast_wpseo_metakeywords', @keywords), (@id, '_yoast_wpseo_primary_product_cat', ''), (@id, '_yoast_wpseo_linkdex', '41'), (@id, '_thumbnail_id', '-1')"; string url_name = data.UrlName; comm.Parameters.AddWithValue("@id", String.Format("{0}", product_id)); comm.Parameters.AddWithValue("@price", String.Format("{0}", data.Price)); comm.Parameters.AddWithValue("@title", String.Format("{0}", data.Title)); comm.Parameters.AddWithValue("@description", String.Format("{0}", data.Description)); comm.Parameters.AddWithValue("@keywords", String.Format("{0}", data.Keywords)); comm.Parameters.AddWithValue("@sku", String.Format("{0}", data.Sku)); comm.Parameters.AddWithValue("@image", String.Format("{0}", data.Image)); comm.ExecuteNonQuery(); } return(result); }