示例#1
0
        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());
            }
        }
示例#2
0
        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());
            }
        }
示例#3
0
 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();
             Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
             // If the Article have a connection with Prestashop
             if (Article.Pre_Id != null)
             {
                 if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                 {
                     this.ExecLocalToDistant(Article);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
        private void ReadRedirection(Model.Local.Article Article)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Article = ArticleRepository.ReadArticle(Article.Art_Id);
                Model.Prestashop.DataClassesPrestashop      DBPrestashop = new Model.Prestashop.DataClassesPrestashop(new MySqlConnection(Properties.Settings.Default.PRESTASHOPConnectionString));
                List <Model.Prestashop.Product_Redirection> list         = DBPrestashop.ExecuteQuery <Model.Prestashop.Product_Redirection>
                                                                               ("select redirect_type, " +
                                        #if (PRESTASHOP_VERSION_172)
                                                                               "id_type_redirected " +
                                        #else
                                                                               "id_product_redirected " +
                                        #endif
                                                                               " from ps_product_shop where id_product = " + Article.Pre_Id + " and id_shop = " + Core.Global.CurrentShop.IDShop + " ").ToList();

                if (list != null && list.Count == 1)
                {
                    Model.Prestashop.Product_Redirection values = list.FirstOrDefault();
                    Article.Art_RedirectType = values.redirect_type;
                                        #if (PRESTASHOP_VERSION_172)
                    Article.Art_RedirectProduct = (ArticleRepository.ExistPre_Id((int)values.id_type_redirected)) ? ArticleRepository.ReadPre_Id((int)values.id_type_redirected).Art_Id : 0;
                                        #else
                    Article.Art_RedirectProduct = (ArticleRepository.ExistPre_Id((int)values.id_product_redirected)) ? ArticleRepository.ReadPre_Id((int)values.id_product_redirected).Art_Id : 0;
                                        #endif
                    ArticleRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#5
0
 private void ExecLocalToDistant(Model.Local.Article Article, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
 {
     try
     {
         Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
         if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
         {
             Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
             Model.Prestashop.PsPackRepository PsPackRepository = new Model.Prestashop.PsPackRepository();
             List <Model.Prestashop.PsPack>    ListPsPack       = PsPackRepository.ListProductPack(Product.IDProduct);
             foreach (Model.Prestashop.PsPack PsPack in ListPsPack)
             {
                 PsPackRepository.Delete(PsPack);
             }
             #region Pack/nomenclature
             if (Article.Art_Pack == true)
             {
                 Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                 List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                 Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                 Model.Local.Article     ArticleNomenclat;
                 Model.Prestashop.PsPack PsPackAdd;
                 foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                 {
                     if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                     {
                         F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                         if (ArticleRepository.ExistSag_Id(F_ARTICLENOMENCLAT.cbMarq) &&
                             F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)
                         // pour ne pas prendre en compte les articles non suivi en stock
                         {
                             ArticleNomenclat = ArticleRepository.ReadSag_Id(F_ARTICLENOMENCLAT.cbMarq);
                             if (ArticleNomenclat.Pre_Id != null && ArticleNomenclat.Pre_Id.Value != 0)
                             {
                                 if (ProductRepository.ExistId((UInt32)ArticleNomenclat.Pre_Id.Value))
                                 {
                                     PsPackAdd = new Model.Prestashop.PsPack()
                                     {
                                         IDProductPack = Product.IDProduct,
                                         IDProductItem = (UInt32)ArticleNomenclat.Pre_Id.Value,
                                         Quantity      = (UInt32)F_NOMENCLAT.NO_Qte.Value
                                     };
                                     PsPackRepository.Add(PsPackAdd);
                                 }
                             }
                         }
                     }
                 }
             }
             #endregion
         }
     }
     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.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                Model.Sage.F_ARTICLE           F_ARTICLE           = new Model.Sage.F_ARTICLE();
                F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                Core.ImportSage.ImportArticle ImportArticle = new ImportSage.ImportArticle();
                ImportArticle.ImportCatalogueInfoLibre(F_ARTICLE, Article);

                //Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();

                //Model.Local.InformationLibreArticleRepository InformationLibreArticleRepository = new Model.Local.InformationLibreArticleRepository();
                //Model.Local.InformationLibreArticle InformationLibreArticleCatalogueParent = new Model.Local.InformationLibreArticle();

                //Model.Local.Catalog Parent;

                //foreach (Model.Local.InformationLibreArticle InformationLibreArticle in InformationLibreArticleRepository.List())
                //{
                //    CatalogRepository = new Model.Local.CatalogRepository();

                //    if (InformationLibreArticle.Inf_Catalogue == 2)
                //    {
                //        if (CatalogRepository.ExistParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue))
                //        {
                //            CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, InformationLibreArticle.Inf_Catalogue + 1, CatalogRepository.ReadParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue).Cat_Id);
                //        }
                //    }
                //    else
                //    {
                //        if (InformationLibreArticleRepository.ExistInfoLibreLevel(InformationLibreArticle.Inf_Parent, 2))
                //        {
                //            InformationLibreArticleCatalogueParent = InformationLibreArticleRepository.ReadInfoLibre(InformationLibreArticle.Inf_Parent, (int)InformationLibreArticle.Inf_Catalogue - 1);
                //            if (CatalogRepository.ExistName(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref)))
                //            {
                //                Parent = CatalogRepository.ReadParent(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref), 2);

                //                if (Parent != null)
                //                {
                //                    CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, 3, Parent.Cat_Id);
                //                }
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#7
0
        public ImportPrestashopArticleManuel()
        {
            InitializeComponent();
            Model.Prestashop.PsProductRepository  PsProductRepository = new Model.Prestashop.PsProductRepository();
            List <Model.Prestashop.ProductResume> list = PsProductRepository.ListResume();

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <int> listlocal = ArticleRepository.ListPrestashop();

            list = list.Where(p => !listlocal.Contains((int)p.id_product)).ToList();
            dataGridPsProduct.ItemsSource = list;
        }
        public Boolean Exec(String PathDoc, Int32 ArticleSend, String Name, String Description, int?cbMarqSageMedia)
        {
            Boolean result            = false;
            Int32   IdArticleDocument = 0;

            try
            {
                Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                Model.Local.Attachment           Attachment           = new Model.Local.Attachment();

                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                Attachment.Att_File = Core.Global.GetRandomHexNumber(40).ToLower();

                String[] ArrayFileName = PathDoc.Split('\\');
                Attachment.Att_FileName = ArrayFileName[ArrayFileName.Length - 1];
                if (AttachmentRepository.ExistFileArticle(Attachment.Att_FileName, ArticleSend) == false)
                {
                    string name = (!string.IsNullOrWhiteSpace(Name)) ? Name : Attachment.Att_FileName;
                    Attachment.Att_Name = (name.Length > 32) ? name.Substring(0, 32) : name;
                    string description = (!string.IsNullOrWhiteSpace(Description)) ? Description : name;
                    Attachment.Att_Description = description;

                    Attachment.Att_Mime = Attachment.GetMimeType(Attachment.Att_FileName);

                    Attachment.Art_Id = Article.Art_Id;
                    Attachment.Sag_Id = cbMarqSageMedia;
                    AttachmentRepository.Add(Attachment);
                    IdArticleDocument = Attachment.Att_Id;

                    this.CopyFile(Attachment, AttachmentRepository, Global.GetConfig().Folders.RootAttachment, PathDoc);

                    result = true;
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
                if (ex.ToString().Contains("System.UnauthorizedAccessException") && IdArticleDocument != 0)
                {
                    Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                    AttachmentRepository.Delete(AttachmentRepository.ReadAttachment(IdArticleDocument));
                }
            }
            return(result);
        }
示例#9
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                if (ArticleRepository.ExistArticle(ArticleSend))
                {
                    Model.Local.Article            Article             = ArticleRepository.ReadArticle(ArticleSend);
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();

                    string AR_Ref = Article.Art_Ref;

                    // ajout gestion lecture des informations pour une composition
                    if (!F_ARTICLERepository.ExistReference(Article.Art_Ref) &&
                        Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition &&
                        Article.CompositionArticle != null && Article.CompositionArticle.Count > 0)
                    {
                        int sag_id = (from Table in Article.CompositionArticle
                                      orderby Table.ComArt_Default descending
                                      select Table.ComArt_F_ARTICLE_SagId).FirstOrDefault();
                        Model.Sage.F_ARTICLE_Light light = F_ARTICLERepository.ReadLight(sag_id);
                        if (light != null && !string.IsNullOrWhiteSpace(light.AR_Ref))
                        {
                            AR_Ref = light.AR_Ref;
                        }
                    }

                    if (F_ARTICLERepository.ExistReference(AR_Ref))
                    {
                        if (ImportValues(Article, AR_Ref))
                        {
                            if (Core.Temp.UpdateDateActive)
                            {
                                Article.Art_Date = DateTime.Now;
                            }

                            ArticleRepository.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#10
0
        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());
            }
        }
示例#11
0
 /// <summary>
 /// ExecArticle - Supprime toutes les images d'un article
 /// </summary>
 /// <param name="ArticleSend"></param>
 public void ExecArticle(Int32 ArticleSend, Boolean OnlyIfNotSourceExist, out List <string> log_out)
 {
     log_out = new List <string>();
     try
     {
         Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
         if (ArticleRepository.ExistArticle(ArticleSend))
         {
             Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
             List <Model.Local.ArticleImage>    List = ArticleImageRepository.ListArticle(ArticleSend);
             if (List != null)
             {
                 Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend);
                 foreach (Model.Local.ArticleImage ArticleImage in List)
                 {
                     List <string> log = null;
                     if (OnlyIfNotSourceExist)
                     {
                         if (!System.IO.File.Exists(System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, ArticleImage.ImaArt_SourceFile)))
                         {
                             Exec(ArticleImage, Article, out log);
                         }
                     }
                     else
                     {
                         Exec(ArticleImage, Article, out log);
                     }
                     if (log != null && log.Count > 0)
                     {
                         log_out.AddRange(log);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
示例#12
0
 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());
     }
 }
示例#13
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProductRepository ProductRepository, Boolean isProduct)
        {
            try
            {
                if (isProduct)
                {
                    Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();
                    Model.Local.Catalog           Catalog           = CatalogRepository.ReadId(Article.Cat_Id);

                    if (Catalog.Pre_Id != null && new Model.Prestashop.PsCategoryRepository().ExistId((int)Catalog.Pre_Id))
                    {
                        Product.IDCategoryDefault = Convert.ToUInt32(Catalog.Pre_Id);

                        ProductRepository.Save();

                        this.AssignCatalogProduct(Article, Product, ArticleRepository);

                        // <JG> 17/12/2012
                        this.ExecShopProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#14
0
        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());
            }
        }
示例#15
0
 public void RecoveryChildData(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Local.ArticleRepository ArticleRepository, Boolean ExistLocal)
 {
     ReadRedirection(Article);
     AssociateCatalogue(PsProduct, Article, ArticleRepository);
     RecoveryDataProductAttribute(PsProduct);
     ImportCharacteristic(PsProduct, Article, true);
 }
        public void Exec(Model.Prestashop.PsProductAttachment PsProductAttachment)
        {
            try
            {
                //<YH> 21/08/2012
                string DirAttachment = Global.GetConfig().Folders.RootAttachment;

                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                if (ArticleRepository.ExistPre_Id(Convert.ToInt32(PsProductAttachment.IDProduct)))
                {
                    Model.Local.Article Article = ArticleRepository.ReadPre_Id(Convert.ToInt32(PsProductAttachment.IDProduct));
                    Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                    if (AttachmentRepository.ExistPre_IdArt_Id(Convert.ToInt32(PsProductAttachment.IDAttachment), Article.Art_Id) == false)
                    {
                        Model.Prestashop.PsAttachmentRepository     PsAttachmentRepository     = new Model.Prestashop.PsAttachmentRepository();
                        Model.Prestashop.PsAttachment               PsAttachment               = PsAttachmentRepository.ReadAttachment(PsProductAttachment.IDAttachment);
                        Model.Prestashop.PsAttachmentLangRepository PsAttachmentLangRepository = new Model.Prestashop.PsAttachmentLangRepository();
                        if (PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang))
                        {
                            Model.Prestashop.PsAttachmentLang PsAttachmentLang = PsAttachmentLangRepository.ReadAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang);
                            Model.Local.Attachment            Attachment       = new Model.Local.Attachment()
                            {
                                Att_FileName    = PsAttachment.FileName,
                                Att_Description = PsAttachmentLang.Description,
                                Att_Mime        = PsAttachment.Mime,
                                Att_Name        = PsAttachmentLang.Name,
                                Att_File        = this.ReadFile(DirAttachment, PsAttachment.File),
                                Pre_Id          = Convert.ToInt32(PsAttachment.IDAttachment),
                                Art_Id          = Article.Art_Id
                            };
                            AttachmentRepository.Add(Attachment);

                            String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                            String User     = Core.Global.GetConfig().ConfigFTPUser;
                            String Password = Core.Global.GetConfig().ConfigFTPPassword;

                            // <JG> 21/05/2013 correction recherche fichier sur le ftp
                            string ftpfullpath           = FTP + "/download/" + PsAttachment.File;
                            System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                            ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                            ftp.UseBinary   = true;
                            ftp.UsePassive  = true;
                            ftp.KeepAlive   = false;
                            ftp.EnableSsl   = Core.Global.GetConfig().ConfigFTPSSL;

                            System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)ftp.GetResponse();
                            Stream reader = response.GetResponseStream();

                            MemoryStream memStream      = new MemoryStream();
                            byte[]       buffer         = new byte[1024];
                            byte[]       downloadedData = new byte[0];
                            while (true)
                            {
                                int bytesRead = reader.Read(buffer, 0, buffer.Length);
                                if (bytesRead != 0)
                                {
                                    memStream.Write(buffer, 0, bytesRead);
                                }
                                else
                                {
                                    break;
                                }
                                downloadedData = memStream.ToArray();
                            }

                            if (downloadedData != null && downloadedData.Length != 0)
                            {
                                FileStream newFile = new FileStream(DirAttachment + Attachment.Att_File, FileMode.Create);
                                newFile.Write(downloadedData, 0, downloadedData.Length);
                                newFile.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public Boolean Exec(String PathImg, Int32 ArticleSend, int position, int Declination)
        {
            Boolean result         = false;
            Int32   IdArticleImage = 0;

            try
            {
                String extension = Path.GetExtension(PathImg);
                String FileName  = Path.GetFileName(PathImg);

                Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();

                if (!ArticleImageRepository.ExistArticleFile(ArticleSend, FileName))
                {
                    Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                    Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);
                    Model.Local.ArticleImage      ArticleImage      = new Model.Local.ArticleImage()
                    {
                        Art_Id            = Article.Art_Id,
                        ImaArt_Name       = Article.Art_Name,
                        ImaArt_Image      = "",
                        ImaArt_DateAdd    = DateTime.Now,
                        ImaArt_SourceFile = FileName
                    };
                    ArticleImage.ImaArt_Position = this.ReadNextPosition(Article, position);
                    ArticleImage.ImaArt_Default  = !(new Model.Local.ArticleImageRepository().ExistArticleDefault(Article.Art_Id, true));
                    ArticleImageRepository.Add(ArticleImage);
                    ArticleImage.ImaArt_Image = String.Format("{0}" + extension, ArticleImage.ImaArt_Id);
                    ArticleImageRepository.Save();
                    IdArticleImage = ArticleImage.ImaArt_Id;

                    string uri = PathImg.Replace("File:///", "").Replace("file:///", "").Replace("File://", "\\\\").Replace("file://", "\\\\").Replace("/", "\\");

                    System.IO.File.Copy(uri, ArticleImage.TempFileName);

                    Model.Prestashop.PsImageTypeRepository PsImageTypeRepository = new Model.Prestashop.PsImageTypeRepository();
                    List <Model.Prestashop.PsImageType>    ListPsImageType       = PsImageTypeRepository.ListProduct(1);

                    System.Drawing.Image img = System.Drawing.Image.FromFile(ArticleImage.TempFileName);

                    foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                    {
                        Core.Img.resizeImage(img, Convert.ToInt32(PsImageType.Width), Convert.ToInt32(PsImageType.Height),
                                             ArticleImage.FileName(PsImageType.Name));
                    }

                    Core.Img.resizeImage(img, Core.Global.GetConfig().ConfigImageMiniatureWidth, Core.Global.GetConfig().ConfigImageMiniatureHeight,
                                         ArticleImage.SmallFileName);

                    img.Dispose();

                    // <JG> 28/10/2015 ajout attribution gamme/images
                    if (Declination != 0)
                    {
                        if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMonoGamme ||
                            ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMultiGammes)
                        {
                            Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                            if (AttributeArticleRepository.Exist(Declination))
                            {
                                Model.Local.AttributeArticleImageRepository AttributeArticleImageRepository = new Model.Local.AttributeArticleImageRepository();
                                if (!AttributeArticleImageRepository.ExistAttributeArticleImage(Declination, ArticleImage.ImaArt_Id))
                                {
                                    AttributeArticleImageRepository.Add(new Model.Local.AttributeArticleImage()
                                    {
                                        AttArt_Id = Declination,
                                        ImaArt_Id = ArticleImage.ImaArt_Id,
                                    });
                                }
                            }
                        }
                        else if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                        {
                            Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                            if (CompositionArticleRepository.Exist(Declination))
                            {
                                Model.Local.CompositionArticleImageRepository CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository();
                                if (!CompositionArticleImageRepository.ExistCompositionArticleImage(Declination, ArticleImage.ImaArt_Id))
                                {
                                    CompositionArticleImageRepository.Add(new Model.Local.CompositionArticleImage()
                                    {
                                        ComArt_Id = Declination,
                                        ImaArt_Id = ArticleImage.ImaArt_Id,
                                    });
                                }
                            }
                        }
                    }

                    result = true;
                }
                else if (Core.Global.GetConfig().ImportImageReplaceFiles)
                {
                    FileInfo importfile = new FileInfo(PathImg);
                    Model.Local.ArticleImage ArticleImage = ArticleImageRepository.ReadArticleFile(ArticleSend, FileName);
                    FileInfo existfile = new FileInfo(ArticleImage.TempFileName);
                    if ((ArticleImage.ImaArt_DateAdd == null || importfile.LastWriteTime > ArticleImage.ImaArt_DateAdd) ||
                        importfile.Length != existfile.Length)
                    {
                        try
                        {
                            // import nouveau fichier
                            string uri = PathImg.Replace("File:///", "").Replace("file:///", "").Replace("File://", "\\\\").Replace("file://", "\\\\").Replace("/", "\\");
                            System.IO.File.Copy(uri, ArticleImage.TempFileName, true);

                            Model.Prestashop.PsImageTypeRepository PsImageTypeRepository = new Model.Prestashop.PsImageTypeRepository();
                            List <Model.Prestashop.PsImageType>    ListPsImageType       = PsImageTypeRepository.ListProduct(1);

                            System.Drawing.Image img = System.Drawing.Image.FromFile(ArticleImage.TempFileName);

                            foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                            {
                                Core.Img.resizeImage(img, Convert.ToInt32(PsImageType.Width), Convert.ToInt32(PsImageType.Height),
                                                     ArticleImage.FileName(PsImageType.Name));
                            }

                            Core.Img.resizeImage(img, Core.Global.GetConfig().ConfigImageMiniatureWidth, Core.Global.GetConfig().ConfigImageMiniatureHeight,
                                                 ArticleImage.SmallFileName);
                            Model.Prestashop.PsImageRepository PsImageRepository = new Model.Prestashop.PsImageRepository();

                            if (ArticleImage.Pre_Id != null && PsImageRepository.ExistImage((uint)ArticleImage.Pre_Id))
                            {
                                String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                                String User     = Core.Global.GetConfig().ConfigFTPUser;
                                String Password = Core.Global.GetConfig().ConfigFTPPassword;

                                Model.Prestashop.PsImage PsImage = PsImageRepository.ReadImage((uint)ArticleImage.Pre_Id);

                                string ftpPath = "/img/p/";
                                switch (Core.Global.GetConfig().ConfigImageStorageMode)
                                {
                                case Core.Parametres.ImageStorageMode.old_system:
                                    #region old_system
                                    // no action on path
                                    break;
                                    #endregion

                                case Core.Parametres.ImageStorageMode.new_system:
                                default:
                                    #region new_system

                                    //System.Net.FtpWebRequest ftp_folder = null;

                                    foreach (char directory in PsImage.IDImage.ToString())
                                    {
                                        ftpPath += directory + "/";

                                        #region MyRegion
                                        try
                                        {
                                            System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(FTP + ftpPath);

                                            request.Credentials = new System.Net.NetworkCredential(User, Password);
                                            request.UsePassive  = true;
                                            request.UseBinary   = true;
                                            request.KeepAlive   = false;

                                            request.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory;

                                            System.Net.FtpWebResponse makeDirectoryResponse = (System.Net.FtpWebResponse)request.GetResponse();
                                        }
                                        catch     //Exception ex
                                        {
                                            //System.Windows.MessageBox.Show(ex.ToString());
                                        }
                                        #endregion
                                    }
                                    break;
                                    #endregion
                                }

                                #region Upload des images
                                extension = ArticleImage.GetExtension;
                                if (System.IO.File.Exists(ArticleImage.TempFileName))
                                {
                                    string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                        ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + ".jpg"
                                        : FTP + ftpPath + PsImage.IDImage + ".jpg";

                                    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.UsePassive = true;
                                    ftp.EnableSsl  = Core.Global.GetConfig().ConfigFTPSSL;
                                    ftp.Method     = System.Net.WebRequestMethods.Ftp.UploadFile;
                                    System.IO.FileStream fs = System.IO.File.OpenRead(ArticleImage.TempFileName);
                                    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();
                                }


                                foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                                {
                                    String localfile = ArticleImage.FileName(PsImageType.Name);
                                    if (System.IO.File.Exists(localfile))
                                    {
                                        string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                            ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + "-" + PsImageType.Name + ".jpg"
                                            : FTP + ftpPath + PsImage.IDImage + "-" + PsImageType.Name + ".jpg";

                                        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.UsePassive = true;
                                        ftp.EnableSsl  = Core.Global.GetConfig().ConfigFTPSSL;
                                        ftp.Method     = System.Net.WebRequestMethods.Ftp.UploadFile;
                                        System.IO.FileStream fs = System.IO.File.OpenRead(localfile);
                                        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
                            }

                            ArticleImage.ImaArt_DateAdd = DateTime.Now;
                            ArticleImageRepository.Save();

                            // <JG> 28/10/2015 ajout attribution gamme/images
                            if (Declination != 0)
                            {
                                if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMonoGamme ||
                                    ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMultiGammes)
                                {
                                    Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                                    if (AttributeArticleRepository.Exist(Declination))
                                    {
                                        Model.Local.AttributeArticleImageRepository AttributeArticleImageRepository = new Model.Local.AttributeArticleImageRepository();
                                        if (!AttributeArticleImageRepository.ExistAttributeArticleImage(Declination, ArticleImage.ImaArt_Id))
                                        {
                                            AttributeArticleImageRepository.Add(new Model.Local.AttributeArticleImage()
                                            {
                                                AttArt_Id = Declination,
                                                ImaArt_Id = ArticleImage.ImaArt_Id,
                                            });
                                        }

                                        // réaffectation côté PrestaShop
                                        Model.Local.AttributeArticle AttributeArticle = AttributeArticleRepository.Read(Declination);
                                        if (AttributeArticle.Pre_Id != null &&
                                            AttributeArticle.Pre_Id != 0)
                                        {
                                            Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository();
                                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)AttributeArticle.Pre_Id, (UInt32)ArticleImage.Pre_Id) == false)
                                            {
                                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                                {
                                                    IDImage            = (UInt32)ArticleImage.Pre_Id,
                                                    IDProductAttribute = (UInt32)AttributeArticle.Pre_Id,
                                                });
                                            }
                                        }
                                    }
                                }
                                else if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                                {
                                    Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                                    if (CompositionArticleRepository.Exist(Declination))
                                    {
                                        Model.Local.CompositionArticleImageRepository CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository();
                                        if (!CompositionArticleImageRepository.ExistCompositionArticleImage(Declination, ArticleImage.ImaArt_Id))
                                        {
                                            CompositionArticleImageRepository.Add(new Model.Local.CompositionArticleImage()
                                            {
                                                ComArt_Id = Declination,
                                                ImaArt_Id = ArticleImage.ImaArt_Id,
                                            });
                                        }

                                        // réaffectation côté PrestaShop
                                        Model.Local.CompositionArticle CompositionArticle = CompositionArticleRepository.Read(Declination);
                                        if (CompositionArticle.Pre_Id != null &&
                                            CompositionArticle.Pre_Id != 0)
                                        {
                                            Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository();
                                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)CompositionArticle.Pre_Id, (UInt32)ArticleImage.Pre_Id) == false)
                                            {
                                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                                {
                                                    IDImage            = (UInt32)ArticleImage.Pre_Id,
                                                    IDProductAttribute = (UInt32)CompositionArticle.Pre_Id,
                                                });
                                            }
                                        }
                                    }
                                }
                            }

                            result = true;

                            logs.Add("II30- Remplacement de l'image " + ArticleImage.ImaArt_SourceFile + " en position " + ArticleImage.ImaArt_Position + " pour l'article " + ArticleImage.Article.Art_Ref);
                        }
                        catch (Exception ex)
                        {
                            Core.Error.SendMailError(ex.ToString());
                            logs.Add("II39- Erreur lors du remplacement de l'image " + ArticleImage.ImaArt_SourceFile + " en position " + ArticleImage.ImaArt_Position + " pour l'article " + ArticleImage.Article.Art_Ref);
                            logs.Add(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
                if (ex.ToString().Contains("System.UnauthorizedAccessException") && IdArticleImage != 0)
                {
                    Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
                    ArticleImageRepository.Delete(ArticleImageRepository.ReadArticleImage(IdArticleImage));
                }
            }
            return(result);
        }
        public void Exec(Int32 ImageSend)
        {
            try
            {
                Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
                if (ArticleImageRepository.ExistPre_Id(ImageSend) == false)
                {
                    Model.Prestashop.PsImageRepository PsImageRepository = new Model.Prestashop.PsImageRepository();
                    Model.Prestashop.PsImage           PsImage           = PsImageRepository.ReadImage(Convert.ToUInt32(ImageSend));
                    Model.Local.ArticleRepository      ArticleRepository = new Model.Local.ArticleRepository();
                    if (ArticleRepository.ExistPre_Id(Convert.ToInt32(PsImage.IDProduct)))
                    {
                        Model.Local.Article Article = ArticleRepository.ReadPre_Id(Convert.ToInt32(PsImage.IDProduct));

                        Model.Prestashop.PsImageLangRepository PsImageLangRepository = new Model.Prestashop.PsImageLangRepository();
                        if (PsImageLangRepository.ExistImageLang(Convert.ToUInt32(ImageSend), Core.Global.Lang))
                        {
                            string extension = Core.Img.jpgExtension;
                            String FTP       = Core.Global.GetConfig().ConfigFTPIP;
                            String User      = Core.Global.GetConfig().ConfigFTPUser;
                            String Password  = Core.Global.GetConfig().ConfigFTPPassword;

                            Model.Prestashop.PsImageLang PsImageLang  = PsImageLangRepository.ReadImageLang(Convert.ToUInt32(ImageSend), Core.Global.Lang);
                            Model.Local.ArticleImage     ArticleImage = new Model.Local.ArticleImage()
                            {
                                ImaArt_Name       = (!String.IsNullOrEmpty(PsImageLang.Legend)) ? PsImageLang.Legend : Article.Art_Ref,
                                ImaArt_Position   = PsImage.Position,
                                ImaArt_Default    = Convert.ToBoolean(PsImage.Cover),
                                Pre_Id            = Convert.ToInt32(PsImage.IDImage),
                                Art_Id            = Article.Art_Id,
                                ImaArt_Image      = string.Empty,
                                ImaArt_SourceFile = SearchFreeNameFile(Article.Art_Id, Article.Art_Ref, extension),
                                ImaArt_DateAdd    = DateTime.Now
                            };
                            ArticleImageRepository.Add(ArticleImage);

                            Boolean import_img = false;
                            try
                            {
                                // <JG> 10/04/2013 gestion système d'images
                                string ftpPath = "/img/p/";
                                switch (Core.Global.GetConfig().ConfigImageStorageMode)
                                {
                                case Core.Parametres.ImageStorageMode.old_system:
                                    #region old_system
                                    // no action on path
                                    break;
                                    #endregion

                                case Core.Parametres.ImageStorageMode.new_system:
                                default:
                                    #region new_system

                                    foreach (char directory in PsImage.IDImage.ToString())
                                    {
                                        ftpPath += directory + "/";
                                    }
                                    break;
                                    #endregion
                                }

                                // <JG> 21/05/2013 import image originale
                                Boolean import_img_tmp = false;
                                try
                                {
                                    string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                        ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + Core.Img.jpgExtension
                                        : FTP + ftpPath + PsImage.IDImage + Core.Img.jpgExtension;

                                    bool existfile = Core.Ftp.ExistFile(ftpfullpath, User, Password);
                                    if (existfile)
                                    {
                                        System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                        ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                        ftp.UseBinary   = true;
                                        ftp.UsePassive  = true;
                                        ftp.KeepAlive   = false;
                                        ftp.EnableSsl   = Core.Global.GetConfig().ConfigFTPSSL;

                                        System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)ftp.GetResponse();
                                        Stream reader = response.GetResponseStream();

                                        MemoryStream memStream      = new MemoryStream();
                                        byte[]       buffer         = new byte[1024];
                                        byte[]       downloadedData = new byte[0];
                                        while (true)
                                        {
                                            int bytesRead = reader.Read(buffer, 0, buffer.Length);
                                            if (bytesRead != 0)
                                            {
                                                memStream.Write(buffer, 0, bytesRead);
                                            }
                                            else
                                            {
                                                break;
                                            }
                                            downloadedData = memStream.ToArray();
                                        }

                                        string target_folder = (Core.Global.GetConfig().ConfigLocalStorageMode == Parametres.LocalStorageMode.simple_system)
                                            ? Global.GetConfig().Folders.TempArticle
                                            : ArticleImage.advanced_folder;

                                        if (downloadedData != null && downloadedData.Length != 0)
                                        {
                                            FileStream newFile = new FileStream(
                                                System.IO.Path.Combine(target_folder, String.Format("{0}" + extension, ArticleImage.ImaArt_Id)),
                                                FileMode.Create);
                                            newFile.Write(downloadedData, 0, downloadedData.Length);
                                            newFile.Close();
                                            newFile.Dispose();
                                            memStream.Dispose();
                                            downloadedData = new byte[0];
                                        }
                                        string local_file_tmp = System.IO.Path.Combine(target_folder, String.Format("{0}" + extension, ArticleImage.ImaArt_Id));

                                        // <JG> 30/09/2013 détection encodage PNG lors de l'import
                                        Boolean rename_to_png    = false;
                                        System.Drawing.Image img = System.Drawing.Image.FromFile(local_file_tmp);
                                        var imgguid = img.RawFormat.Guid;
                                        img.Dispose();
                                        System.Drawing.Imaging.ImageCodecInfo search;
                                        foreach (System.Drawing.Imaging.ImageCodecInfo codec in System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders())
                                        {
                                            if (codec.FormatID == imgguid)
                                            {
                                                search = codec;
                                                if (search.FormatDescription == "PNG")
                                                {
                                                    rename_to_png = true;
                                                }
                                                break;
                                            }
                                        }
                                        if (rename_to_png)
                                        {
                                            if (System.IO.File.Exists(local_file_tmp))
                                            {
                                                extension = Core.Img.pngExtension;
                                                System.IO.File.Move(local_file_tmp, System.IO.Path.Combine(target_folder, String.Format("{0}" + extension, ArticleImage.ImaArt_Id)));
                                            }
                                            ArticleImage.ImaArt_SourceFile = SearchFreeNameFile(Article.Art_Id, Article.Art_Ref, extension);
                                        }
                                        ArticleImage.ImaArt_Image = String.Format("{0}" + extension, ArticleImage.ImaArt_Id);
                                        ArticleImageRepository.Save();

                                        Core.Img.resizeImage(new System.Drawing.Bitmap(ArticleImage.TempFileName),
                                                             Core.Global.GetConfig().ConfigImageMiniatureWidth,
                                                             Core.Global.GetConfig().ConfigImageMiniatureHeight,
                                                             ArticleImage.SmallFileName);
                                        import_img_tmp = true;
                                    }
                                }
                                catch (Exception)
                                {
                                    // Not implemented
                                }
                                if (import_img_tmp)
                                {
                                    Model.Prestashop.PsImageTypeRepository PsImageTypeRepository = new Model.Prestashop.PsImageTypeRepository();
                                    List <Model.Prestashop.PsImageType>    ListPsImageType       = PsImageTypeRepository.ListProduct(1);
                                    foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                                    {
                                        string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                            ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + "-" + PsImageType.Name + Core.Img.jpgExtension
                                            : FTP + ftpPath + PsImage.IDImage + "-" + PsImageType.Name + Core.Img.jpgExtension;

                                        System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                        ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                        ftp.UseBinary   = true;
                                        ftp.UsePassive  = true;
                                        ftp.KeepAlive   = false;
                                        ftp.EnableSsl   = Core.Global.GetConfig().ConfigFTPSSL;

                                        System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)ftp.GetResponse();
                                        Stream reader = response.GetResponseStream();

                                        MemoryStream memStream      = new MemoryStream();
                                        byte[]       buffer         = new byte[1024];
                                        byte[]       downloadedData = new byte[0];
                                        while (true)
                                        {
                                            int bytesRead = reader.Read(buffer, 0, buffer.Length);
                                            if (bytesRead != 0)
                                            {
                                                memStream.Write(buffer, 0, bytesRead);
                                            }
                                            else
                                            {
                                                break;
                                            }
                                            downloadedData = memStream.ToArray();
                                        }

                                        if (downloadedData != null && downloadedData.Length != 0)
                                        {
                                            FileStream newFile = new FileStream(ArticleImage.FileName(PsImageType.Name), FileMode.Create);
                                            newFile.Write(downloadedData, 0, downloadedData.Length);
                                            newFile.Close();
                                        }
                                    }
                                    import_img = true;

                                    // gestion image par défaut
                                    if (ArticleImage.ImaArt_Default)
                                    {
                                        List <Model.Local.ArticleImage> ListArticleImage = ArticleImageRepository.ListArticle(ArticleImage.Art_Id.Value);
                                        if (ListArticleImage.Count(i => i.ImaArt_Default == true && i.ImaArt_Id != ArticleImage.ImaArt_Id) > 0)
                                        {
                                            foreach (Model.Local.ArticleImage ArticleImageDefault in ListArticleImage.Where(i => i.ImaArt_Default == true && i.ImaArt_Id != ArticleImage.ImaArt_Id))
                                            {
                                                ArticleImageDefault.ImaArt_Default = false;
                                                ArticleImageRepository.Save();
                                            }
                                        }
                                    }

                                    // liens images déclinaisons
                                    ExecAttributeImage(PsImage, ArticleImage);
                                }
                            }
                            catch (Exception ex)
                            {
                                Core.Error.SendMailError("[DOWNLOAD FTP IMAGE ARTICLE]<br />" + ex.ToString());
                                ArticleImageRepository.Delete(ArticleImage);
                            }
                            if (!import_img)
                            {
                                ArticleImageRepository.Delete(ArticleImage);
                            }
                        }
                    }
                }
                else if (ArticleImageRepository.ExistPrestaShop(ImageSend))
                {
                    // import des affectations aux déclinaisons
                    Model.Prestashop.PsImageRepository PsImageRepository = new Model.Prestashop.PsImageRepository();
                    Model.Prestashop.PsImage           PsImage           = PsImageRepository.ReadImage(Convert.ToUInt32(ImageSend));
                    Model.Local.ArticleImage           ArticleImage      = ArticleImageRepository.ReadPrestaShop(ImageSend);
                    ExecAttributeImage(PsImage, ArticleImage);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public void CreateCompositionArticle()
        {
            if (SelectedResultSearchCompositionArticle != null)
            {
                Model.Sage.F_ARTICLE F_ARTICLE = new Model.Sage.F_ARTICLERepository().ReadArticle(SelectedResultSearchCompositionArticle.cbMarq);
                if (F_ARTICLE != null)
                {
                    Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();

                    string dft = Core.Global.RemovePurge(SelectedResultSearchCompositionArticle.AR_Design, 255);

                    Model.Local.Article Article = new Model.Local.Article()
                    {
                        Art_Name              = dft,
                        Art_Type              = (short)Model.Local.Article.enum_TypeArticle.ArticleComposition,
                        Art_Description       = SelectedResultSearchCompositionArticle.AR_Design,
                        Art_Description_Short = SelectedResultSearchCompositionArticle.AR_Design,
                        Art_MetaTitle         = dft,
                        Art_MetaDescription   = dft,
                        Art_MetaKeyword       = Core.Global.RemovePurgeMeta(dft, 255),
                        Art_LinkRewrite       = Core.Global.ReadLinkRewrite(dft),
                        Art_Active            = Core.Global.GetConfig().ImportArticleStatutActif,
                        Art_Date              = DateTime.Now,
                        Art_Solde             = false,
                        Art_Sync              = false,
                        Sag_Id              = 0,
                        Cat_Id              = 0,
                        Art_RedirectType    = new Model.Internal.RedirectType(Core.Parametres.RedirectType.NoRedirect404).Page,
                        Art_RedirectProduct = 0,
                        // champs non renseignés pour les compositions
                        Art_Pack  = false,
                        Art_Ref   = string.Empty,
                        Art_Ean13 = string.Empty,
                    };

                    Core.ImportSage.ImportArticle ImportArticle = new Core.ImportSage.ImportArticle();
                    Article.Cat_Id = ImportArticle.ReadCatalog(F_ARTICLE);

                    if (Article.Cat_Id == 0 && Core.Temp.selectedcatalog_composition != 0)
                    {
                        Article.Cat_Id = Core.Temp.selectedcatalog_composition;
                    }

                    if (Article.Cat_Id != 0)
                    {
                        ArticleRepository.Add(Article);

                        ImportArticle.AssignCatalog(0, Article.Cat_Id, Article, Core.Global.GetConfig().ImportArticleRattachementParents);

                        Core.ImportSage.ImportStatInfoLibreArticle ImportStatInfoLibreArticle = new Core.ImportSage.ImportStatInfoLibreArticle();
                        ImportStatInfoLibreArticle.ImportValues(Article, F_ARTICLE.AR_Ref);

                        PRESTACONNECT.Loading Loading = new PRESTACONNECT.Loading();
                        Loading.Show();

                        Core.Temp.selected_taxe_composition  = SelectedF_TAXE;
                        Core.Temp.reference_sage_composition = F_ARTICLE.AR_Ref;
                        Core.Temp.designation_composition    = F_ARTICLE.AR_Design;

                        PRESTACONNECT.Article Form = new Article(Article);
                        Loading.Close();
                        Form.ShowDialog();

                        if (FilterComposition)
                        {
                            SearchArticleComposition();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Aucune correspondance catalogue n'a été trouvée !", "Lien catalogue absent", MessageBoxButton.OK, MessageBoxImage.Stop);
                    }
                }
            }
        }
        public void SearchArticleComposition()
        {
            if (SelectedF_TAXE == null)
            {
                MessageBox.Show("Veuillez sélectionner une taxe !", "Recherche article", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                List <Model.Sage.F_ARTICLE_Composition> temp = new Model.Sage.F_ARTICLERepository().ListComposition();

                // Filtres sommeil et publié
                bool sommeil   = Core.Global.GetConfig().ArticleEnSommeil;
                bool nonpublie = Core.Global.GetConfig().ArticleNonPublieSurLeWeb;
                // <JG> 19/12/2016 ajout filtre gammes
                temp = temp.Where(ar => (sommeil || ar.AR_Sommeil == 0) && (nonpublie || ar.AR_Publie == 1) && (sommeil || ar.AE_Sommeil != 1)).ToList();

                Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                Model.Local.ArticleRepository            ArticleRepository            = new Model.Local.ArticleRepository();

                // FILTRE TAXE OBLIGATOIRE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                #region Taxes
                switch (Core.Global.GetConfig().TaxSageTVA)
                {
                case PRESTACONNECT.Core.Parametres.TaxSage.CodeTaxe1:
                    temp = temp.Where(a => a.TA_Code1 == SelectedF_TAXE.TA_Code || (string.IsNullOrEmpty(a.TA_Code1) && a.TA_CodeFamille1 == SelectedF_TAXE.TA_Code)).ToList();
                    break;

                case PRESTACONNECT.Core.Parametres.TaxSage.CodeTaxe2:
                    temp = temp.Where(a => a.TA_Code2 == SelectedF_TAXE.TA_Code || (string.IsNullOrEmpty(a.TA_Code2) && a.TA_CodeFamille2 == SelectedF_TAXE.TA_Code)).ToList();
                    break;

                case PRESTACONNECT.Core.Parametres.TaxSage.CodeTaxe3:
                    temp = temp.Where(a => a.TA_Code3 == SelectedF_TAXE.TA_Code || (string.IsNullOrEmpty(a.TA_Code3) && a.TA_CodeFamille3 == SelectedF_TAXE.TA_Code)).ToList();
                    break;

                case PRESTACONNECT.Core.Parametres.TaxSage.Empty:
                default:
                    temp = new List <Model.Sage.F_ARTICLE_Composition>();
                    break;
                }
                #endregion

                if (temp.Count == 0)
                {
                    MessageBox.Show("Aucun résultat pour la taxe sélectionnée !", "Recherche article", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    // filtres
                    if (SelectedF_FAMILLE != null)
                    {
                        temp = temp.Where(ar => ar.FA_CodeFamille == SelectedF_FAMILLE.FA_CodeFamille).ToList();
                    }
                    if (SelectedP_GAMME1 != null)
                    {
                        temp = temp.Where(ar => ar.AR_Gamme1 == SelectedP_GAMME1.cbMarq).ToList();
                    }
                    if (SelectedP_GAMME2 != null)
                    {
                        temp = temp.Where(ar => ar.AR_Gamme2 == SelectedP_GAMME1.cbMarq).ToList();
                    }
                    if (SelectedP_CONDITIONNEMENT != null)
                    {
                        temp = temp.Where(ar => ar.AR_Condition == SelectedP_CONDITIONNEMENT.cbMarq).ToList();
                    }
                    if (!string.IsNullOrWhiteSpace(FilterReferenceValue))
                    {
                        if (FilterReferenceContains)
                        {
                            temp = temp.Where(ar => ar.AR_Ref.Contains(FilterReferenceValue)).ToList();
                        }
                        if (FilterReferenceStartWith)
                        {
                            temp = temp.Where(ar => ar.AR_Ref.StartsWith(FilterReferenceValue)).ToList();
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(FilterDesignationValue))
                    {
                        if (FilterDesignationContains)
                        {
                            temp = temp.Where(ar => ar.AR_Design.ToLower().Contains(FilterDesignationValue.ToLower())).ToList();
                        }
                        if (FilterDesignationStartWith)
                        {
                            temp = temp.Where(ar => ar.AR_Design.ToLower().StartsWith(FilterDesignationValue.ToLower())).ToList();
                        }
                    }

                    List <Int32> ListF_ARTICLE_SagId    = null;
                    List <Int32> ListF_ARTENUMREF_SagId = null;
                    List <Int32> ListF_CONDITION_SagId  = null;
                    if (FilterComposition)
                    {
                        ListF_ARTICLE_SagId    = CompositionArticleRepository.ListSageF_ARTICLE();
                        ListF_ARTENUMREF_SagId = CompositionArticleRepository.ListSageF_ARTENUMREF();
                        ListF_CONDITION_SagId  = CompositionArticleRepository.ListSageF_CONDITION();
                    }
                    if (FilterArticle)
                    {
                        if (ListF_ARTICLE_SagId != null)
                        {
                            ListF_ARTICLE_SagId.AddRange(ArticleRepository.ListSageId());
                        }
                        else
                        {
                            ListF_ARTICLE_SagId = ArticleRepository.ListSageId();
                        }
                    }
                    if (ListF_ARTICLE_SagId != null)
                    {
                        temp = temp.Where(ar => !ListF_ARTICLE_SagId.Contains(ar.cbMarq)).ToList();
                    }
                    if (ListF_ARTENUMREF_SagId != null)
                    {
                        temp = temp.Where(ar => ar.F_ARTENUMREF_SagId == null || (ar.F_ARTENUMREF_SagId != null && !ListF_ARTENUMREF_SagId.Contains(ar.F_ARTENUMREF_SagId.Value))).ToList();
                    }
                    if (ListF_CONDITION_SagId != null)
                    {
                        temp = temp.Where(ar => ar.F_CONDITION_SagId == null || (ar.F_CONDITION_SagId != null && !ListF_CONDITION_SagId.Contains(ar.F_CONDITION_SagId.Value))).ToList();
                    }

                    // filtres exclusion
                    int count = temp.Count;
                    List <Model.Sage.F_ARTICLE_Composition> results = Core.Tools.FiltreImportSage.ImportSageFilter(temp);
                    StrCompositionFilteredProducts = (results.Count < count) ? ((count - results.Count) + " résultats dans les filtres d'exclusion") : string.Empty;
                    if (!ShowResultInImportSageFilter)
                    {
                        temp = results;
                    }

                    ListResultSearchCompositionArticle = new ObservableCollection <Model.Sage.F_ARTICLE_Composition>(temp);
                }
            }
        }
示例#21
0
        private void ExecDistantToLocal(Model.Prestashop.PsProduct Product, Model.Local.Article Article, Model.Local.ArticleRepository ArticleRepository)
        {
            try
            {
                #region Recovery Data From CategoryProduct
                Model.Prestashop.PsCategoryProductRepository PsCategoryProductRepository = new Model.Prestashop.PsCategoryProductRepository();
                Model.Local.CatalogRepository         CatalogRepository        = new Model.Local.CatalogRepository();
                Model.Local.ArticleCatalogRepository  ArticleCatalogRepository = new Model.Local.ArticleCatalogRepository();
                Model.Prestashop.PsCategoryRepository PsCategoryRepository     = new Model.Prestashop.PsCategoryRepository();

                // filtrage des catalogues existants dans PC et PS
                List <Model.Local.CatalogLight> ListLocalCatalog = CatalogRepository.ListLight();
                List <uint> ListPrestashopCategory = PsCategoryRepository.ListIdOrderByLevelDepth(Core.Global.CurrentShop.IDShop, PsCategoryRepository.ReadId(Core.Global.CurrentShop.IDCategory).LevelDepth);
                ListLocalCatalog = ListLocalCatalog.Where(lc => ListPrestashopCategory.Count(pc => pc == (uint)lc.Pre_Id) > 0).ToList();

                // filtrage des associations PS par rapport aux catégories PS existantes en tant que catalogue PC
                List <Model.Prestashop.PsCategoryProduct> ListPsCategoryProduct = PsCategoryProductRepository.ListProduct(Product.IDProduct);
                ListPsCategoryProduct = ListPsCategoryProduct.Where(cp => ListLocalCatalog.Count(lc => lc.Pre_Id == cp.IDCategory) > 0).ToList();

                // filtrage des associations PC par rapport aux catégories ayant un ID PS
                List <Model.Local.ArticleCatalog> ListLocal = ArticleCatalogRepository.ListArticle(Article.Art_Id);
                ListLocal = ListLocal.Where(ac => ac.Catalog.Pre_Id != null).ToList();

                // tant que les associations en local contiennent des associations non présentes dans Prestashop
                if (Core.Global.GetConfig().DeleteCatalogProductAssociation)
                {
                    // suppression des occurences inexistantes dans PS
                    while (ListLocal.Count(ac => ListPsCategoryProduct.Count(cp => cp.IDCategory == ac.Catalog.Pre_Id) == 0) > 0)
                    {
                        Model.Local.ArticleCatalog target = ListLocal.FirstOrDefault(ac => ListPsCategoryProduct.Count(cp => cp.IDCategory == ac.Catalog.Pre_Id) == 0);
                        ArticleCatalogRepository.Delete(target);
                        ListLocal.Remove(target);
                    }
                    ;
                }

                // récupération catégorie principale si catalogue existant dans Prestaconnect
                if (Product.IDCategoryDefault != null && Product.IDCategoryDefault != 0 &&
                    ListLocalCatalog.Count(lc => lc.Pre_Id == (int)Product.IDCategoryDefault) > 0)
                {
                    ArticleRepository = new Model.Local.ArticleRepository();
                    Article           = ArticleRepository.ReadArticle(Article.Art_Id);

                    Article.Cat_Id = ListLocalCatalog.FirstOrDefault(lc => lc.Pre_Id == (int)Product.IDCategoryDefault).Cat_Id;
                    ArticleRepository.Save();

                    if (ListLocal.Count(ac => ac.Art_Id == Article.Art_Id && ac.Cat_Id == Article.Cat_Id) == 0)
                    {
                        ArticleCatalogRepository.Add(new Model.Local.ArticleCatalog()
                        {
                            Art_Id = Article.Art_Id,
                            Cat_Id = Article.Cat_Id
                        });
                    }
                }

                // filtre des associations Prestashop par rapport à celles déjà présentes dans Prestaconnect puis ajout
                ListLocal             = ArticleCatalogRepository.ListArticle(Article.Art_Id);
                ListLocal             = ListLocal.Where(ac => ac.Catalog.Pre_Id != null).ToList();
                ListPsCategoryProduct = ListPsCategoryProduct.Where(cp => ListLocal.Count(ac => ac.Catalog.Pre_Id == (Int32)cp.IDCategory) == 0).ToList();
                foreach (Model.Prestashop.PsCategoryProduct PsCategoryProduct in ListPsCategoryProduct)
                {
                    ArticleCatalogRepository.Add(new Model.Local.ArticleCatalog()
                    {
                        Art_Id = Article.Art_Id,
                        Cat_Id = ListLocalCatalog.FirstOrDefault(lc => lc.Pre_Id == (Int32)PsCategoryProduct.IDCategory).Cat_Id
                    });
                }
                #endregion
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#22
0
        private void AssignCatalogProduct(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Local.ArticleRepository ArticleRepository)
        {
            try
            {
                Model.Local.ArticleCatalogRepository         ArticleCatalogRepository    = new Model.Local.ArticleCatalogRepository();
                Model.Local.CatalogRepository                CatalogRepository           = new Model.Local.CatalogRepository();
                Model.Prestashop.PsCategoryProductRepository PsCategoryProductRepository = new Model.Prestashop.PsCategoryProductRepository();
                Model.Prestashop.PsCategoryRepository        PsCategoryRepository        = new Model.Prestashop.PsCategoryRepository();

                // filtrage des catalogues existants dans PC et PS
                List <Model.Local.CatalogLight> ListLocalCatalog = CatalogRepository.ListLight();
                List <uint> ListPrestashopCategory = PsCategoryRepository.ListIdOrderByLevelDepth(Core.Global.CurrentShop.IDShop, PsCategoryRepository.ReadId(Core.Global.CurrentShop.IDCategory).LevelDepth);
                ListLocalCatalog = ListLocalCatalog.Where(lc => ListPrestashopCategory.Count(pc => pc == (uint)lc.Pre_Id) > 0).ToList();

                // filtrage des associations PS par rapport aux catégories PS existantes en tant que catalogue PC
                List <Model.Prestashop.PsCategoryProduct> ListPsCategoryProduct = PsCategoryProductRepository.ListProduct(Product.IDProduct);
                ListPsCategoryProduct = ListPsCategoryProduct.Where(cp => ListLocalCatalog.Count(lc => lc.Pre_Id == cp.IDCategory) > 0).ToList();

                // filtrage des associations PC par rapport aux catégories ayant un ID PS
                List <Model.Local.ArticleCatalog> ListLocal = ArticleCatalogRepository.ListArticle(Article.Art_Id);
                ListLocal = ListLocal.Where(ac => ac.Catalog.Pre_Id != null).ToList();

                if (Core.Global.GetConfig().DeleteCatalogProductAssociation)
                {
                    // suppressions des associations inexistantes dans PC
                    while (ListPsCategoryProduct.Count(cp => ListLocal.Count(ac => ac.Catalog.Pre_Id == cp.IDCategory) == 0) > 0)
                    {
                        Model.Prestashop.PsCategoryProduct target = ListPsCategoryProduct.FirstOrDefault(cp => ListLocal.Count(ac => ac.Catalog.Pre_Id == cp.IDCategory) == 0);
                        PsCategoryProductRepository.Delete(target);
                        ListPsCategoryProduct.Remove(target);
                    }
                    ;
                }

                ListLocal = ListLocal.Where(ac => ListPsCategoryProduct.Count(cp => cp.IDCategory == ac.Catalog.Pre_Id) == 0).ToList();
                foreach (Model.Local.ArticleCatalog ArticleCatalog in ListLocal)
                {
                    uint IDCategory = (UInt32)ArticleCatalog.Catalog.Pre_Id;
                    PsCategoryProductRepository.Add(new Model.Prestashop.PsCategoryProduct()
                    {
                        IDProduct  = Product.IDProduct,
                        IDCategory = IDCategory,
                        Position   = Model.Prestashop.PsCategoryProductRepository.NextPositionProductCatalog(IDCategory),
                    });
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }