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()); } }
public void LoadCatalogs() { IsBusy = true; LoadingStep = "Chargement des catalogues ..."; Application.Current.Dispatcher.BeginInvoke(new Action(delegate { Mouse.OverrideCursor = Cursors.Wait; }), null); CatalogRepository = new Model.Local.CatalogRepository(); Catalogs = new ObservableCollection <Model.Local.Catalog>(CatalogRepository.ListParent(0)); Core.Temp.ListF_CATALOGUE = new List <Model.Sage.F_CATALOGUE>(); Core.Temp.ListF_CATALOGUE.Add(new Model.Sage.F_CATALOGUE() { CL_Intitule = "Aucun", }); Core.Temp.ListF_CATALOGUE.AddRange(new Model.Sage.F_CATALOGUERepository().List()); OnPropertyChanged("ListF_CATALOGUE"); SelectedCatalog = null; SyncAll = true; LoadingStep = string.Empty; IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(delegate { Mouse.OverrideCursor = null; }), null); }
public void Exec(Int32 F_CATALOGUESend, out List <String> log_out) { log = new List <string>(); try { Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository(); if (CatalogRepository.ExistSag_Id(F_CATALOGUESend) == false) { Model.Sage.F_CATALOGUERepository F_CATALOGUERepository = new Model.Sage.F_CATALOGUERepository(); Model.Sage.F_CATALOGUE F_CATALOGUE = F_CATALOGUERepository.ReadCatalogue(F_CATALOGUESend); string dft = Core.Global.RemovePurge(F_CATALOGUE.CL_Intitule, 128); Model.Local.Catalog Catalog = new Model.Local.Catalog() { Cat_Name = dft, Cat_Description = F_CATALOGUE.CL_Intitule, Cat_MetaTitle = dft, Cat_MetaDescription = dft, Cat_MetaKeyword = Core.Global.RemovePurgeMeta(dft, 255), Cat_LinkRewrite = Core.Global.ReadLinkRewrite(dft), Cat_Active = true, Cat_Date = DateTime.Now, Cat_Sync = true, Cat_Level = 2, Sag_Id = F_CATALOGUE.cbMarq }; //if (F_CATALOGUERepository.ExistParent(F_CATALOGUE.CL_NoParent.Value)) //{ // Model.Sage.F_CATALOGUE F_CATALOGUEParent = F_CATALOGUERepository.ReadParent(F_CATALOGUE.CL_NoParent.Value); // Catalog.Cat_Parent = F_CATALOGUEParent.cbMarq; //} //<YH> 19/11/2012 : L'usage du Cat_Parent a été modifié //<JG> 29/01/2013 Correction récupération du Cat_Id par rapport au cbMarq du parent dans la base locale et non au CL_No // <JG> 07/10/2016 correction calcul niveau catalogue si import des enfants sans les parents if (F_CATALOGUERepository.ExistParent(F_CATALOGUE.CL_NoParent.Value) && CatalogRepository.ExistSag_Id(F_CATALOGUE.F_CATALOGUE1.cbMarq)) { Model.Local.Catalog parent = CatalogRepository.ReadSag_Id(F_CATALOGUE.F_CATALOGUE1.cbMarq); Catalog.Cat_Parent = parent.Cat_Id; Catalog.Cat_Level = parent.Cat_Level + 1; } CatalogRepository.Add(Catalog); log.Add("IC10- Import du catalogue Sage [ " + F_CATALOGUE.ComboText + " ]"); } } catch (Exception ex) { Core.Error.SendMailError("IC01- Une erreur est survenue : " + ex.ToString()); } finally { log_out = log; } }
public CompositionContext() : base() { ListF_TAXE = new ObservableCollection <Model.Sage.F_TAXE>(new Model.Sage.F_TAXERepository().ListTTauxSens(ABSTRACTION_SAGE.F_TAXE.Obj._Enum_TA_TTaux.Taux, (short)ABSTRACTION_SAGE.F_TAXE.Obj._Enum_TA_Sens.Collectee)); ListF_FAMILLE = new ObservableCollection <Model.Sage.F_FAMILLE>(new Model.Sage.F_FAMILLERepository().List()); ListP_GAMME = new ObservableCollection <Model.Sage.P_GAMME>(new Model.Sage.P_GAMMERepository().ListIntituleNotNull()); ListP_CONDITIONNEMENT = new ObservableCollection <Model.Sage.P_CONDITIONNEMENT>(new Model.Sage.P_CONDITIONNEMENTRepository().ListIntituleNotNull()); ListLocalCatalog = new Model.Local.CatalogRepository().List(); }
//public void Exec(Int32 CategorySend) //{ // try // { // if (CategorySend != 1) // { // CatalogRepository CatalogRepository = new CatalogRepository(); // if (CatalogRepository.ExistPre_Id(CategorySend) == false) // { // PsCategoryLangRepository PsCategoryLangRepository = new PsCategoryLangRepository(); // if (PsCategoryLangRepository.ExistCategoryLang(CategorySend, Core.Global.Lang)) // { // PsCategoryRepository PsCategoryRepository = new PsCategoryRepository(); // PsCategory PsCategory = PsCategoryRepository.ReadId(CategorySend); // PsCategoryLang PsCategoryLang = PsCategoryLangRepository.ReadCategoryLang(CategorySend, Core.Global.Lang); // F_CATALOGUERepository F_CATALOGUERepository = new F_CATALOGUERepository(); // if (F_CATALOGUERepository.ExistIntituleNiveau(PsCategoryLang.Name, Convert.ToInt16(PsCategory.LevelDepth - 1))) // { // F_CATALOGUE F_CATALOGUE = F_CATALOGUERepository.ReadIntituleNiveau(PsCategoryLang.Name, Convert.ToInt16(PsCategory.LevelDepth - 1)); // Catalog Catalog = new Catalog() // { // Cat_Name = PsCategoryLang.Name, // Cat_Description = PsCategoryLang.Description, // Cat_Level = PsCategory.LevelDepth, // Cat_MetaTitle = PsCategoryLang.MetaTitle, // Cat_MetaKeyword = PsCategoryLang.MetaKeywords, // Cat_Active = Convert.ToBoolean(PsCategory.Active), // Cat_MetaDescription = PsCategoryLang.MetaDescription, // Cat_LinkRewrite = PsCategoryLang.LinkRewrite, // Cat_Sync = true, // Cat_Date = PsCategory.DateUpd, // Sag_Id = F_CATALOGUE.cbMarq, // Pre_Id = Convert.ToInt32(PsCategory.IDCategory) // }; // if (PsCategory.IDParent != 0 && PsCategory.IDParent != 1) // { // if (PsCategoryRepository.ExistId(Convert.ToInt32(PsCategory.IDParent))) // { // PsCategory PsCategoryParent = PsCategoryRepository.ReadId(Convert.ToInt32(PsCategory.IDParent)); // if (CatalogRepository.ExistPre_Id(Convert.ToInt32(PsCategoryParent.IDCategory))) // { // Catalog CatalogParent = CatalogRepository.ReadPre_Id(Convert.ToInt32(PsCategoryParent.IDCategory)); // Catalog.Cat_Parent = CatalogParent.Cat_Id; // } // } // } // CatalogRepository.Add(Catalog); // } // } // } // } // } // catch (Exception ex) // { // Core.Error.SendMailError(ex.ToString()); // } //} //public void Exec(Int32 CategorySend) //{ // try // { // if (CategorySend != 1) // { // CatalogRepository catalogs = new CatalogRepository(); // //Vérifie si le catalogue PS est référence dans PC // if (!catalogs.ExistPre_Id(CategorySend)) // { // PsCategoryLangRepository langs = new PsCategoryLangRepository(); // //Vérifie que le catalogue existe bien dans la langue définit dans PC // if (langs.ExistCategoryLang(CategorySend, Global.Lang,Global.CurrentShop.IDShop)) // { // PsCategoryRepository categories = new PsCategoryRepository(); // //Récupération du catalogue dans PS // PsCategory category = categories.ReadId(CategorySend); // PsCategoryLang lang = langs.ReadCategoryLang(CategorySend, Global.Lang, Global.CurrentShop.IDShop); // //Récupération de tous les catalogues S suceptible de correspondre au catalogue PS // List<F_CATALOGUE> correspondances = new List<F_CATALOGUE>( // new F_CATALOGUERepository().ReadIntituleNiveau(lang.Name, Convert.ToInt16(category.LevelDepth - 1))); // if (correspondances.Count > 0) // { // PsCategory parentPrestashop = null; // //Récupération du parent dans PS // //Le catalogue 1 correspond à au noeud racine "Accueil" dans PS (il n'est ni utilisable, ni supprimable, ni exportable) // if (category.IDParent != 0 && category.IDParent != 1) // parentPrestashop = categories.ReadId(Convert.ToInt32(category.IDParent)); // Catalog nouveauCatalogue = null; // if (correspondances.Count == 1) // nouveauCatalogue = GetCatalogue(category, lang, correspondances[0].cbMarq); // else if (correspondances.Count > 1) // foreach (var correspondanceSage in correspondances) // if (correspondanceSage.CL_NoParent.HasValue) // { // //Récupération de la référence au parent de la correspondance en cours dans PC // Catalog parentCorrespondance = catalogs.ReadSag_Id(correspondanceSage.CL_NoParent.Value); // //Comparaison de l'ID de la réf PS du parent de la correspondance avec l'id du parent PS. // if (parentCorrespondance != null) // if (parentCorrespondance.Pre_Id == parentPrestashop.IDCategory) // { // nouveauCatalogue = GetCatalogue(category, lang, correspondanceSage.cbMarq); // break; // } // } // if (nouveauCatalogue != null && parentPrestashop != null) // { // //Si l'identifiant PS du parent existe dans PC // if (catalogs.ExistPre_Id(Convert.ToInt32(parentPrestashop.IDCategory))) // nouveauCatalogue.Cat_Parent = catalogs.ReadPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)).Sag_Id; // } // catalogs.Add(nouveauCatalogue); // } // } // } // } // } // catch (Exception ex) // { // Core.Error.SendMailError(ex.ToString()); // } //} public void Exec(Int32 CategorySend) { try { if (CategorySend != Core.Global.CurrentShop.IDCategory) { Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository(); //Vérifie si le catalogue PS est référence dans PC if (!CatalogRepository.ExistPre_Id(CategorySend)) { Model.Prestashop.PsCategoryLangRepository PsCategoryLangRepository = new Model.Prestashop.PsCategoryLangRepository(); //Vérifie que le catalogue existe bien dans la langue définit dans PC if (PsCategoryLangRepository.ExistCategoryLang(CategorySend, Global.Lang, Core.Global.CurrentShop.IDShop)) { Model.Prestashop.PsCategoryRepository PsCategoryRepository = new Model.Prestashop.PsCategoryRepository(); //Récupération du catalogue dans PS Model.Prestashop.PsCategory PsCategory = PsCategoryRepository.ReadId((UInt32)CategorySend); Model.Prestashop.PsCategoryLang PsCategoryLang = PsCategoryLangRepository.ReadCategoryLang(CategorySend, Global.Lang, Core.Global.CurrentShop.IDShop); Model.Prestashop.PsCategory parentPrestashop = null; //Récupération du parent dans PS //Le catalogue 1 correspond à au noeud racine "Accueil" dans PS (il n'est ni utilisable, ni supprimable, ni exportable) if (PsCategory.IDParent != 0 && PsCategory.IDParent != 1 && PsCategory.IDParent != Core.Global.CurrentShop.IDShop) { parentPrestashop = PsCategoryRepository.ReadId(PsCategory.IDParent); } Model.Local.Catalog nouveauCatalogue = GetCatalogue(PsCategory, PsCategoryLang, 0); if (nouveauCatalogue != null && parentPrestashop != null) { //Si l'identifiant PS du parent existe dans PC if (CatalogRepository.ExistPre_Id(Convert.ToInt32(parentPrestashop.IDCategory))) { nouveauCatalogue.Cat_Parent = CatalogRepository.ReadPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)).Cat_Id; } } CatalogRepository.Add(nouveauCatalogue); } } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
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()); } }
public void LoadCatalogs() { IsBusy = true; LoadingStep = "Chargement des catalogues ..."; Application.Current.Dispatcher.BeginInvoke(new Action(delegate { Mouse.OverrideCursor = Cursors.Wait; }), null); CatalogRepository = new Model.Local.CatalogRepository(); Catalogs = new ObservableCollection <Model.Local.Catalog>(CatalogRepository.ListParent(0)); SelectedCatalog = null; LoadingStep = string.Empty; IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(delegate { Mouse.OverrideCursor = null; }), null); }
private Int32 ReadCatalog(uint?IdPsCategory) { Int32 Catalog = 0; try { Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository(); if (IdPsCategory != null && CatalogRepository.ExistPre_Id((int)IdPsCategory)) { Catalog = CatalogRepository.ReadPre_Id((int)IdPsCategory).Cat_Id; } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } return(Catalog); }
public List <Int32> ListCataloguesArticle(Int32 Article) { List <Int32> result = new List <int>(); List <Model.Local.Catalog> Catalogs = new Model.Local.CatalogRepository().List(); // récupération des ids des catalogues rattachés aux articles sélectionnés result.AddRange(Catalogs.Where(c => c.Article.Count(a => a.Art_Id == Article) > 0 || c.ArticleCatalog.Count(ac => ac.Art_Id == Article) > 0) .Select(c => c.Cat_Id)); // récupération des catalogues parents de ceux déjà filtrés Catalogs = Catalogs.Where(c => c.ChildrenContainsCatalog(result)).ToList(); result.AddRange(Catalogs.Select(c => c.Cat_Id)); // tri des doublons result = result.Distinct().ToList(); return(result); }
public void MoveCatalog() { if (MessageBox.Show("Valider le déplacement de :\n\"" + TargetCatalog.Cat_Name + "\"\n vers :\n\"" + ((SelectedCatalog == null) ? "Racine boutique" : SelectedCatalog.Cat_Name) + "\"", "Déplacement catalogue", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { CatalogRepository.WriteParent(TargetCatalog.Cat_Id, ((SelectedCatalog == null) ? 0 : SelectedCatalog.Cat_Id)); CatalogRepository = new Model.Local.CatalogRepository(); TargetCatalog = CatalogRepository.ReadId(TargetCatalog.Cat_Id); TargetCatalog.Cat_Level = ((SelectedCatalog == null) ? 2 : SelectedCatalog.Cat_Level + 1); TargetCatalog.Cat_Date = DateTime.Now; // <JG> 07/10/2016 ajout recalcul des niveaux sur les enfants ChangeLevelChilds(TargetCatalog); CatalogRepository.Save(); } }
public void Exec(Int32 CatalogSend) { try { Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository(); Model.Local.Catalog Catalog = CatalogRepository.ReadId(CatalogSend); // if the catalog have a parent Boolean isSync = false; uint IdParent = 0; if (Catalog.Cat_Parent != 0) { if (CatalogRepository.ExistId(Catalog.Cat_Parent)) { Model.Local.Catalog CatalogParent = CatalogRepository.ReadId(Catalog.Cat_Parent); if (CatalogParent.Pre_Id != null && CatalogParent.Pre_Id != 0) { IdParent = (uint)CatalogParent.Pre_Id.Value; isSync = true; } } } // default IdParent is defined on shop in Prestashop else { isSync = true; IdParent = Global.CurrentShop.IDCategory; } if (isSync == true) { Boolean isCategory = false; Model.Prestashop.PsCategory Category = new Model.Prestashop.PsCategory(); Model.Prestashop.PsCategoryRepository CategoryRepository = new Model.Prestashop.PsCategoryRepository(); // If the Catalog have a connection with Prestashop if (Catalog.Pre_Id != null) { Catalog.Cat_Date = Catalog.Cat_Date.AddMilliseconds(-Catalog.Cat_Date.Millisecond); if (CategoryRepository.ExistId(Catalog.Pre_Id.Value)) { Category = CategoryRepository.ReadId((UInt32)Catalog.Pre_Id.Value); isCategory = true; if (Category.DateUpd.Ticks > Catalog.Cat_Date.Ticks) { this.ExecDistantLocal(Category, Catalog, CatalogRepository); } else if (Category.DateUpd.Ticks < Catalog.Cat_Date.Ticks) { this.ExecLocalDistant(Catalog, Category, CatalogRepository, CategoryRepository, isCategory, IdParent); } else { ExecGroupsLocalDistant(Category); } } } // We need to sync Catalog with Category else { this.ExecLocalDistant(Catalog, Category, CatalogRepository, CategoryRepository, isCategory, IdParent); } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
private void ExecLocalDistant(Model.Local.Catalog Catalog, Model.Prestashop.PsCategory Category, Model.Local.CatalogRepository CatalogRepository, Model.Prestashop.PsCategoryRepository CategoryRepository, Boolean isCategory, uint IdParent) { try { bool flag_move = (Category.IDParent != IdParent); Core.Temp.SyncCatalogue_ClearSmartyCache = true; Core.Temp.SyncCatalogue_RegenerateTree = true; // Assign data from Catalog to Category //Category.Position = (uint)Catalog.Cat_Position; Category.Active = Convert.ToByte(Catalog.Cat_Active); Category.LevelDepth = (Byte)Catalog.Cat_Level; Category.IDParent = IdParent; Category.DateUpd = Catalog.Cat_Date; // use cron for function "regenerateEntireNtree" //Category.NLeft = CategoryRepository.ReadId(IdParent).NLeft; //Category.NRight = CategoryRepository.ReadId(IdParent).NRight; Category.IDShopDefault = Global.CurrentShop.IDShop; if (isCategory == false) { Category.DateAdd = Category.DateUpd; Category.IsRootCategory = Convert.ToSByte(false); Category.Position = 0; CategoryRepository.Add(Category, Global.CurrentShop.IDShop); // We assign the CategoryId to Catalog Catalog.Pre_Id = (Int32)Category.IDCategory; CatalogRepository.Save(); } else { CategoryRepository.Save(); if (flag_move) { Model.Prestashop.PsCategoryShopRepository PsCategoryShopRepository = new Model.Prestashop.PsCategoryShopRepository(); if (PsCategoryShopRepository.ExistCategoryShop(Category.IDCategory, Core.Global.CurrentShop.IDShop)) { Model.Prestashop.PsCategoryShop PsCategoryShop = PsCategoryShopRepository.ReadCategoryShop(Category.IDCategory, Core.Global.CurrentShop.IDShop); PsCategoryShop.Position = new Model.Prestashop.PsCategoryRepository().ReadNextPosition(1, Category, (uint)Core.Global.CurrentShop.IDShop); PsCategoryShopRepository.Save(); Category.Position = PsCategoryShop.Position; CategoryRepository.Save(); } } } // We need to update CategoryLang too Boolean isCategoryLang = false; Model.Prestashop.PsCategoryLangRepository CategoryLangRepository = new Model.Prestashop.PsCategoryLangRepository(); Model.Prestashop.PsCategoryLang CategoryLang = new Model.Prestashop.PsCategoryLang(); if (CategoryLangRepository.ExistCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop)) { CategoryLang = CategoryLangRepository.ReadCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop); isCategoryLang = true; } CategoryLang.Name = Core.Global.RemovePurge(Catalog.Cat_Name, 128); CategoryLang.Description = Catalog.Cat_Description; CategoryLang.LinkRewrite = Core.Global.ReadLinkRewrite(Catalog.Cat_LinkRewrite); CategoryLang.MetaTitle = Core.Global.RemovePurge(Catalog.Cat_MetaTitle, 70); CategoryLang.MetaDescription = Core.Global.RemovePurge(Catalog.Cat_MetaDescription, 160); CategoryLang.MetaKeywords = Core.Global.RemovePurgeMeta(Catalog.Cat_MetaKeyword, 255); if (isCategoryLang == false) { CategoryLang.IDShop = Global.CurrentShop.IDShop; CategoryLang.IDLang = (uint)Core.Global.Lang; CategoryLang.IDCategory = Category.IDCategory; CategoryLangRepository.Add(CategoryLang); } else { CategoryLangRepository.Save(); } // <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 (!CategoryLangRepository.ExistCategoryLang((int)Category.IDCategory, PsLang.IDLang, Global.CurrentShop.IDShop)) { CategoryLang = new Model.Prestashop.PsCategoryLang(); CategoryLang.IDShop = Global.CurrentShop.IDShop; CategoryLang.IDCategory = Category.IDCategory; CategoryLang.IDLang = PsLang.IDLang; CategoryLang.Name = Core.Global.RemovePurge(Catalog.Cat_Name, 128); CategoryLang.Description = Catalog.Cat_Description; CategoryLang.LinkRewrite = Core.Global.ReadLinkRewrite(Catalog.Cat_LinkRewrite); CategoryLang.MetaTitle = Core.Global.RemovePurge(Catalog.Cat_MetaTitle, 70); CategoryLang.MetaDescription = Core.Global.RemovePurge(Catalog.Cat_MetaDescription, 160); CategoryLang.MetaKeywords = Core.Global.RemovePurgeMeta(Catalog.Cat_MetaKeyword, 255); CategoryLangRepository.Add(CategoryLang); } } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } this.ExecGroupsLocalDistant(Category); // We need to send pictures this.ExecLocalDistantImage(Catalog, Category); } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
private void ExecDistantLocal(Model.Prestashop.PsCategory Category, Model.Local.Catalog Catalog, Model.Local.CatalogRepository CatalogRepository) { try { // Recovery Data From CatalogLang Model.Prestashop.PsCategoryLangRepository CategoryLangRepository = new Model.Prestashop.PsCategoryLangRepository(); Model.Prestashop.PsCategoryLang CategoryLang = new Model.Prestashop.PsCategoryLang(); if (CategoryLangRepository.ExistCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop)) { CategoryLang = CategoryLangRepository.ReadCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop); Catalog.Cat_Name = CategoryLang.Name; Catalog.Cat_Description = CategoryLang.Description; Catalog.Cat_MetaTitle = CategoryLang.MetaTitle; Catalog.Cat_MetaKeyword = CategoryLang.MetaKeywords; Catalog.Cat_MetaDescription = CategoryLang.MetaDescription; Catalog.Cat_LinkRewrite = CategoryLang.LinkRewrite; } bool find_parent = false; if (Category.IDParent != Core.Global.CurrentShop.IDCategory) { if (!CatalogRepository.ExistPre_Id((int)Category.IDParent)) { // todo import catalogue depuis prestashop Core.ImportPrestashop.ImportCatalogue ImportCatalogue = new ImportPrestashop.ImportCatalogue(); ImportCatalogue.Exec((int)Category.IDParent); find_parent = CatalogRepository.ExistPre_Id((int)Category.IDParent); } else { find_parent = true; } if (find_parent) { Catalog.Cat_Level = Category.LevelDepth; } } else { Catalog.Cat_Level = Category.LevelDepth; } //Catalog.Cat_Position = (Int32)Category.Position; Catalog.Cat_Active = Convert.ToBoolean(Category.Active); Catalog.Cat_Date = (Category.DateUpd != null && Category.DateUpd > new DateTime(1753, 1, 2)) ? Category.DateUpd : DateTime.Now.Date; CatalogRepository.Save(); int parent = (Category.IDParent != Core.Global.CurrentShop.IDCategory) ? CatalogRepository.ReadPre_Id((int)Category.IDParent).Cat_Id : 0; CatalogRepository.WriteParent(Catalog.Cat_Id, parent); } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } }
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()); } }