Ejemplo n.º 1
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();
                    }
                }
            }
        }
Ejemplo n.º 2
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());
            }
        }