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(); } } } }
internal static Int32?CreateFeatureValue(String InfoLibreValue, Int32 Feature) { Int32?r = null; try { lock (Core.Temp.ListFeatureLocked) { // ajout de la gestion d'une liste de locked feature au moment de la création pr éviter les doublons // while (Core.Temp.ListFeatureLocked.Contains(Feature)) { System.Threading.Thread.Sleep(20); } Core.Temp.ListFeatureLocked.Add(Feature); Model.Prestashop.PsFeatureValueLangRepository PsFeatureValueLangRepository = new Model.Prestashop.PsFeatureValueLangRepository(); if (PsFeatureValueLangRepository.ExistFeatureValueLang(InfoLibreValue, Core.Global.Lang, (UInt32)Feature)) { r = (int)PsFeatureValueLangRepository.ReadFeatureValueLang(InfoLibreValue, Core.Global.Lang, (UInt32)Feature).IDFeatureValue; } else { Model.Prestashop.PsFeatureValue PsFeatureValue = new Model.Prestashop.PsFeatureValue() { Custom = 0, IDFeature = (uint)Feature }; new Model.Prestashop.PsFeatureValueRepository().Add(PsFeatureValue); r = (int)PsFeatureValue.IDFeatureValue; foreach (Model.Prestashop.PsLang lang in new Model.Prestashop.PsLangRepository().ListActive(1, Core.Global.CurrentShop.IDShop)) { new Model.Prestashop.PsFeatureValueLangRepository().Add(new Model.Prestashop.PsFeatureValueLang() { IDLang = lang.IDLang, IDFeatureValue = PsFeatureValue.IDFeatureValue, Value = InfoLibreValue }); } } Core.Temp.ListFeatureLocked.Remove(Feature); } } catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); } return(r); }
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()); } }