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 RecoveryDataProductAttribute(Model.Prestashop.PsProduct Product) { Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository(); Model.Prestashop.PsProductAttributeShopRepository PsProductAttributeShopRepository = new Model.Prestashop.PsProductAttributeShopRepository(); Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository(); Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository(); Model.Local.ConditioningArticleRepository ConditioningArticleRepository = new Model.Local.ConditioningArticleRepository(); Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository(); Model.Local.AttributeArticleImageRepository AttributeArticleImageRepository = new Model.Local.AttributeArticleImageRepository(); Model.Local.CompositionArticleImageRepository CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository(); Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository(); Model.Local.AttributeArticle AttributeArticle; Model.Local.ConditioningArticle ConditioningArticle; Model.Local.CompositionArticle CompositionArticle; Model.Local.ArticleImage ArticleImage; List <Model.Prestashop.PsProductAttribute> ListPsProductAttribute = PsProductAttributeRepository.List(Product.IDProduct); //parcours déclinaisons PrestaShop foreach (Model.Prestashop.PsProductAttribute PsProductAttribute in ListPsProductAttribute) { // test si déclinaison en gamme dans PrestaConnect if (AttributeArticleRepository.ExistPrestashop((int)PsProductAttribute.IDProductAttribute)) { AttributeArticle = AttributeArticleRepository.ReadPrestashop((int)PsProductAttribute.IDProductAttribute); Model.Prestashop.PsProductAttributeShop PsProductAttributeShop = (PsProductAttributeShopRepository.ExistPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop)) ? PsProductAttributeShopRepository.ReadPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop) : null; bool defaut = (PsProductAttributeShop != null) ? PsProductAttributeShop.DefaultOn == 1 : PsProductAttribute.DefaultOn == 1; if (AttributeArticle.AttArt_Default != defaut) { AttributeArticle.AttArt_Default = defaut; AttributeArticleRepository.Save(); if (defaut) { List <Model.Local.AttributeArticle> ListAttributeArticle = AttributeArticleRepository.ListArticle(AttributeArticle.Art_Id); if (ListAttributeArticle.Count(i => i.AttArt_Default == true && i.AttArt_Id != AttributeArticle.AttArt_Id) > 0) { foreach (Model.Local.AttributeArticle AttributeArticleDefault in ListAttributeArticle.Where(i => i.AttArt_Default == true && i.AttArt_Id != AttributeArticle.Art_Id)) { AttributeArticleDefault.AttArt_Default = false; AttributeArticleRepository.Save(); } } } } // attribution images gammes if (PsProductAttributeImageRepository.ExistProductAttribute(PsProductAttribute.IDProductAttribute)) { List <Model.Prestashop.PsProductAttributeImage> ListPsProductAttributeImage = PsProductAttributeImageRepository.ListProductAttribute(PsProductAttribute.IDProductAttribute); // étape 1 attachement dans PrestaConnect des images affectées a la déclinaison PrestaShop foreach (Model.Prestashop.PsProductAttributeImage PsProductAttributeImage in ListPsProductAttributeImage) { // si l'image existe dans PrestaConnect if (ArticleImageRepository.ExistPre_Id((int)PsProductAttributeImage.IDImage)) { ArticleImage = ArticleImageRepository.ReadPrestaShop((int)PsProductAttributeImage.IDImage); if (!AttributeArticleImageRepository.ExistAttributeArticleImage(AttributeArticle.AttArt_Id, ArticleImage.ImaArt_Id)) { AttributeArticleImageRepository.Add(new Model.Local.AttributeArticleImage() { AttArt_Id = AttributeArticle.AttArt_Id, ImaArt_Id = ArticleImage.ImaArt_Id, }); } } } // étape 2 détachement List <uint> list_prestashop = ListPsProductAttributeImage.Select(pai => pai.IDImage).ToList(); foreach (Model.Local.AttributeArticleImage AttributeArticleImage in AttributeArticleImageRepository.ListAttributeArticle(AttributeArticle.AttArt_Id)) { if (AttributeArticleImage.ArticleImage.Pre_Id != null && !list_prestashop.Contains((uint)AttributeArticleImage.ArticleImage.Pre_Id.Value)) { AttributeArticleImageRepository.Delete(AttributeArticleImage); } } } else if (AttributeArticleImageRepository.ExistAttributeArticle(AttributeArticle.AttArt_Id)) { // absence de lien gamme déclinaison dans Prestashop donc suppression des liens dans PrestaConnect AttributeArticleImageRepository.DeleteAll(AttributeArticleImageRepository.ListAttributeArticle(AttributeArticle.AttArt_Id)); } } // test si déclinaison en conditionnement dans PrestaConnect else if (ConditioningArticleRepository.ExistPrestashop((int)PsProductAttribute.IDProductAttribute)) { ConditioningArticle = ConditioningArticleRepository.ReadPrestashop((int)PsProductAttribute.IDProductAttribute); Model.Prestashop.PsProductAttributeShop PsProductAttributeShop = (PsProductAttributeShopRepository.ExistPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop)) ? PsProductAttributeShopRepository.ReadPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop) : null; bool defaut = (PsProductAttributeShop != null) ? PsProductAttributeShop.DefaultOn == 1 : PsProductAttribute.DefaultOn == 1; if (ConditioningArticle.ConArt_Default != defaut) { ConditioningArticle.ConArt_Default = defaut; ConditioningArticleRepository.Save(); if (defaut) { List <Model.Local.ConditioningArticle> ListConditioningArticle = ConditioningArticleRepository.ListArticle(ConditioningArticle.Art_Id); if (ListConditioningArticle.Count(i => i.ConArt_Default == true && i.ConArt_Id != ConditioningArticle.ConArt_Id) > 0) { foreach (Model.Local.ConditioningArticle ConditioningArticleDefault in ListConditioningArticle.Where(i => i.ConArt_Default == true && i.ConArt_Id != ConditioningArticle.Art_Id)) { ConditioningArticleDefault.ConArt_Default = false; ConditioningArticleRepository.Save(); } } } } } // test si déclinaison composition dans PrestaConnect else if (CompositionArticleRepository.ExistPrestaShop((int)PsProductAttribute.IDProductAttribute)) { CompositionArticle = CompositionArticleRepository.ReadPrestaShop((int)PsProductAttribute.IDProductAttribute); Model.Prestashop.PsProductAttributeShop PsProductAttributeShop = (PsProductAttributeShopRepository.ExistPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop)) ? PsProductAttributeShopRepository.ReadPsProductAttributeShop(PsProductAttribute.IDProductAttribute, Core.Global.CurrentShop.IDShop) : null; bool defaut = (PsProductAttributeShop != null) ? PsProductAttributeShop.DefaultOn == 1 : PsProductAttribute.DefaultOn == 1; if (CompositionArticle.ComArt_Default != defaut) { CompositionArticle.ComArt_Default = defaut; CompositionArticleRepository.Save(); if (defaut) { List <Model.Local.CompositionArticle> ListCompositionArticle = CompositionArticleRepository.ListArticle(CompositionArticle.ComArt_ArtId); if (ListCompositionArticle.Count(i => i.ComArt_Default == true && i.ComArt_Id != CompositionArticle.ComArt_Id) > 0) { foreach (Model.Local.CompositionArticle CompositionArticleDefault in ListCompositionArticle.Where(i => i.ComArt_Default == true && i.ComArt_Id != CompositionArticle.ComArt_ArtId)) { CompositionArticleDefault.ComArt_Default = false; ConditioningArticleRepository.Save(); } } } } // attribution images gammes if (PsProductAttributeImageRepository.ExistProductAttribute(PsProductAttribute.IDProductAttribute)) { List <Model.Prestashop.PsProductAttributeImage> ListPsProductAttributeImage = PsProductAttributeImageRepository.ListProductAttribute(PsProductAttribute.IDProductAttribute); // étape 1 attachement dans PrestaConnect des images affectées a la déclinaison PrestaShop foreach (Model.Prestashop.PsProductAttributeImage PsProductAttributeImage in ListPsProductAttributeImage) { // si l'image existe dans PrestaConnect if (ArticleImageRepository.ExistPre_Id((int)PsProductAttributeImage.IDImage)) { ArticleImage = ArticleImageRepository.ReadPrestaShop((int)PsProductAttributeImage.IDImage); if (!CompositionArticleImageRepository.ExistCompositionArticleImage(CompositionArticle.ComArt_Id, ArticleImage.ImaArt_Id)) { CompositionArticleImageRepository.Add(new Model.Local.CompositionArticleImage() { ComArt_Id = CompositionArticle.ComArt_Id, ImaArt_Id = ArticleImage.ImaArt_Id, }); } } } // étape 2 détachement List <uint> list_prestashop = ListPsProductAttributeImage.Select(pai => pai.IDImage).ToList(); foreach (Model.Local.CompositionArticleImage CompositionArticleImage in CompositionArticleImageRepository.ListCompositionArticle(CompositionArticle.ComArt_Id)) { if (CompositionArticleImage.ArticleImage.Pre_Id != null && !list_prestashop.Contains((uint)CompositionArticleImage.ArticleImage.Pre_Id.Value)) { CompositionArticleImageRepository.Delete(CompositionArticleImage); } } } else if (CompositionArticleImageRepository.ExistCompositionArticle(CompositionArticle.ComArt_Id)) { // absence de lien gamme déclinaison dans Prestashop donc suppression des liens dans PrestaConnect CompositionArticleImageRepository.DeleteAll(CompositionArticleImageRepository.ListCompositionArticle(CompositionArticle.ComArt_Id)); } } } }