コード例 #1
0
        public ActionResult CategoryProductAttributeInsert(GridCommand command, CategoryProductAttributeModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var pva = new CategoryProductAttribute()
            {
                CategoryProductGroupId = model.CategoryProductGroupId,
                ProductAttributeId     = Int32.Parse(model.ProductAttribute), //use ProductAttribute property (not ProductAttributeId) because appropriate property is stored in it
                TextPrompt             = model.TextPrompt,
                IsRequired             = model.IsRequired,
                MainAttribute          = model.MainAttribute,
                ProductBoxAttribute    = model.ProductBoxAttribute,
                AdditionalAttribute    = model.AdditionalAttribute,
                AttributeControlTypeId = Int32.Parse(model.AttributeControlType), //use AttributeControlType property (not AttributeControlTypeId) because appropriate property is stored in it
                SearchControlTypeId    = Int32.Parse(model.SearchAttributeControlType),
                DisplayOrder           = model.DisplayOrder1
            };

            bool flag       = false;
            var  categories = _categoryService.GetAllCategories().Where(x => x.CategoryToCategoryProductAttributeGroups.Where(g => g.CategoryProductAttributeGroupId == model.CategoryProductGroupId).FirstOrDefault() != null);

            foreach (var category in categories)
            {
                foreach (var group in category.CategoryToCategoryProductAttributeGroups.Where(x => x.CategoryProductAttributeGroupId != model.CategoryProductGroupId)
                         .Select(x => x.CategoryProductAttributeGroup))
                {
                    var attr = group.CategoryProductAttributes.Where(x => x.ProductAttributeId == pva.ProductAttributeId).FirstOrDefault();
                    if (attr != null)
                    {
                        flag = true;
                    }
                }
            }

            string conflictMessage = "";

            conflictMessage = ValidateForConflict(pva);
            //productAttribute.
            if (!flag)
            {
                if (!String.IsNullOrEmpty(conflictMessage))
                {
                    ModelState.AddModelError("ProductAttribute", conflictMessage);
                    var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                    return(Content(modelStateErrors.FirstOrDefault()));
                }
                _categoryProductAttributeService.InsertCategoryProductAttribute(pva);
            }
            else
            {
                ModelState.AddModelError("ProductAttribute", "Category attribute group conflict");
                var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            return(CategoryProductAttributeList(command, model.CategoryProductGroupId));
        }
コード例 #2
0
        /// <summary>
        /// A value indicating whether this product variant attribute should have values
        /// </summary>
        /// <param name="categoryProductAttribute">Product variant attribute</param>
        /// <returns>Result</returns>
        public static bool ShouldHaveValues(this CategoryProductAttribute categoryProductAttribute)
        {
            if (categoryProductAttribute == null)
            {
                return(false);
            }

            if (categoryProductAttribute.AttributeControlType == AttributeControlType.TextBox)
            {
                return(false);
            }

            if (categoryProductAttribute.AttributeControlType == AttributeControlType.Money)
            {
                return(false);
            }
            if (categoryProductAttribute.AttributeControlType == AttributeControlType.MoneyRange)
            {
                return(false);
            }
            //other attribute controle types support values
            return(true);
        }
コード例 #3
0
        private void UpdateDb(List <ExportCategory> categoryList, List <ExportProductAttributeValueList> productAttributeValueLists, List <ExportProductAttribute> productAttributeList)
        {
            foreach (var attr in productAttributeList)
            {
                var productAttribute = new ProductAttribute()
                {
                    Name = attr.Name
                };
                _productAttributeService.InsertProductAttribute(productAttribute);
                _localizedEntityService.SaveLocalizedValue(productAttribute, x => x.Name, attr.Name, 1);
                _localizedEntityService.SaveLocalizedValue(productAttribute, x => x.Name, attr.NameRu, 2);
                _localizedEntityService.SaveLocalizedValue(productAttribute, x => x.Name, attr.NameDe, 3);
                _localizedEntityService.SaveLocalizedValue(productAttribute, x => x.Name, attr.NameEs, 4);
                attr.RecievedId = productAttribute.Id;
            }

            foreach (var attributeGroup in productAttributeValueLists)
            {
                var group = new CategoryProductAttributeGroup()
                {
                    Name = attributeGroup.Name
                };

                _categoryProductAttributeService.InsertCategoryProductAttributeGroup(group);
                _localizedEntityService.SaveLocalizedValue(group, x => x.Name, attributeGroup.Name, 1);
                _localizedEntityService.SaveLocalizedValue(group, x => x.Name, attributeGroup.NameRu, 2);
                _localizedEntityService.SaveLocalizedValue(group, x => x.Name, attributeGroup.NameDe, 3);
                _localizedEntityService.SaveLocalizedValue(group, x => x.Name, attributeGroup.NameEs, 4);
                attributeGroup.RecievedId = group.Id;
                var attrs = attributeGroup.List.GroupBy(x => x.AttributeTitle);
                foreach (var attr in attrs)
                {
                    int productAttributeId       = productAttributeList.Where(x => x.Name == attr.Key).First().RecievedId;
                    var categoryProductAttribute = new CategoryProductAttribute()
                    {
                        AttributeControlTypeId = (int)AttributeControlType.Checkboxes,
                        CategoryProductGroupId = group.Id,
                        DisplayOrder           = 0,
                        IsRequired             = false,
                        ProductAttributeId     = productAttributeId
                    };

                    _categoryProductAttributeService.InsertCategoryProductAttribute(categoryProductAttribute);
                    foreach (var value in attr)
                    {
                        var categoryProductAttributeValue = new CategoryProductAttributeValue()
                        {
                            DisplayOrder = 0,
                            CategoryProductAttributeId = categoryProductAttribute.Id,
                            Name          = value.Title,
                            IsPreSelected = false
                        };
                        _categoryProductAttributeService.InsertCategoryProductAttributeValue(categoryProductAttributeValue);
                        _localizedEntityService.SaveLocalizedValue(categoryProductAttributeValue, x => x.Name, value.Title, 1);
                        _localizedEntityService.SaveLocalizedValue(categoryProductAttributeValue, x => x.Name, value.TitleRu, 2);
                        _localizedEntityService.SaveLocalizedValue(categoryProductAttributeValue, x => x.Name, value.TitleDe, 3);
                        _localizedEntityService.SaveLocalizedValue(categoryProductAttributeValue, x => x.Name, value.TitleEs, 4);
                    }
                }
            }

            foreach (var category in categoryList.Where(x => x.ParentCategoryId == 0))
            {
                InsertChildCategories(category, categoryList, productAttributeValueLists);
            }
        }
コード例 #4
0
 public static CategoryProductAttribute ToEntity(this CategoryProductAttributeModel model, CategoryProductAttribute destination)
 {
     return(Mapper.Map(model, destination));
 }
コード例 #5
0
 public static CategoryProductAttributeModel ToModel(this CategoryProductAttribute entity)
 {
     return(Mapper.Map <CategoryProductAttribute, CategoryProductAttributeModel>(entity));
 }
コード例 #6
0
        private SearchProductAttributeModel PrepareProductAttributeModel(CategoryProductAttribute attribute)
        {
            var attributeModel = new SearchProductAttributeModel();

            attributeModel.AttributeTitle         = attribute.ProductAttribute.Name;
            attributeModel.Id                     = attribute.Id;
            attributeModel.PictureThumbnailUrl    = _pictureService.GetPictureUrl(attribute.ProductAttribute.PictureId.GetValueOrDefault(), 100, false);
            attributeModel.Description            = attribute.ProductAttribute.Description;
            attributeModel.AttributeControlTypeId = attribute.SearchControlTypeId;
            switch (attribute.SearchControlType)
            {
            case SearchAttributeControlType.CheckBox:
            case SearchAttributeControlType.CheckBoxGroup:
            {
                var attributeValues = attribute.CategoryProductAttributeValues;
                if (attributeValues.Count > 0)
                {
                    attributeModel.Values = new List <SearchProductAttributeValueModel>();
                    foreach (var value in attributeValues.OrderBy(x => x.DisplayOrder))
                    {
                        var attributeValueModel = new SearchProductAttributeValueModel();
                        attributeValueModel.Id           = value.Id;
                        attributeValueModel.Selected     = value.IsPreSelected;
                        attributeValueModel.ValueText    = value.Name;
                        attributeValueModel.Popularvalue = value.PopularValue;
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }
                break;
            }

            case SearchAttributeControlType.DropDown:
            {
                var attributeValues = attribute.CategoryProductAttributeValues;
                if (attributeValues.Count > 0)
                {
                    attributeModel.Values = new List <SearchProductAttributeValueModel>();
                    //if (attribute.CategoryProductAttributeValues.FirstOrDefault(x => x.IsPreSelected) == null)
                    //{
                    //    attributeModel.Values.Add(new SearchProductAttributeValueModel()
                    //    {
                    //        Id = 0,
                    //        ValueText = attribute.ProductAttribute.Name,
                    //        Selected = true
                    //    });
                    //}

                    if (attributeModel.Values.FirstOrDefault(x => x.Selected) == null)
                    {
                        attributeModel.Values.Add(new SearchProductAttributeValueModel()
                            {
                                Id        = 0,
                                ValueText = attribute.MainAttribute ? attribute.ProductAttribute.Name : _localizationService.GetResource("ITBFA.Attribute.NoImportant"),
                                Selected  = true
                            });
                    }
                    else
                    {
                        if (attributeModel.Values.FirstOrDefault(x => x.Id == 0) == null)
                        {
                            attributeModel.Values.Add(new SearchProductAttributeValueModel()
                                {
                                    Id        = 0,
                                    ValueText = attribute.MainAttribute ? attribute.ProductAttribute.Name : _localizationService.GetResource("ITBFA.Attribute.NoImportant"),
                                    Selected  = false
                                });
                        }
                    }


                    foreach (var value in attributeValues.OrderBy(x => x.DisplayOrder))
                    {
                        var attributeValueModel = new SearchProductAttributeValueModel();
                        attributeValueModel.Id           = value.Id;
                        attributeValueModel.ValueText    = value.Name;
                        attributeValueModel.Popularvalue = value.PopularValue;
                        attributeModel.Values.Add(attributeValueModel);
                        if (value.IsPreSelected)
                        {
                            attributeModel.SelectedAttributeId = value.Id;
                        }
                    }
                }

                break;
            }

            case SearchAttributeControlType.ToddlerIntBetween:
            case SearchAttributeControlType.ToddlerMax:
            case SearchAttributeControlType.ToddlerMin:
            {
                var values = attribute.CategoryProductAttributeValues.Where(x => x.RealValue.HasValue)
                             .Where(x => x.Products.Where(p => !p.Deleted).Any() || x.Products.Count == 0);
                if (!values.Any())
                {
                    attributeModel.MinValue = 0;
                    attributeModel.MinValue = int.MaxValue;
                }
                else
                {
                    values = values.OrderByDescending(x => x.RealValue).ToList();
                    attributeModel.MinValue = (int)values.Last().RealValue;
                    attributeModel.MaxValue = (int)values.First().RealValue;
                    attributeModel.Values   = new List <SearchProductAttributeValueModel>();
                    foreach (var val in attribute.CategoryProductAttributeValues.Where(x => x.PopularValue).Where(x => x.RealValue.HasValue))
                    {
                        var popularValue = new SearchProductAttributeValueModel();
                        popularValue.ValueDouble = ((int)val.RealValue).ToString();
                        attributeModel.Values.Add(popularValue);
                    }
                }
                break;
            }
            }

            return(attributeModel);
        }
コード例 #7
0
        private string ValidateForConflict(CategoryProductAttribute pva)
        {
            var sb = new StringBuilder();

            if (pva.MainAttribute && pva.AdditionalAttribute)
            {
                sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.MainAttributeAdditionalAttribute.Conflict"));
            }
            if (pva.MainAttribute)
            {
                if (pva.SearchControlType == SearchAttributeControlType.CheckBox ||
                    pva.SearchControlType == SearchAttributeControlType.CheckBoxGroup ||
                    pva.SearchControlType == SearchAttributeControlType.ToddlerIntBetween ||
                    pva.SearchControlType == SearchAttributeControlType.ToddlerMax ||
                    pva.SearchControlType == SearchAttributeControlType.ToddlerMin)
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.MainAttribute.Conflict"));
                }
            }

            if (pva.AdditionalAttribute)
            {
                if (!(pva.SearchControlType == SearchAttributeControlType.ToddlerIntBetween ||
                      pva.SearchControlType == SearchAttributeControlType.ToddlerMax ||
                      pva.SearchControlType == SearchAttributeControlType.ToddlerMin))
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.AdditionalAttribute.Conflict"));
                }
            }

            if (pva.AttributeControlType == AttributeControlType.Money ||
                pva.AttributeControlType == AttributeControlType.MoneyRange)
            {
                if (pva.SearchControlType != SearchAttributeControlType.Money)
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.Money.Conflict"));
                }
            }

            if (pva.AttributeControlType == AttributeControlType.ToddlerInt)
            {
                if (!(pva.SearchControlType == SearchAttributeControlType.TextBoxReal ||
                      pva.SearchControlType == SearchAttributeControlType.ToddlerIntBetween ||
                      pva.SearchControlType == SearchAttributeControlType.ToddlerMax ||
                      pva.SearchControlType == SearchAttributeControlType.ToddlerMin))
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.ToddlerInt.Conflict"));
                }
            }

            if (pva.AttributeControlType == AttributeControlType.DropdownList)
            {
                if (pva.SearchControlType != SearchAttributeControlType.DropDown)
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.DropDownList.Conflict"));
                }
            }

            if (pva.AttributeControlType == AttributeControlType.TextBox)
            {
                if (pva.SearchControlType != SearchAttributeControlType.TextBoxText)
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.TextBox.Conflict"));
                }
            }

            if (pva.AttributeControlType == AttributeControlType.Checkboxes)
            {
                if (!(pva.SearchControlType == SearchAttributeControlType.CheckBoxGroup ||
                      pva.SearchControlType == SearchAttributeControlType.CheckBox))
                {
                    sb.AppendLine(_localizationService.GetResource("ITBSFA.Admin.CheckBox.Conflict"));
                }
            }

            return(sb.ToString());
        }