Beispiel #1
0
        /// <summary>
        /// Install plugin
        /// </summary>
        public override void Install()
        {
            var artistAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Artist").FirstOrDefault();

            if (artistAttr == null)
            {
                artistAttr      = new Core.Domain.Catalog.SpecificationAttribute();
                artistAttr.Name = "Artist";
                _specificationAttributeService.InsertSpecificationAttribute(artistAttr);
            }
            var DefaultEnvelopeColorAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "DefaultEnvelopeColor").FirstOrDefault();

            if (DefaultEnvelopeColorAttr == null)
            {
                DefaultEnvelopeColorAttr      = new Core.Domain.Catalog.SpecificationAttribute();
                DefaultEnvelopeColorAttr.Name = "DefaultEnvelopeColor";


                _specificationAttributeService.InsertSpecificationAttribute(DefaultEnvelopeColorAttr);
            }
            var OrientationAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Orientation").FirstOrDefault();

            if (OrientationAttr == null)
            {
                OrientationAttr      = new Core.Domain.Catalog.SpecificationAttribute();
                OrientationAttr.Name = "Orientation";

                var _specificationOptionsVertical = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsVertical.Name = "Vertical";
                OrientationAttr.SpecificationAttributeOptions.Add(_specificationOptionsVertical);

                var _specificationOptionsHorizontal = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsHorizontal.Name = "Horizontal";
                OrientationAttr.SpecificationAttributeOptions.Add(_specificationOptionsHorizontal);

                _specificationAttributeService.InsertSpecificationAttribute(OrientationAttr);
            }

            this.AddOrUpdatePluginLocaleResource("Plugin.ProductArtist.ArtistName", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.ProductArtist.ArtistName.Hint", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.Product.Atist", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.Artist.Saved", "Artist Saved");
            this.AddOrUpdatePluginLocaleResource("artistname.by", "by");
            this.AddOrUpdatePluginLocaleResource("Product.Category", "Categories");
            base.Install();
        }
Beispiel #2
0
        /// <summary>
        /// Install plugin
        /// </summary>
        public override void Install()
        {
            var artistAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Artist").FirstOrDefault();

            if (artistAttr == null)
            {
                artistAttr      = new Core.Domain.Catalog.SpecificationAttribute();
                artistAttr.Name = "Artist";
                _specificationAttributeService.InsertSpecificationAttribute(artistAttr);
            }

            var Treatment = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Treatment").FirstOrDefault();

            if (Treatment == null)
            {
                Treatment      = new Core.Domain.Catalog.SpecificationAttribute();
                Treatment.Name = "Treatment";

                var _specificationOptionsTreatmentImage = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsTreatmentImage.Name = "TreatmentImage";
                Treatment.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentImage);


                var _specificationOptionsTreatmentFill = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsTreatmentFill.Name = "TreatmentFill";
                Treatment.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFill);


                _specificationAttributeService.InsertSpecificationAttribute(Treatment);
            }
            var TreatmentImage = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentImage").FirstOrDefault();

            if (TreatmentImage == null)
            {
                TreatmentImage      = new Core.Domain.Catalog.SpecificationAttribute();
                TreatmentImage.Name = "TreatmentImage";
                _specificationAttributeService.InsertSpecificationAttribute(TreatmentImage);
            }

            var TreatmentFill = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFill").FirstOrDefault();

            if (TreatmentFill == null)
            {
                TreatmentFill      = new Core.Domain.Catalog.SpecificationAttribute();
                TreatmentFill.Name = "TreatmentFill";

                var _specificationOptionsTreatmentFillColor = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsTreatmentFillColor.Name = "TreatmentFillColor";
                TreatmentFill.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFillColor);


                var _specificationOptionsTreatmentFillPattern = new Core.Domain.Catalog.SpecificationAttributeOption();
                _specificationOptionsTreatmentFillPattern.Name = "TreatmentFillPattern";
                TreatmentFill.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFillPattern);

                _specificationAttributeService.InsertSpecificationAttribute(TreatmentFill);
            }
            var TreatmentFillColor = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFillColor").FirstOrDefault();

            if (TreatmentFillColor == null)
            {
                TreatmentFillColor      = new Core.Domain.Catalog.SpecificationAttribute();
                TreatmentFillColor.Name = "TreatmentFillColor";
                _specificationAttributeService.InsertSpecificationAttribute(TreatmentFillColor);
            }

            var TreatmentFillPattern = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFillPattern").FirstOrDefault();

            if (TreatmentFillPattern == null)
            {
                TreatmentFillPattern      = new Core.Domain.Catalog.SpecificationAttribute();
                TreatmentFillPattern.Name = "TreatmentFillPattern";
                _specificationAttributeService.InsertSpecificationAttribute(TreatmentFillPattern);
            }

            this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.ArtistName", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.ArtistName.Hint", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.Artist", "Artist");
            this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.Artist.Saved", "Artist Saved");
            this.AddOrUpdatePluginLocaleResource("artistname.by", "by");
            this.AddOrUpdatePluginLocaleResource("Product.Category", "Categories");
            base.Install();
        }
        internal static List <SpecificationAttribute> Import(КоммерческаяИнформация source,
                                                             ISpecificationAttributeService specificationAttributeService,
                                                             string mappingsFile,
                                                             out Dictionary <string, int> outMappings,
                                                             string logFile)
        {
            logFile.Log("Начало импорта свойств");
            var stats = new[] { 0, 0, 0, 0 };

            // attribute: key = 1c id, value = nopcommerce id
            // attribute value: key = <1c attribute id>.<1c value id>, value = nopcommerce id
            var mappings = File.Exists(mappingsFile)
                ? JsonConvert.DeserializeObject <Dictionary <string, int> >(File.ReadAllText(mappingsFile))
                : new Dictionary <string, int>();;

            var attributes = specificationAttributeService.GetSpecificationAttributes().ToList();

            foreach (var attr in source.Классификатор.Свойства)
            {
                // ищем соответствие только по маппингу
                // потому что может быть несколько атрибутов с одинаковым названием

                var attribute = mappings.ContainsKey(attr.Ид)
                    ? attributes.FirstOrDefault(a => a.Id == mappings[attr.Ид])
                    : null;
                if (attribute != null)
                {
                    // для существующего только добавляем новые значения
                    if (attr.ТипЗначений == AttrTypeDictionary)
                    {
                        foreach (var attrOption in attr.ВариантыЗначений)
                        {
                            var key = $"{attr.Ид}.{attrOption.ИдЗначения}";

                            var option = mappings.ContainsKey(key)
                                ? attribute.SpecificationAttributeOptions.FirstOrDefault(o => o.Id == mappings[key])
                                : null;

                            if (option == null)
                            {
                                // ищем по имени
                                option = attribute.SpecificationAttributeOptions.FirstOrDefault(o => o.Name == attrOption.Значение);
                                if (option == null)
                                {
                                    // добавляем новое значение
                                    option = new Core.Domain.Catalog.SpecificationAttributeOption
                                    {
                                        SpecificationAttributeId = attribute.Id,
                                        Name = attrOption.Значение
                                    };
                                    specificationAttributeService.InsertSpecificationAttributeOption(option);
                                    attribute.SpecificationAttributeOptions.Add(option);
                                    //logFile.Log($"В существующий атрибут {attribute.Name} ({attribute.Id}) добавлено значение {option.Name}");
                                    stats[0]++;
                                }
                                else
                                {
                                    // мапим существующее значение
                                    //logFile.Log($"В существующем атрибуте {attribute.Name} ({attribute.Id}) добавлено сопоставление для значения {option.Name}");
                                    stats[1]++;
                                }
                                mappings[key] = option.Id;
                            }
                        }
                    }
                    continue;
                }

                // new attribute
                attribute = new Core.Domain.Catalog.SpecificationAttribute
                {
                    Name = attr.Наименование
                };
                specificationAttributeService.InsertSpecificationAttribute(attribute);
                attributes.Add(attribute);
                mappings[attr.Ид] = attribute.Id;
                //logFile.Log($"Новый атрибут {attribute.Name} ({attribute.Id})");
                stats[2]++;

                if (attr.ТипЗначений == AttrTypeDictionary)
                {
                    foreach (var attrOption in attr.ВариантыЗначений)
                    {
                        var key = $"{attr.Ид}.{attrOption.ИдЗначения}";

                        var option = new Core.Domain.Catalog.SpecificationAttributeOption
                        {
                            SpecificationAttributeId = attribute.Id,
                            Name = attrOption.Значение
                        };
                        specificationAttributeService.InsertSpecificationAttributeOption(option);
                        attribute.SpecificationAttributeOptions.Add(option);

                        mappings[key] = option.Id;
                        //logFile.Log($"В новый атрибут {attribute.Name} ({attribute.Id}) добавлено значение {option.Name}");
                        stats[3]++;
                    }
                }
                else
                {
                    var key    = $"{attr.Ид}.";
                    var option = new Core.Domain.Catalog.SpecificationAttributeOption
                    {
                        SpecificationAttributeId = attribute.Id,
                        Name = string.Empty
                    };
                    specificationAttributeService.InsertSpecificationAttributeOption(option);
                    attribute.SpecificationAttributeOptions.Add(option);

                    mappings[key] = option.Id;
                }
            }

            File.WriteAllText(mappingsFile, JsonConvert.SerializeObject(mappings, Formatting.Indented), Encoding.UTF8);
            logFile.Log($"Импорт свойств завершен. Привязано: {stats[0]} атрибутов и {stats[1]} значений. Добавлено: {stats[2]} атрибутов и {stats[3]} значений.");

            outMappings = mappings;
            return(attributes);
        }