Esempio n. 1
0
        protected List <ConversionImageModel> PrepareConversionImagesList(int categoryAttributeGroupId)
        {
            var imagesList = new List <ConversionImageModel>();

            if (categoryAttributeGroupId != 0)
            {
                var group = _categoryProductAttributeService.GetCategoryProductAttributeGroupById(categoryAttributeGroupId);
                foreach (var image in group.ConversionImages)
                {
                    var model = new ConversionImageModel()
                    {
                        Name         = image.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id, false),
                        Id           = image.Id,
                        GroupModelId = categoryAttributeGroupId
                    };
                    model.Locales = new List <ConversionImageLocalizedModel>();
                    AddLocales(_languageService, model.Locales, (locale, languageId) =>
                    {
                        locale.Name      = image.GetLocalized(x => x.Name, languageId, false, false);
                        locale.PictureId = image.GetLocalized(x => x.PictureId, languageId, false, false);
                    });
                    imagesList.Add(model);
                }
                return(imagesList);
            }
            return(imagesList);
        }
Esempio n. 2
0
        public ActionResult CategoryProductAttributeGroupAdd(string categoryGroupId, string categoryId)
        {
            int  intCategoryGroupId = 0;
            int  intCategoryId      = 0;
            bool resCategoryGroupId = Int32.TryParse(categoryGroupId, out intCategoryGroupId);
            bool resCategoryId      = Int32.TryParse(categoryId, out intCategoryId);

            if (resCategoryGroupId && resCategoryId)
            {
                CategoryToCategoryProductAttributeGroup ctc = new CategoryToCategoryProductAttributeGroup()
                {
                    CategoryId = intCategoryId,
                    CategoryProductAttributeGroupId = intCategoryGroupId
                };
                var catAttrGr = _categoryProductAttributeService.GetCategoryToCategoryProductAttributeGroupByCategoryIdAndGroupId(intCategoryId, intCategoryGroupId);
                if (catAttrGr == null)
                {
                    var  groups = _categoryService.GetCategoryById(intCategoryId).CategoryToCategoryProductAttributeGroups.Select(x => x.CategoryProductAttributeGroup);
                    var  grp    = _categoryProductAttributeService.GetCategoryProductAttributeGroupById(intCategoryGroupId);
                    bool result = false;
                    foreach (var group in groups)
                    {
                        foreach (var attr in group.CategoryProductAttributes)
                        {
                            var attr_exist = grp.CategoryProductAttributes.Where(x => x.ProductAttributeId == attr.ProductAttributeId).FirstOrDefault();
                            if (attr_exist != null)
                            {
                                result = true;
                            }
                        }
                    }
                    if (!result)
                    {
                        _categoryProductAttributeService.InsertCategoryToCategoryProductAttributeGroup(ctc);
                    }
                    else
                    {
                        return(Content("Group has attribute that was already defined in other attribute group attached to this category!"));
                    }
                }

                return(Content("Success"));
            }
            return(RedirectToAction("List"));
        }