public void Exec(Int32 ArticleSend) { try { Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend); Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct Product = new Model.Prestashop.PsProduct(); // If the Article have a connection with Prestashop if (Article.Pre_Id != null) { //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond); if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value))) { Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value)); Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository(); if (F_ARTICLERepository.ExistArticle(Article.Sag_Id)) { SynchronisationArticle.ExecFeature(Article); } } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
public void Exec(Int32 ArticleSend) { try { Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend); // If the catalog is sync with Prestashop //if (Article.Catalog.Pre_Id != null || Article.Catalog.Pre_Id != 0) { Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository(); Boolean isProduct = false; // If the Article have a connection with Prestashop if (Article.Pre_Id != null && ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value))) { Model.Prestashop.PsProduct Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value)); isProduct = true; if (Product.DateUpd.Ticks > Article.Art_Date.Ticks) { this.ExecDistantToLocal(Product, Article, ArticleRepository); } else if (Product.DateUpd.Ticks < Article.Art_Date.Ticks) { this.ExecLocalToDistant(Article, Product, ArticleRepository, ProductRepository, isProduct); } } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
public void Exec(Int32 ArticleSend, out List <string> log_chrono, out uint pre_id) { log_chrono = new List <string>(); pre_id = 0; try { Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend); DateTime start = DateTime.UtcNow; if (Core.Global.GetConfig().ChronoSynchroStockPriceActif) { log_chrono.Add("----" + Article.Art_Ref + "----" + start.ToString("HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture)); } Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct Product = new Model.Prestashop.PsProduct(); // If the Article have a connection with Prestashop if (Article.Pre_Id != null) { //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond); if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value))) { Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value)); List <string> log; this.ExecLocalToDistant(Article, Product, ProductRepository, out log); if (log != null && log.Count > 0) { log_chrono.AddRange(log); } pre_id = Product.IDProduct; } } if (Core.Global.GetConfig().ChronoSynchroStockPriceActif) { log_chrono.Add("----" + Article.Art_Ref + "----" + (DateTime.UtcNow - start).ToString()); } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
public void Exec(Int32 ArticleSend) { try { Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend); Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct Product = new Model.Prestashop.PsProduct(); // If the Article have a connection with Prestashop if (Article.Pre_Id != null) { //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond); if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value))) { Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value)); this.ExecLocalToDistant(Article, ArticleRepository, Product, ProductRepository); } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
//<YH> 23/08/2012 private void ExecLocalToDistant(Model.Local.Article Article) { try { Model.Prestashop.PsAttachmentRepository PsAttachmentRepository = new Model.Prestashop.PsAttachmentRepository(); Model.Prestashop.PsAttachment PsAttachment; Model.Prestashop.PsAttachmentLangRepository PsAttachmentLangRepository = new Model.Prestashop.PsAttachmentLangRepository(); Model.Prestashop.PsAttachmentLang PsAttachmentLang; Model.Prestashop.PsProductAttachmentRepository PsProductAttachmentRepository = new Model.Prestashop.PsProductAttachmentRepository(); Model.Prestashop.PsProductAttachment PsProductAttachment; Boolean isAttachmentLang = false; String FTP = Core.Global.GetConfig().ConfigFTPIP; String User = Core.Global.GetConfig().ConfigFTPUser; String Password = Core.Global.GetConfig().ConfigFTPPassword; Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository(); List <Model.Local.Attachment> ListAttachment = AttachmentRepository.ListArticle(Article.Art_Id); foreach (Model.Local.Attachment Attachment in ListAttachment) { try { if (Attachment.Pre_Id == null) { String PathAttachment = Path.Combine(Global.GetConfig().Folders.RootAttachment, Attachment.Att_File); if (System.IO.File.Exists(PathAttachment)) { #region infos document joint PsAttachment = new Model.Prestashop.PsAttachment(); PsAttachment.File = Attachment.Att_File; PsAttachment.FileName = Attachment.Att_FileName; PsAttachment.Mime = Attachment.Att_Mime; PsAttachmentRepository.Add(PsAttachment); isAttachmentLang = false; PsAttachmentLang = new Model.Prestashop.PsAttachmentLang(); if (PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang)) { PsAttachmentLang = PsAttachmentLangRepository.ReadAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang); isAttachmentLang = true; } PsAttachmentLang.Name = Attachment.Att_Name; PsAttachmentLang.Description = Attachment.Att_Description; if (isAttachmentLang == true) { PsAttachmentLangRepository.Save(); } else { PsAttachmentLang.IDAttachment = PsAttachment.IDAttachment; PsAttachmentLang.IDLang = Core.Global.Lang; PsAttachmentLangRepository.Add(PsAttachmentLang); } #endregion // <JG> 24/05/2013 ajout insertion autres langues actives si non renseignées #region Multi-langues try { Model.Prestashop.PsLangRepository PsLangRepository = new Model.Prestashop.PsLangRepository(); foreach (Model.Prestashop.PsLang PsLang in PsLangRepository.ListActive(1, Global.CurrentShop.IDShop)) { if (!PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, PsLang.IDLang)) { PsAttachmentLang = new Model.Prestashop.PsAttachmentLang() { IDAttachment = PsAttachment.IDAttachment, IDLang = PsLang.IDLang, Name = Attachment.Att_Name, Description = Attachment.Att_Description }; PsAttachmentLangRepository.Add(PsAttachmentLang); } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } #endregion // affectation au produit PsProductAttachment = new Model.Prestashop.PsProductAttachment(); if (PsProductAttachmentRepository.ExistProductAttachment(Convert.ToUInt32(Article.Pre_Id), PsAttachment.IDAttachment) == false) { PsProductAttachment.IDProduct = Convert.ToUInt32(Article.Pre_Id); PsProductAttachment.IDAttachment = PsAttachment.IDAttachment; PsProductAttachmentRepository.Add(PsProductAttachment); } try { #region upload string ftpfullpath = FTP + "/download/" + Attachment.Att_File; System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath); ftp.Credentials = new System.Net.NetworkCredential(User, Password); //userid and password for the ftp server to given ftp.UseBinary = true; ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile; System.IO.FileStream fs = System.IO.File.OpenRead(PathAttachment); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); System.IO.Stream ftpstream = ftp.GetRequestStream(); ftpstream.Write(buffer, 0, buffer.Length); ftpstream.Close(); ftp.Abort(); #endregion #region update Product field cache_as_attachements Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct PsProduct = PsProductRepository.ReadId(PsProductAttachment.IDProduct); if (PsProduct.CacheHasAttachments == 0) { PsProduct.CacheHasAttachments = (sbyte)1; PsProductRepository.Save(); } #endregion Attachment.Pre_Id = Convert.ToInt32(PsAttachment.IDAttachment); AttachmentRepository.Save(); } catch (Exception ex) { Core.Error.SendMailError("[UPLOAD FTP DOCUMENT]<br />" + ex.ToString()); PsProductAttachmentRepository.Delete(PsProductAttachmentRepository.ListAttachment(PsAttachment.IDAttachment)); PsAttachmentLangRepository.Delete(PsAttachmentLangRepository.ListAttachment(PsAttachment.IDAttachment)); PsAttachmentRepository.Delete(PsAttachment); } } } } catch (Exception ex) { Core.Error.SendMailError("[SYNCHRO DOCUMENT ARTICLE]<br />" + ex.ToString()); } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
public void Exec(Int32 ProductSend) { try { Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository(); if (ArticleRepository.ExistPre_Id(ProductSend) == false) { Model.Prestashop.PsProductLangRepository PsProductLangRepository = new Model.Prestashop.PsProductLangRepository(); if (PsProductLangRepository.ExistProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop)) { Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct PsProduct = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend)); Model.Prestashop.PsProductLang PsProductLang = PsProductLangRepository.ReadProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop); Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository(); string product_reference = PsProduct.Reference; product_reference = product_reference.Replace(" ", "_"); if (F_ARTICLERepository.ExistReference(product_reference)) { Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadReference(product_reference); Model.Local.Article Article = new Model.Local.Article() { Art_Name = PsProductLang.Name, Art_Description = PsProductLang.Description, Art_Description_Short = PsProductLang.DescriptionShort, Art_LinkRewrite = PsProductLang.LinkRewrite, Art_MetaTitle = PsProductLang.MetaTitle, Art_MetaKeyword = PsProductLang.MetaKeywords, Art_MetaDescription = PsProductLang.MetaDescription, Art_Ref = PsProduct.Reference, Art_Ean13 = PsProduct.EAn13, Art_Pack = PsProduct.CacheIsPack == 1, Art_Solde = Convert.ToBoolean(PsProduct.OnSale), Art_Active = Convert.ToBoolean(PsProduct.Active), Art_Sync = true, Art_SyncPrice = true, Art_Date = (PsProduct.DateUpd != null && PsProduct.DateUpd > new DateTime(1753, 1, 2)) ? PsProduct.DateUpd : DateTime.Now.Date, Sag_Id = F_ARTICLE.cbMarq, Pre_Id = Convert.ToInt32(PsProduct.IDProduct), Cat_Id = this.ReadCatalog(PsProduct.IDCategoryDefault), Art_RedirectType = new Model.Internal.RedirectType(Core.Parametres.RedirectType.NoRedirect404).Page, Art_RedirectProduct = 0, Art_Manufacturer = (PsProduct.IDManufacturer != null) ? (int)PsProduct.IDManufacturer : 0, Art_Supplier = (PsProduct.IDSupplier != null) ? (int)PsProduct.IDSupplier : 0, }; if (Article.Cat_Id == 0) { foreach (Model.Prestashop.PsCategoryProduct PsCategoryProduct in new Model.Prestashop.PsCategoryProductRepository().ListProduct(PsProduct.IDProduct)) { Article.Cat_Id = this.ReadCatalog(PsCategoryProduct.IDCategory); if (Article.Cat_Id != 0) { break; } } } if (PsProduct.CacheIsPack == 1) { Article.Art_Pack = true; } if (Article.Cat_Id != 0) { ArticleRepository.Add(Article); RecoveryChildData(Article, PsProduct, ArticleRepository, false); } } } } else { Model.Local.Article Article = ArticleRepository.ReadPre_Id(ProductSend); Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository(); Model.Prestashop.PsProduct PsProduct = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend)); RecoveryChildData(Article, PsProduct, ArticleRepository, true); } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }