예제 #1
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());
            }
        }
예제 #2
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());
            }
        }
예제 #3
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);
 }
예제 #4
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());
     }
 }
예제 #5
0
        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());
            }
        }
예제 #6
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());
            }
        }
예제 #7
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());
            }
        }
예제 #9
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());
            }
        }
예제 #10
0
        public void ImportCharacteristic(Model.Prestashop.PsProduct PsProduct, Model.Local.Article Article, bool ArticleExists)
        {
            Model.Local.ConfigRepository ConfigRepository = new Model.Local.ConfigRepository();
            Model.Local.Config           Config           = ConfigRepository.ReadName(Global.ConfigLang);

            if (Config != null && Global.IsNumeric(Config.Con_Value))
            {
                Model.Prestashop.PsFeatureProductRepository   PsFeatureProductRepository   = new Model.Prestashop.PsFeatureProductRepository();
                Model.Prestashop.PsFeatureValueRepository     PsFeatureValueRepository     = new Model.Prestashop.PsFeatureValueRepository();
                Model.Prestashop.PsFeatureValueLangRepository PsFeatureValueLangRepository = new Model.Prestashop.PsFeatureValueLangRepository();
                Model.Local.CharacteristicRepository          CharacteristicRepository     = new Model.Local.CharacteristicRepository();

                foreach (Model.Prestashop.PsFeatureProduct FeatureProduct in PsFeatureProductRepository.List(PsProduct.IDProduct))
                {
                    Model.Prestashop.PsFeatureValue     PsFeatureValue     = PsFeatureValueRepository.ReadFeatureValue(FeatureProduct.IDFeatureValue);
                    Model.Prestashop.PsFeatureValueLang PsFeatureValueLang = PsFeatureValueLangRepository.ReadFeatureValueLang(FeatureProduct.IDFeatureValue, Convert.ToUInt32(Config.Con_Value));

                    Model.Local.Characteristic Characteristic = null;

                    if (ArticleExists)
                    {
                        Characteristic = CharacteristicRepository.ReadFeatureArticle((int)FeatureProduct.IDFeature, Article.Art_Id);
                    }

                    if (!ArticleExists || Characteristic == null)
                    {
                        Characteristic = new Model.Local.Characteristic()
                        {
                            Art_Id        = Article.Art_Id,
                            Cha_Custom    = Convert.ToBoolean(PsFeatureValue.Custom),
                            Cha_IdFeature = (int)FeatureProduct.IDFeature,
                            Cha_Value     = PsFeatureValueLang.Value,
                            Pre_Id        = (int)FeatureProduct.IDFeatureValue,
                        };

                        CharacteristicRepository.Add(Characteristic);
                    }
                    else
                    {
                        Characteristic.Cha_Custom = Convert.ToBoolean(PsFeatureValue.Custom);
                        Characteristic.Cha_Value  = PsFeatureValueLang.Value;
                        Characteristic.Pre_Id     = (int)FeatureProduct.IDFeatureValue;

                        CharacteristicRepository.Save();
                    }
                }
            }
        }
        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);
        }
예제 #12
0
        public SyncArticle(Model.Local.Article local, Model.Sage.F_ARTICLE sage)
        {
            Local = local;
            Sage  = sage;

            OnPropertyChanged("CanDelete");

            ListRedirectType = new ObservableCollection <RedirectType>();
            foreach (Core.Parametres.RedirectType valeur in Enum.GetValues(typeof(Core.Parametres.RedirectType)))
            {
                ListRedirectType.Add(new RedirectType(valeur));
            }
            if (!String.IsNullOrWhiteSpace(Local.Art_RedirectType) && Core.Global.IsInteger(Local.Art_RedirectType) && ListRedirectType.Count(r => r.Page == Local.Art_RedirectType) == 1)
            {
                SelectedRedirectType = ListRedirectType.First(r => r.Page == Local.Art_RedirectType);
            }
        }
예제 #13
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());
            }
        }
        private Int32 ReadNextPosition(Model.Local.Article Article, int position)
        {
            Int32 Position = (position > 0) ? position : 1;

            try
            {
                List <Int32> ListPosition = new Model.Local.ArticleImageRepository().ListPositionsArticle(Article.Art_Id);
                while (ListPosition.Contains(Position))
                {
                    Position += 1;
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            return(Position);
        }
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
        {
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Quantity = 0;
                        Product.Price    = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        SynchronisationArticle.ExecCompositionArticle(Article, Product, ProductRepository);
                    }
                }
                else
                {
                    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);

                        if ((F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0) || (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0))
                        {
                            int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                            Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                            Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);


                            // <JG> 19/02/2013 déplacement pour correction problème prix spécifiques lors de la création de l'article
                            SynchronisationArticle.ExecAttribute(Article, Product, ProductRepository, TaxeTVA);
                            SynchronisationArticle.ExecConditioning(Article, Product, ProductRepository, TaxeTVA);

                            //List<string> log;
                            //SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article.Art_Id, TaxeTVA, TaxeEco, out log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #16
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());
            }
        }
        private void ExecLocalToDistant(Model.Local.Article Article)
        {
            try
            {
                String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                String User     = Core.Global.GetConfig().ConfigFTPUser;
                String Password = Core.Global.GetConfig().ConfigFTPPassword;

                Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
                List <Model.Local.ArticleImage>    ListArticleImage       = ArticleImageRepository.ListArticle(Article.Art_Id);
                foreach (Model.Local.ArticleImage ArticleImage in ListArticleImage)
                {
                    ExecImage(FTP, User, Password, Article, ArticleImage, ArticleImageRepository);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #18
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());
     }
 }
예제 #19
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());
     }
 }
예제 #20
0
        private void ExecAttribute(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            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.Local.AttributeGroupRepository        AttributeGroupRepository   = new Model.Local.AttributeGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0 &&
                        AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme1) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme1).Pre_Id) &&
                        ((F_ARTICLE.AR_Gamme2 == null || F_ARTICLE.AR_Gamme2 == 0) ||
                         (AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme2) &&
                          PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme2).Pre_Id))))
                    {
                        Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                        List <Model.Local.AttributeArticle>    ListAttributeArticle       = AttributeArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;

                        int CumulStockGammes = 0;
                        foreach (Model.Local.AttributeArticle AttributeArticle in ListAttributeArticle)
                        {
                            if (AttributeArticle.EnumereF_ARTENUMREF != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;

                                if (AttributeArticle.Pre_Id != null && AttributeArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)AttributeArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)AttributeArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (isProductAttribute == true)
                                {
                                    if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                    {
                                        SynchronisationArticle.ReadWeightAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1);
                                    }

                                    SynchronisationArticle.ReadQuantityAttribute(PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2);
                                    CumulStockGammes += PsProductAttribute.Quantity;

                                    // <JG> 03/06/2016
                                    if (Article.Art_SyncPrice)
                                    {
                                        SynchronisationArticle.ReadPriceAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2, TaxeTVA);
                                    }

                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        if (PsProduct.Quantity != CumulStockGammes)
                        {
                            PsProduct.Quantity = CumulStockGammes;
                            PsProductRepository.Save();
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #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());
            }
        }
        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);
                    }
                }
            }
        }
예제 #23
0
        //<YH> 23/08/2012
        private void ExecLocalToDistant(Model.Local.Article Article)
        {
            try
            {
                Model.Prestashop.PsAttachmentRepository PsAttachmentRepository = new Model.Prestashop.PsAttachmentRepository();
                Model.Prestashop.PsAttachment           PsAttachment;

                Model.Prestashop.PsAttachmentLangRepository PsAttachmentLangRepository = new Model.Prestashop.PsAttachmentLangRepository();
                Model.Prestashop.PsAttachmentLang           PsAttachmentLang;

                Model.Prestashop.PsProductAttachmentRepository PsProductAttachmentRepository = new Model.Prestashop.PsProductAttachmentRepository();
                Model.Prestashop.PsProductAttachment           PsProductAttachment;

                Boolean isAttachmentLang = false;

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

                Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                List <Model.Local.Attachment>    ListAttachment       = AttachmentRepository.ListArticle(Article.Art_Id);
                foreach (Model.Local.Attachment Attachment in ListAttachment)
                {
                    try
                    {
                        if (Attachment.Pre_Id == null)
                        {
                            String PathAttachment = Path.Combine(Global.GetConfig().Folders.RootAttachment, Attachment.Att_File);
                            if (System.IO.File.Exists(PathAttachment))
                            {
                                #region infos document joint
                                PsAttachment          = new Model.Prestashop.PsAttachment();
                                PsAttachment.File     = Attachment.Att_File;
                                PsAttachment.FileName = Attachment.Att_FileName;
                                PsAttachment.Mime     = Attachment.Att_Mime;
                                PsAttachmentRepository.Add(PsAttachment);

                                isAttachmentLang = false;
                                PsAttachmentLang = new Model.Prestashop.PsAttachmentLang();
                                if (PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang))
                                {
                                    PsAttachmentLang = PsAttachmentLangRepository.ReadAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang);
                                    isAttachmentLang = true;
                                }
                                PsAttachmentLang.Name        = Attachment.Att_Name;
                                PsAttachmentLang.Description = Attachment.Att_Description;
                                if (isAttachmentLang == true)
                                {
                                    PsAttachmentLangRepository.Save();
                                }
                                else
                                {
                                    PsAttachmentLang.IDAttachment = PsAttachment.IDAttachment;
                                    PsAttachmentLang.IDLang       = Core.Global.Lang;
                                    PsAttachmentLangRepository.Add(PsAttachmentLang);
                                }
                                #endregion

                                // <JG> 24/05/2013 ajout insertion autres langues actives si non renseignées
                                #region Multi-langues
                                try
                                {
                                    Model.Prestashop.PsLangRepository PsLangRepository = new Model.Prestashop.PsLangRepository();
                                    foreach (Model.Prestashop.PsLang PsLang in PsLangRepository.ListActive(1, Global.CurrentShop.IDShop))
                                    {
                                        if (!PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, PsLang.IDLang))
                                        {
                                            PsAttachmentLang = new Model.Prestashop.PsAttachmentLang()
                                            {
                                                IDAttachment = PsAttachment.IDAttachment,
                                                IDLang       = PsLang.IDLang,
                                                Name         = Attachment.Att_Name,
                                                Description  = Attachment.Att_Description
                                            };
                                            PsAttachmentLangRepository.Add(PsAttachmentLang);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError(ex.ToString());
                                }
                                #endregion

                                // affectation au produit
                                PsProductAttachment = new Model.Prestashop.PsProductAttachment();
                                if (PsProductAttachmentRepository.ExistProductAttachment(Convert.ToUInt32(Article.Pre_Id), PsAttachment.IDAttachment) == false)
                                {
                                    PsProductAttachment.IDProduct    = Convert.ToUInt32(Article.Pre_Id);
                                    PsProductAttachment.IDAttachment = PsAttachment.IDAttachment;
                                    PsProductAttachmentRepository.Add(PsProductAttachment);
                                }

                                try
                                {
                                    #region upload

                                    string ftpfullpath           = FTP + "/download/" + Attachment.Att_File;
                                    System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                    ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                    //userid and password for the ftp server to given

                                    ftp.UseBinary = true;
                                    ftp.Method    = System.Net.WebRequestMethods.Ftp.UploadFile;
                                    System.IO.FileStream fs = System.IO.File.OpenRead(PathAttachment);
                                    byte[] buffer           = new byte[fs.Length];
                                    fs.Read(buffer, 0, buffer.Length);
                                    fs.Close();
                                    System.IO.Stream ftpstream = ftp.GetRequestStream();
                                    ftpstream.Write(buffer, 0, buffer.Length);
                                    ftpstream.Close();
                                    ftp.Abort();

                                    #endregion

                                    #region update Product field cache_as_attachements

                                    Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                                    Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(PsProductAttachment.IDProduct);
                                    if (PsProduct.CacheHasAttachments == 0)
                                    {
                                        PsProduct.CacheHasAttachments = (sbyte)1;
                                        PsProductRepository.Save();
                                    }

                                    #endregion

                                    Attachment.Pre_Id = Convert.ToInt32(PsAttachment.IDAttachment);
                                    AttachmentRepository.Save();
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError("[UPLOAD FTP DOCUMENT]<br />" + ex.ToString());
                                    PsProductAttachmentRepository.Delete(PsProductAttachmentRepository.ListAttachment(PsAttachment.IDAttachment));
                                    PsAttachmentLangRepository.Delete(PsAttachmentLangRepository.ListAttachment(PsAttachment.IDAttachment));
                                    PsAttachmentRepository.Delete(PsAttachment);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Core.Error.SendMailError("[SYNCHRO DOCUMENT ARTICLE]<br />" + ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #24
0
        private void DeleteFeatureProduct(Model.Local.InformationLibre InformationLibre, Model.Local.Article Article)
        {
            try
            {
                Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                {
                    Model.Local.Characteristic ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                    //delete prestashop
                    if (Article.Pre_Id != null)
                    {
                        Model.Prestashop.PsFeatureProductRepository PsFeatureProductRepository = new Model.Prestashop.PsFeatureProductRepository();
                        if (PsFeatureProductRepository.ExistFeatureProduct((uint)ArticleCharacteristic.Cha_IdFeature, (uint)Article.Pre_Id))
                        {
                            Model.Prestashop.PsFeatureProduct PsFeatureProduct = PsFeatureProductRepository.ReadFeatureProduct((uint)ArticleCharacteristic.Cha_IdFeature, (uint)Article.Pre_Id);
                            PsFeatureProductRepository.Delete(PsFeatureProduct);

                            Model.Prestashop.PsFeatureValueRepository PsFeatureValueRepository = new Model.Prestashop.PsFeatureValueRepository();
                            if (PsFeatureValueRepository.ExistFeatureValue(PsFeatureProduct.IDFeatureValue))
                            {
                                Model.Prestashop.PsFeatureValue PsFeatureValue = PsFeatureValueRepository.ReadFeatureValue(PsFeatureProduct.IDFeatureValue);
                                //delete all datas if featurevalue is custom
                                if (PsFeatureValue.Custom == 1)
                                {
                                    Model.Prestashop.PsFeatureValueLangRepository PsFeatureValueLangRepository = new Model.Prestashop.PsFeatureValueLangRepository();
                                    PsFeatureValueLangRepository.DeleteAll(PsFeatureValueLangRepository.ListFeatureValue(PsFeatureValue.IDFeatureValue));

                                    PsFeatureValueRepository.Delete(PsFeatureValue);
                                }
                            }
                        }
                    }
                    //delete local
                    CharacteristicRepository.Delete(ArticleCharacteristic);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #25
0
        private void ExecConditioning(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            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.Local.ConditioningGroupRepository     ConditioningGroupRepository = new Model.Local.ConditioningGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository  = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0 &&
                        ConditioningGroupRepository.ExistSage((int)F_ARTICLE.AR_Condition) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)ConditioningGroupRepository.ReadSage((int)F_ARTICLE.AR_Condition).Pre_Id))
                    {
                        Model.Local.ConditioningArticleRepository ConditioningArticleRepository = new Model.Local.ConditioningArticleRepository();
                        List <Model.Local.ConditioningArticle>    ListConditioningArticle       = ConditioningArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;
                        int stockmaxunity = 0;
                        foreach (Model.Local.ConditioningArticle ConditioningArticle in ListConditioningArticle)
                        {
                            if (ConditioningArticle.EnumereF_CONDITION != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;
                                if (ConditioningArticle.Pre_Id != null && ConditioningArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)ConditioningArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)ConditioningArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightConditioning(PsProduct, PsProductAttribute, ConditioningArticle.EnumereF_CONDITION);
                                }

                                SynchronisationArticle.ReadQuantityConditioning(PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION);

                                if (Core.Global.GetConfig().LimiteStockConditionnement&& PsProductAttribute.Quantity >= stockmaxunity)
                                {
                                    stockmaxunity      = PsProductAttribute.Quantity;
                                    PsProduct.Quantity = stockmaxunity;
                                    PsProductRepository.Save();
                                }

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceConditioning(PsProduct, PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION, TaxeTVA);
                                }

                                //PsProductAttribute.DefaultOn = (ConditioningArticle.ConArt_Default) ? (byte)1 : (byte)0;
                                if (isProductAttribute == true)
                                {
                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
예제 #26
0
        public Boolean ImportValues(Model.Local.Article Article, string AR_Ref)
        {
            Boolean HasValue = false;

            try
            {
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();

                #region Informations libre Article

                Model.Local.InformationLibreRepository InformationLibreRepository = new Model.Local.InformationLibreRepository();
                foreach (Model.Local.InformationLibre InformationLibre in InformationLibreRepository.ListSync())
                {
                    // <JG> 21/08/2017 ajout filtre info libre pour automates
                    if (Core.Temp.TaskImportStatInfoLibreFilter == null || Core.Temp.TaskImportStatInfoLibreFilter.Contains(Core.Global.EscapeArgumentSyntax(InformationLibre.Sag_InfoLibre)))
                    {
                        Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(InformationLibre.Sag_InfoLibre, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                        switch (TypeInfoLibre)
                        {
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                            #region text
                            if (F_ARTICLERepository.ExistArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (!string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref))))
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref));;
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        HasValue = true;
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibre.Sag_InfoLibre, AR_Ref)),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

                        case Model.Sage.cbSysLibreRepository.CB_Type.SageValeur:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageMontant:
                            #region decimal
                            if (F_ARTICLERepository.ExistArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref) != null)
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref).Value
                                                                          .ToString((TypeInfoLibre == Model.Sage.cbSysLibreRepository.CB_Type.SageMontant) ? "0.00####" : "0.######");
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        HasValue = true;
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = F_ARTICLERepository.ReadArticleInformationLibreNumerique(InformationLibre.Sag_InfoLibre, AR_Ref).Value
                                                            .ToString((TypeInfoLibre == Model.Sage.cbSysLibreRepository.CB_Type.SageMontant) ? "0.00####" : "0.######"),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

                        case Model.Sage.cbSysLibreRepository.CB_Type.SageDate:
                        case Model.Sage.cbSysLibreRepository.CB_Type.SageSmallDate:
                            #region datetime
                            if (F_ARTICLERepository.ExistArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref))
                            {
                                if (F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref) != null)
                                {
                                    Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                    Model.Local.Characteristic           ArticleCharacteristic;
                                    if (CharacteristicRepository.ExistFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id))
                                    {
                                        ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationLibre.Cha_Id, Article.Art_Id);
                                        string temp_text = ArticleCharacteristic.Cha_Value;
                                        int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                        ArticleCharacteristic.Cha_Value = F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref).ToString();
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Save();
                                        if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                        {
                                            HasValue = true;
                                        }
                                    }
                                    else
                                    {
                                        ArticleCharacteristic = new Model.Local.Characteristic()
                                        {
                                            Art_Id        = Article.Art_Id,
                                            Cha_IdFeature = (int)InformationLibre.Cha_Id,
                                            Cha_Value     = F_ARTICLERepository.ReadArticleInformationLibreDate(InformationLibre.Sag_InfoLibre, AR_Ref).ToString(),
                                        };
                                        switch (InformationLibre.Inf_Mode)
                                        {
                                        case (short)Core.Parametres.InformationLibreValeursMode.Predefinies:
                                            ArticleCharacteristic.Cha_Custom = false;
                                            ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationLibre.Cha_Id);
                                            break;

                                        case (short)Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                            ArticleCharacteristic.Cha_Custom = true;
                                            break;
                                        }
                                        CharacteristicRepository.Add(ArticleCharacteristic);
                                    }
                                }
                                else if (Core.Global.GetConfig().ArticleSuppressionAutoCaracteristique)
                                {
                                    DeleteFeatureProduct(InformationLibre, Article);
                                }
                            }
                            #endregion
                            break;

                        case Model.Sage.cbSysLibreRepository.CB_Type.Deleted:
                        default:
                            break;
                        }
                    }
                }

                #endregion

                // traitement uniquement si absence de filtre sur l'automate
                if (Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    #region Statistiques Article

                    Model.Local.StatistiqueArticleRepository StatistiqueArticleRepository = new Model.Local.StatistiqueArticleRepository();
                    foreach (Model.Local.StatistiqueArticle StatistiqueArticle in StatistiqueArticleRepository.ListSync())
                    {
                        Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                        if (P_INTSTATARTRepository.ExistStatArt(StatistiqueArticle.Sag_StatArt))
                        {
                            Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(StatistiqueArticle.Sag_StatArt);
                            Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                            String stat_value = null;
                            switch (P_INTSTATART.cbMarq)
                            {
                            case 1:
                                stat_value = F_ARTICLE.AR_Stat01;
                                break;

                            case 2:
                                stat_value = F_ARTICLE.AR_Stat02;
                                break;

                            case 3:
                                stat_value = F_ARTICLE.AR_Stat03;
                                break;

                            case 4:
                                stat_value = F_ARTICLE.AR_Stat04;
                                break;

                            case 5:
                                stat_value = F_ARTICLE.AR_Stat05;
                                break;
                            }
                            if (!String.IsNullOrWhiteSpace(stat_value))
                            {
                                Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                Model.Local.Characteristic           ArticleCharacteristic;
                                if (CharacteristicRepository.ExistFeatureArticle(StatistiqueArticle.Cha_Id, Article.Art_Id))
                                {
                                    ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(StatistiqueArticle.Cha_Id, Article.Art_Id);
                                    string temp_text = ArticleCharacteristic.Cha_Value;
                                    int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                    ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(stat_value);
                                    switch (StatistiqueArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, StatistiqueArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Save();
                                    if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                    {
                                        HasValue = true;
                                    }
                                }
                                else
                                {
                                    HasValue = true;
                                    ArticleCharacteristic = new Model.Local.Characteristic()
                                    {
                                        Art_Id        = Article.Art_Id,
                                        Cha_IdFeature = (int)StatistiqueArticle.Cha_Id,
                                        Cha_Value     = Core.Global.SageValueReplacement(stat_value),
                                    };
                                    switch (StatistiqueArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, StatistiqueArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Add(ArticleCharacteristic);
                                }
                            }
                        }
                    }

                    #endregion
                }

                #region Marque/Fabricant

                if (Core.Global.GetConfig().MarqueAutoStatistiqueActif&& Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                    if (P_INTSTATARTRepository.ExistStatArt(Core.Global.GetConfig().MarqueAutoStatistiqueName))
                    {
                        Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(Core.Global.GetConfig().MarqueAutoStatistiqueName);
                        Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                        String stat_value = null;
                        switch (P_INTSTATART.cbMarq)
                        {
                        case 1:
                            stat_value = F_ARTICLE.AR_Stat01;
                            break;

                        case 2:
                            stat_value = F_ARTICLE.AR_Stat02;
                            break;

                        case 3:
                            stat_value = F_ARTICLE.AR_Stat03;
                            break;

                        case 4:
                            stat_value = F_ARTICLE.AR_Stat04;
                            break;

                        case 5:
                            stat_value = F_ARTICLE.AR_Stat05;
                            break;
                        }
                        if (!String.IsNullOrWhiteSpace(stat_value))
                        {
                            int temp_id = Article.Art_Manufacturer;
                            Article.Art_Manufacturer = CreateManufacturer(Core.Global.SageValueReplacement(stat_value));
                            if (temp_id != Article.Art_Manufacturer)
                            {
                                HasValue = true;
                            }
                        }
                    }
                }
                else if (Core.Global.GetConfig().MarqueAutoInfolibreActif)
                {
                    Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(Core.Global.GetConfig().MarqueAutoInfolibreName, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                    switch (TypeInfoLibre)
                    {
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                        #region text
                        if (F_ARTICLERepository.ExistArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref) &&
                            !string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref))))
                        {
                            int temp_id = Article.Art_Manufacturer;
                            Article.Art_Manufacturer = CreateManufacturer(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().MarqueAutoInfolibreName, AR_Ref)));
                            if (temp_id != Article.Art_Manufacturer)
                            {
                                HasValue = true;
                            }
                        }
                        #endregion
                        break;

                    default:
                        break;
                    }
                }

                #endregion

                #region Fournisseur

                if (Core.Global.GetConfig().FournisseurAutoStatistiqueActif&& Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    Model.Sage.P_INTSTATARTRepository P_INTSTATARTRepository = new Model.Sage.P_INTSTATARTRepository();
                    if (P_INTSTATARTRepository.ExistStatArt(Core.Global.GetConfig().FournisseurAutoStatistiqueName))
                    {
                        Model.Sage.P_INTSTATART P_INTSTATART = P_INTSTATARTRepository.ReadStatArt(Core.Global.GetConfig().FournisseurAutoStatistiqueName);
                        Model.Sage.F_ARTICLE    F_ARTICLE    = F_ARTICLERepository.ReadReference(AR_Ref);
                        String stat_value = null;
                        switch (P_INTSTATART.cbMarq)
                        {
                        case 1:
                            stat_value = F_ARTICLE.AR_Stat01;
                            break;

                        case 2:
                            stat_value = F_ARTICLE.AR_Stat02;
                            break;

                        case 3:
                            stat_value = F_ARTICLE.AR_Stat03;
                            break;

                        case 4:
                            stat_value = F_ARTICLE.AR_Stat04;
                            break;

                        case 5:
                            stat_value = F_ARTICLE.AR_Stat05;
                            break;
                        }
                        if (!String.IsNullOrWhiteSpace(stat_value))
                        {
                            int temp_id = Article.Art_Supplier;
                            Article.Art_Supplier = CreateSupplier(Core.Global.SageValueReplacement(stat_value));
                            if (temp_id != Article.Art_Supplier)
                            {
                                HasValue = true;
                            }
                        }
                    }
                }
                else if (Core.Global.GetConfig().FournisseurAutoInfolibreActif)
                {
                    Model.Sage.cbSysLibreRepository.CB_Type TypeInfoLibre = new Model.Sage.cbSysLibreRepository().ReadTypeInformationLibre(Core.Global.GetConfig().FournisseurAutoInfolibreName, Model.Sage.cbSysLibreRepository.CB_File.F_ARTICLE);

                    switch (TypeInfoLibre)
                    {
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageText:
                    case PRESTACONNECT.Model.Sage.cbSysLibreRepository.CB_Type.SageTable:
                        #region text
                        if (F_ARTICLERepository.ExistArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref) &&
                            !string.IsNullOrWhiteSpace(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref))))
                        {
                            int temp_id = Article.Art_Supplier;
                            Article.Art_Supplier = CreateSupplier(Core.Global.SageValueReplacement(F_ARTICLERepository.ReadArticleInformationLibreText(Core.Global.GetConfig().FournisseurAutoInfolibreName, AR_Ref)));
                            if (temp_id != Article.Art_Supplier)
                            {
                                HasValue = true;
                            }
                        }
                        #endregion
                        break;

                    default:
                        break;
                    }
                }

                #endregion

                if (Core.Temp.TaskImportStatInfoLibreFilter == null)
                {
                    #region Information Sage

                    Model.Local.InformationArticleRepository InformationArticleRepository = new Model.Local.InformationArticleRepository();
                    foreach (Model.Local.InformationArticle InformationArticle in InformationArticleRepository.ListSync())
                    {
                        {
                            Model.Internal.SageInfoArticle SageInfoArticle = new Model.Internal.SageInfoArticle((Parametres.SageInfoArticle)InformationArticle.Sag_InfoArt);
                            Model.Sage.F_ARTICLE           F_ARTICLE       = F_ARTICLERepository.ReadReference(AR_Ref);
                            String stat_value = null;
                            switch (SageInfoArticle._SageInfoArticle)
                            {
                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Substitut:
                                stat_value = F_ARTICLE.AR_Substitut;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.FamilleCode:
                                stat_value = F_ARTICLE.FA_CodeFamille;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.FamilleIntitule:
                                if (F_ARTICLE.F_FAMILLE != null && !string.IsNullOrEmpty(F_ARTICLE.F_FAMILLE.FA_Intitule))
                                {
                                    stat_value = F_ARTICLE.F_FAMILLE.FA_Intitule;
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Garantie:
                                if (F_ARTICLE.AR_Garantie != null)
                                {
                                    stat_value = F_ARTICLE.AR_Garantie.Value.ToString();
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.Pays:
                                stat_value = F_ARTICLE.AR_Pays;
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.PoidsNet:
                                if (F_ARTICLE.AR_PoidsNet != null && F_ARTICLE.AR_PoidsNet != 0)
                                {
                                    stat_value = F_ARTICLE.AR_PoidsNet.ToString();
                                }
                                break;

                            case PRESTACONNECT.Core.Parametres.SageInfoArticle.PoidsBrut:
                                if (F_ARTICLE.AR_PoidsBrut != null && F_ARTICLE.AR_PoidsBrut != 0)
                                {
                                    stat_value = F_ARTICLE.AR_PoidsBrut.ToString();
                                }
                                break;
                            }
                            if (!String.IsNullOrWhiteSpace(stat_value))
                            {
                                Model.Local.CharacteristicRepository CharacteristicRepository = new Model.Local.CharacteristicRepository();
                                Model.Local.Characteristic           ArticleCharacteristic;
                                if (CharacteristicRepository.ExistFeatureArticle(InformationArticle.Cha_Id, Article.Art_Id))
                                {
                                    ArticleCharacteristic = CharacteristicRepository.ReadFeatureArticle(InformationArticle.Cha_Id, Article.Art_Id);
                                    string temp_text = ArticleCharacteristic.Cha_Value;
                                    int?   temp_id   = ArticleCharacteristic.Pre_Id;
                                    ArticleCharacteristic.Cha_Value = Core.Global.SageValueReplacement(stat_value);
                                    switch (InformationArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Save();
                                    if (temp_text != ArticleCharacteristic.Cha_Value || temp_id != ArticleCharacteristic.Pre_Id)
                                    {
                                        HasValue = true;
                                    }
                                }
                                else
                                {
                                    HasValue = true;
                                    ArticleCharacteristic = new Model.Local.Characteristic()
                                    {
                                        Art_Id        = Article.Art_Id,
                                        Cha_IdFeature = (int)InformationArticle.Cha_Id,
                                        Cha_Value     = Core.Global.SageValueReplacement(stat_value),
                                    };
                                    switch (InformationArticle.Inf_Mode)
                                    {
                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Predefinies:
                                        ArticleCharacteristic.Cha_Custom = false;
                                        ArticleCharacteristic.Pre_Id     = CreateFeatureValue(ArticleCharacteristic.Cha_Value, InformationArticle.Cha_Id);
                                        break;

                                    case (short)PRESTACONNECT.Core.Parametres.InformationLibreValeursMode.Personnalisees:
                                        ArticleCharacteristic.Cha_Custom = true;
                                        break;
                                    }
                                    CharacteristicRepository.Add(ArticleCharacteristic);
                                }
                            }
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            return(HasValue);
        }
        private void ExecImage(string FTP, string User, string Password, Model.Local.Article Article, Model.Local.ArticleImage ArticleImage, Model.Local.ArticleImageRepository ArticleImageRepository)
        {
            Model.Prestashop.PsImageRepository     PsImageRepository     = new Model.Prestashop.PsImageRepository();
            Model.Prestashop.PsImage               PsImage               = null;
            Model.Prestashop.PsImageLangRepository PsImageLangRepository = new Model.Prestashop.PsImageLangRepository();
            Model.Prestashop.PsImageLang           PsImageLang;
            Boolean isImageLang = false;

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

            try
            {
                if (ArticleImage.Pre_Id == null)
                {
                    PsImage = new Model.Prestashop.PsImage();

                    PsImage.IDProduct = Convert.ToUInt32(Article.Pre_Id);
                    PsImage.Position  = (ushort)ExecPosition((uint)Article.Pre_Id.Value, (uint)ArticleImage.ImaArt_Position, PsImageRepository, PsImage);
                    PsImage.Cover     = ExecCover((uint)Article.Pre_Id.Value, ArticleImage.ImaArt_Default, PsImageRepository, PsImage);
                    PsImageRepository.Add(PsImage, Global.CurrentShop.IDShop);

                    #region lang
                    isImageLang = false;
                    PsImageLang = new Model.Prestashop.PsImageLang();
                    if (PsImageLangRepository.ExistImageLang(PsImage.IDImage, Core.Global.Lang))
                    {
                        PsImageLang = PsImageLangRepository.ReadImageLang(PsImage.IDImage, Core.Global.Lang);
                        isImageLang = true;
                    }
                    PsImageLang.Legend = ArticleImage.ImaArt_Name;
                    if (isImageLang == true)
                    {
                        PsImageLangRepository.Save();
                    }
                    else
                    {
                        PsImageLang.IDImage = PsImage.IDImage;
                        PsImageLang.IDLang  = Core.Global.Lang;
                        PsImageLangRepository.Add(PsImageLang);
                    }
                    // <JG> 26/12/2012 ajout insertion autres langues actives si non renseignées
                    try
                    {
                        Model.Prestashop.PsLangRepository PsLangRepository = new Model.Prestashop.PsLangRepository();
                        foreach (Model.Prestashop.PsLang PsLang in PsLangRepository.ListActive(1, Global.CurrentShop.IDShop))
                        {
                            if (!PsImageLangRepository.ExistImageLang(PsImage.IDImage, PsLang.IDLang))
                            {
                                PsImageLang = new Model.Prestashop.PsImageLang()
                                {
                                    IDImage = PsImage.IDImage,
                                    IDLang  = PsLang.IDLang,
                                    Legend  = ArticleImage.ImaArt_Name
                                };
                                PsImageLangRepository.Add(PsImageLang);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Core.Error.SendMailError(ex.ToString());
                    }
                    #endregion

                    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

                            //System.Net.FtpWebRequest ftp_folder = null;

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

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

                                    request.Credentials = new NetworkCredential(User, Password);
                                    request.UsePassive  = true;
                                    request.UseBinary   = true;
                                    request.KeepAlive   = false;
                                    request.EnableSsl   = Core.Global.GetConfig().ConfigFTPSSL;

                                    request.Method = WebRequestMethods.Ftp.MakeDirectory;

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

                                //try
                                //{
                                //    ftp_folder = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(FTP + ftpPath);

                                //    ftp_folder.Credentials = new System.Net.NetworkCredential(User, Password);
                                //    ftp_folder.UseBinary = true;
                                //    ftp_folder.UsePassive = true;
                                //    ftp_folder.KeepAlive = false;
                                //    ftp_folder.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory;

                                //    System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)ftp_folder.GetResponse();
                                //    System.IO.Stream ftpStream = response.GetResponseStream();

                                //    ftpStream.Close();
                                //    response.Close();
                                //}
                                //catch(Exception ex)
                                //{
                                //    System.Windows.MessageBox.Show(ex.ToString());
                                //}
                            }
                            break;
                            #endregion
                        }

                        #region Upload des images
                        String 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 PathImg = ArticleImage.FileName(PsImageType.Name);
                            if (System.IO.File.Exists(PathImg))
                            {
                                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(PathImg);
                                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.Pre_Id = Convert.ToInt32(PsImage.IDImage);
                        ArticleImageRepository.Save();
                    }
                    catch (Exception ex)
                    {
                        Core.Error.SendMailError("[UPLOAD FTP IMAGE ARTICLE]<br />" + ex.ToString());
                        PsImageLangRepository.DeleteAll(PsImageLangRepository.ListImage(PsImage.IDImage));
                        PsImageRepository.Delete(PsImage);
                    }
                }
                // option car si PAS GADA écrase infos PS
                else if (Core.Global.GetConfig().ConfigImageSynchroPositionLegende)
                {
                    PsImage = new Model.Prestashop.PsImage();
                    if (PsImageRepository.ExistImage((uint)ArticleImage.Pre_Id))
                    {
                        PsImage = PsImageRepository.ReadImage((uint)ArticleImage.Pre_Id);
                        if (PsImage.Position != (UInt16)ArticleImage.ImaArt_Position ||
                            PsImage.Cover !=
                                                                #if (PRESTASHOP_VERSION_172 || PRESTASHOP_VERSION_161)
                            ((ArticleImage.ImaArt_Default) ? Convert.ToByte(ArticleImage.ImaArt_Default) : (byte?)null))
                                                                #else
                            Convert.ToByte(ArticleImage.ImaArt_Default))
                                                                #endif
                        {
                            PsImage.Position = (ushort)ExecPosition((uint)Article.Pre_Id, (uint)ArticleImage.ImaArt_Position, PsImageRepository, PsImage);
                            PsImage.Cover    = ExecCover((uint)Article.Pre_Id, ArticleImage.ImaArt_Default, PsImageRepository, PsImage);
                            PsImageRepository.Save();

                            Model.Prestashop.PsImageShopRepository PsImageShopRepository = new Model.Prestashop.PsImageShopRepository();
                            Model.Prestashop.PsImageShop           PsImageShop           = PsImageShopRepository.ReadImage(PsImage.IDImage);
                            if (PsImageShop != null && PsImageShop.Cover !=
                                                                #if (PRESTASHOP_VERSION_160)
                                (sbyte)PsImage.Cover
                                                                #else
                                PsImage.Cover
                                                                #endif
                                )
                            {
                                                                #if (PRESTASHOP_VERSION_160)
                                PsImageShop.Cover = (sbyte)PsImage.Cover;
                                                                #else
                                PsImageShop.Cover = PsImage.Cover;
                                                                #endif
                                PsImageShopRepository.Save();
                            }
                        }

                        #region lang
                        PsImageLang = new Model.Prestashop.PsImageLang();
                        isImageLang = false;
                        if (PsImageLangRepository.ExistImageLang(PsImage.IDImage, Core.Global.Lang))
                        {
                            PsImageLang = PsImageLangRepository.ReadImageLang(PsImage.IDImage, Core.Global.Lang);
                            isImageLang = true;
                        }
                        PsImageLang.Legend = ArticleImage.ImaArt_Name;
                        if (isImageLang == true)
                        {
                            PsImageLangRepository.Save();
                        }
                        else
                        {
                            PsImageLang.IDImage = PsImage.IDImage;
                            PsImageLang.IDLang  = Core.Global.Lang;
                            PsImageLangRepository.Add(PsImageLang);
                        }
                        // <JG> 26/12/2012 ajout insertion autres langues actives si non renseignées
                        try
                        {
                            Model.Prestashop.PsLangRepository PsLangRepository = new Model.Prestashop.PsLangRepository();
                            foreach (Model.Prestashop.PsLang PsLang in PsLangRepository.ListActive(1, Global.CurrentShop.IDShop))
                            {
                                if (!PsImageLangRepository.ExistImageLang(PsImage.IDImage, PsLang.IDLang))
                                {
                                    PsImageLang = new Model.Prestashop.PsImageLang()
                                    {
                                        IDImage = PsImage.IDImage,
                                        IDLang  = PsLang.IDLang,
                                        Legend  = ArticleImage.ImaArt_Name
                                    };
                                    PsImageLangRepository.Add(PsImageLang);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Core.Error.SendMailError(ex.ToString());
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError("[SYNCHRO IMAGE ARTICLE]<br />" + ex.ToString());

                if (PsImage != null)
                {
                    PsImageLangRepository.DeleteAll(PsImageLangRepository.ListImage(PsImage.IDImage));
                    PsImageRepository.Delete(PsImage);
                }
            }
        }
예제 #28
0
        private void ExecCompositionArticle(Model.Local.Article Article, Model.Prestashop.PsProduct Product)
        {
            Model.Sage.F_ARTICLERepository           F_ARTICLERepository          = new Model.Sage.F_ARTICLERepository();
            Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
            List <Model.Local.CompositionArticle>    ListCompositionArticle       = CompositionArticleRepository.ListArticle(Article.Art_Id);

            foreach (var item in ListCompositionArticle)
            {
                try
                {
                    Model.Sage.F_ARTICLE_Composition F_ARTICLE_Composition = F_ARTICLERepository.ReadComposition(item.ComArt_F_ARTICLE_SagId, item.ComArt_F_ARTENUMREF_SagId, item.ComArt_F_CONDITION_SagId);
                    if (F_ARTICLE_Composition != null)
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(item.ComArt_F_ARTICLE_SagId);
                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository  = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttributeComposition = new Model.Prestashop.PsProductAttribute();
                        Boolean isProductAttribute = false;
                        if (item.Pre_Id != null && PsProductAttributeRepository.ExistProductAttribute((uint)item.Pre_Id))
                        {
                            PsProductAttributeComposition = PsProductAttributeRepository.ReadProductAttribute((uint)item.Pre_Id);
                            if (PsProductAttributeComposition != null)
                            {
                                isProductAttribute = true;
                            }
                        }

                        if (isProductAttribute == true)
                        {
                            int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                            Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);

                            Model.Prestashop.PsProduct temp_product = new Model.Prestashop.PsProduct();
                            temp_product.taxe_famillesage = Product.taxe_famillesage;

                            // temp_product sert pour conserver l'information "ecoraxeht_sage" pour la fonction SpecificPrice
                            Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, temp_product, TaxeTVA, CatComptaArticle);
                            PsProductAttributeComposition.EcOtAx = temp_product.EcOtAx;

                            if (F_ARTICLE_Composition.F_CONDITION_SagId == null && F_ARTICLE_Composition.F_ARTENUMREF_SagId == null)
                            {
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, PsProductAttributeComposition);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, PsProductAttributeComposition);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, PsProductAttributeComposition, TaxeTVA);
                                }

                                //List<string> log;
                                //this.ExecSpecificPrice(F_ARTICLE, Product, Article.Art_Id, TaxeTVA, TaxeEco, out log);
                                //if (log != null && log.Count > 0)
                                //    log_chrono.AddRange(log);
                            }
                            else if (F_ARTICLE_Composition.F_ARTENUMREF_SagId != null)
                            {
                                Model.Prestashop.PsProduct temp_product_f_artenumref = new Model.Prestashop.PsProduct();
                                // lecture des valeurs pour F_ARTICLE
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, temp_product_f_artenumref);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, temp_product_f_artenumref);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, temp_product_f_artenumref, TaxeTVA);
                                }

                                // transformation en fonction de f_artenumref
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightAttribute(temp_product_f_artenumref, PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1);
                                    PsProductAttributeComposition.Weight += temp_product_f_artenumref.Weight;
                                }
                                SynchronisationArticle.ReadQuantityAttribute(PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2);
                                //SynchronisationArticle.ReadRefEANAttribute(PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceAttribute(temp_product_f_artenumref, PsProductAttributeComposition, F_ARTICLE, item.EnumereGamme1, item.EnumereGamme2, TaxeTVA);
                                }
                                PsProductAttributeComposition.Price += temp_product_f_artenumref.Price;
                            }
                            else if (F_ARTICLE_Composition.F_CONDITION_SagId != null)
                            {
                                Model.Prestashop.PsProduct temp_product_f_condition = new Model.Prestashop.PsProduct();
                                // lecture des valeurs pour F_ARTICLE
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeight(F_ARTICLE, temp_product_f_condition);
                                }

                                SynchronisationArticle.ReadQuantity(F_ARTICLE, temp_product_f_condition);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPrice(F_ARTICLE, temp_product_f_condition, TaxeTVA);
                                }

                                // transformation en fonction de F_CONDITION
                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightConditioning(temp_product_f_condition, PsProductAttributeComposition, item.EnumereF_CONDITION);
                                    PsProductAttributeComposition.Weight += temp_product_f_condition.Weight;
                                }
                                SynchronisationArticle.ReadQuantityConditioning(PsProductAttributeComposition, F_ARTICLE, item.EnumereF_CONDITION);

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceConditioning(temp_product_f_condition, PsProductAttributeComposition, F_ARTICLE, item.EnumereF_CONDITION, TaxeTVA);
                                }
                                PsProductAttributeComposition.Price += temp_product_f_condition.Price;
                            }

                            //PsProductAttributeComposition.DefaultOn = (item.ComArt_Default) ? (byte)1 : (byte)0;
                            PsProductAttributeRepository.Save();
                            SynchronisationArticle.ExecShopProductAttribute(PsProductAttributeComposition);

                            SynchronisationArticle.WriteStockAvailableComposition(Product, PsProductAttributeComposition);

                            // <JG> 03/06/2016
                            if (Article.Art_SyncPrice)
                            {
                                // prix spécifiques
                                temp_product.Price     = PsProductAttributeComposition.Price;
                                temp_product.IDProduct = Product.IDProduct;
                                List <string> log;
                                SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, temp_product, Article, item, TaxeTVA, TaxeEco, out log);
                                if (log != null && log.Count > 0)
                                {
                                    SynchronisationArticle.log_chrono.AddRange(log);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); }
            }
        }
        private void ExecAttributeImage(Model.Local.Article Article)
        {
            Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
            List <Model.Local.ArticleImage>    ListArticleImage       = ArticleImageRepository.ListArticle(Article.Art_Id);

            Model.Local.AttributeArticleImageRepository        AttributeArticleImageRepository   = new Model.Local.AttributeArticleImageRepository();
            Model.Local.CompositionArticleImageRepository      CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository();
            Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository();
            Model.Prestashop.PsImageRepository PsImageRepository  = new Model.Prestashop.PsImageRepository();
            Model.Local.AttributeArticle       AttributeArticle   = new Model.Local.AttributeArticle();
            Model.Local.CompositionArticle     CompositionArticle = new Model.Local.CompositionArticle();

            foreach (Model.Local.ArticleImage ArticleImage in ListArticleImage)
            {
                if (ArticleImage.Pre_Id != null && PsImageRepository.ExistImage((uint)ArticleImage.Pre_Id.Value))
                {
                    List <Model.Local.AttributeArticleImage>   ListAttributeArticleImage   = AttributeArticleImageRepository.ListImageArticle(ArticleImage.ImaArt_Id);
                    List <Model.Local.CompositionArticleImage> ListCompositionArticleImage = CompositionArticleImageRepository.ListImageArticle(ArticleImage.ImaArt_Id);

                    #region suppression lien image déclinaison PrestaShop
                    Model.Local.AttributeArticleRepository   AttributeArticleRepository   = new Model.Local.AttributeArticleRepository();
                    Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                    // liste des liens images déclinaisons Prestashop
                    foreach (Model.Prestashop.PsProductAttributeImage PsProductAttributeImage in PsProductAttributeImageRepository.ListImage((uint)ArticleImage.Pre_Id))
                    {
                        // si la déclinaison existe dans PrestaConnect
                        if (AttributeArticleRepository.ExistPrestashop((int)PsProductAttributeImage.IDProductAttribute))
                        {
                            AttributeArticle = AttributeArticleRepository.ReadPrestashop((int)PsProductAttributeImage.IDProductAttribute);
                            // si dans prestaconnect la déclinaison n'est pas liée à l'image
                            if (!AttributeArticleImageRepository.ExistAttributeArticleImage(AttributeArticle.AttArt_Id, ArticleImage.ImaArt_Id))
                            {
                                // suppression du lien dans PrestaShop
                                PsProductAttributeImageRepository.Delete(PsProductAttributeImage);
                            }
                        }
                        else if (CompositionArticleRepository.ExistPrestaShop((int)PsProductAttributeImage.IDProductAttribute))
                        {
                            CompositionArticle = CompositionArticleRepository.ReadPrestaShop((int)PsProductAttributeImage.IDProductAttribute);
                            // si dans prestaconnect la déclinaison n'est pas liée à l'image
                            if (!CompositionArticleImageRepository.ExistCompositionArticleImage(CompositionArticle.ComArt_Id, ArticleImage.ImaArt_Id))
                            {
                                // suppression du lien dans PrestaShop
                                PsProductAttributeImageRepository.Delete(PsProductAttributeImage);
                            }
                        }
                    }
                    #endregion

                    // affectation image déclinaison
                    foreach (Model.Local.AttributeArticleImage AttributeArticleImage in ListAttributeArticleImage)
                    {
                        if (AttributeArticleImage.AttributeArticle.Pre_Id != null &&
                            AttributeArticleImage.AttributeArticle.Pre_Id != 0)
                        {
                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)AttributeArticleImage.AttributeArticle.Pre_Id, (UInt32)AttributeArticleImage.ArticleImage.Pre_Id) == false)
                            {
                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                {
                                    IDImage            = (UInt32)AttributeArticleImage.ArticleImage.Pre_Id,
                                    IDProductAttribute = (UInt32)AttributeArticleImage.AttributeArticle.Pre_Id,
                                });
                            }
                        }
                    }
                    foreach (Model.Local.CompositionArticleImage CompositionArticleImage in ListCompositionArticleImage)
                    {
                        if (CompositionArticleImage.CompositionArticle.Pre_Id != null &&
                            CompositionArticleImage.CompositionArticle.Pre_Id != 0)
                        {
                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)CompositionArticleImage.CompositionArticle.Pre_Id, (UInt32)CompositionArticleImage.ArticleImage.Pre_Id) == false)
                            {
                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                {
                                    IDImage            = (UInt32)CompositionArticleImage.ArticleImage.Pre_Id,
                                    IDProductAttribute = (UInt32)CompositionArticleImage.CompositionArticle.Pre_Id,
                                });
                            }
                        }
                    }
                }
            }
        }
예제 #30
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository PsProductRepository,
                                        out List <string> log_chrono)
        {
            log_chrono = new List <string>();
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Price    = 0;
                        Product.Quantity = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        ExecCompositionArticle(Article, Product);
                    }
                }
                else
                {
                    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);
                        SynchronisationArticle.ReadQuantity(F_ARTICLE, Product);

                        #region Stock pack limité par composés
                        if (Article.Art_Pack == true || F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Composant ||
                            F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Compose)                                        // pour que les articles en nomenclature soient pris en compte
                        {
                            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;
                            Int32 QuantityPack = 0;
                            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 (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
                                    {
                                        Int32 CurrentQuantity = SynchronisationArticle.ReadQuantityPack(F_ARTICLENOMENCLAT, F_NOMENCLAT.NO_Qte.Value);
                                        if (Core.Global.GetConfig().ArticleStockNegatifZero&& CurrentQuantity < 0)
                                        {
                                            CurrentQuantity = 0;
                                        }
                                        if (CurrentQuantity < QuantityPack)
                                        {
                                            QuantityPack = CurrentQuantity;
                                        }
                                        else if (QuantityPack == 0)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Product.Quantity = QuantityPack;
                        }
                        #endregion

                        int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                        Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                        Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);
                        }

                        if (Core.Global.GetConfig().MajPoidsSynchroStock)
                        {
                            SynchronisationArticle.ReadWeight(F_ARTICLE, Product);
                        }

                        if (Core.Global.GetConfig().ArticleDateDispoInfoLibreActif)
                        {
                            SynchronisationArticle.ReadDateDispo(Product, F_ARTICLE);
                        }

                        PsProductRepository.Save();
                        PsProductRepository.WriteDate(Product.IDProduct);

                        // <JG> 05/11/2013 déplacement pour application taxes et pdt spécifiques sur nouvelles déclinaisons
                        this.ExecAttribute(Article, Product, TaxeTVA, PsProductRepository);
                        this.ExecConditioning(Article, Product, TaxeTVA, PsProductRepository);

                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            List <string> log;
                            SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article, null, TaxeTVA, TaxeEco, out log);
                            if (log != null && log.Count > 0)
                            {
                                log_chrono.AddRange(log);
                            }
                        }

                        // <JG> 17/12/2012
                        SynchronisationArticle.ExecShopProduct(Product);

                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }