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()); } }
//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 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()); } }