Ejemplo n.º 1
0
        private SearchProductCategoryModel PrepareSearchCategoryModel(int categoryId, bool MainAttributes, bool additionalAttributes = false)
        {
            var currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel()
            {
                Id   = x.Id,
                Name = x.CurrencyCode
            }).ToList();
            var category      = _categoryService.GetCategoryById(categoryId);
            var categoryModel = new SearchProductCategoryModel();

            categoryModel.Currencies   = currencies;
            categoryModel.Attributes   = new List <SearchProductAttributeModel>();
            categoryModel.CateogyTitle = category.Name;
            categoryModel.CategoryId   = category.Id;
            var attributeGroups = _categoryProductAttributeService.GetCategoryToCategoryProductAttributeGroupByCategoryId(category.Id);

            if (attributeGroups.Count > 0)
            {
                foreach (var group in attributeGroups)
                {
                    var attributes = group.CategoryProductAttributeGroup.CategoryProductAttributes;
                    attributes = attributes.Where(x => x.MainAttribute == MainAttributes && x.AdditionalAttribute == additionalAttributes).OrderByDescending(x => x.DisplayOrder).ToList();
                    if (attributes.Count > 0)
                    {
                        foreach (var attribute in attributes)
                        {
                            var attributeModel = PrepareProductAttributeModel(attribute);
                            categoryModel.Attributes.Add(attributeModel);
                        }
                    }
                }
            }

            return(categoryModel);
        }
Ejemplo n.º 2
0
        public async Task <PaginatedResult <ProductCategory> > SearchAsync(SearchProductCategoryModel rq)
        {
            // filter
            var queryObject = QueryObject <ProductCategory> .Empty;

            if (!string.IsNullOrWhiteSpace(rq.Keyword))
            {
                var keyword = rq.Keyword;
                queryObject.And(new ProductCategoryQueryObjects.ContainsKeyword(keyword));
            }

            // orderby
            if (!rq.Sort.Any())
            {
                rq.Sort.Add(new SortItem {
                    FieldName = nameof(ProductCategory.IdentityKey)
                });
            }

            rq.Sort.ForEach(x => queryObject.AddOrderBy(x.FieldName, x.IsDescending));

            // execute
            var result = await _genericRepo.SearchAsync(queryObject, rq.Pagination);

            return(result);
        }
Ejemplo n.º 3
0
        public ActionResult HomePageSearchBlock()
        {
            var categories = _categoryService.GetAllCategories();
            var currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel()
            {
                Id   = x.Id,
                Name = x.CurrencyCode
            }).ToList();
            var model = new SearchProductCategoriesModel();

            model.Categories = new List <SearchProductCategoryModel>();
            foreach (var category in categories)
            {
                var categoryModel = new SearchProductCategoryModel();
                categoryModel.Currencies   = currencies;
                categoryModel.Attributes   = new List <SearchProductAttributeModel>();
                categoryModel.CateogyTitle = category.Name;
                categoryModel.CategoryId   = category.Id;
                categoryModel.SeoName      = category.GetSeName(_workContext.WorkingLanguage.Id);
                var attributeGroups = _categoryProductAttributeService.GetCategoryToCategoryProductAttributeGroupByCategoryId(category.Id);
                if (attributeGroups.Count > 0)
                {
                    foreach (var group in attributeGroups)
                    {
                        var attributes = group.CategoryProductAttributeGroup.CategoryProductAttributes;
                        attributes = attributes.Where(x => x.MainAttribute).OrderByDescending(x => x.DisplayOrder).ToList();
                        if (attributes.Count > 0)
                        {
                            foreach (var attribute in attributes)
                            {
                                var attributeModel = PrepareProductAttributeModel(attribute);
                                categoryModel.Attributes.Add(attributeModel);
                            }
                        }
                    }
                }

                model.Categories.Add(categoryModel);
            }

            model.CustomerAttributes = PrepareCustomerAttributes();
            return(View(model));
        }
Ejemplo n.º 4
0
        private SearchProductCategoryModel RestoreCustomerSearchAttributes(SearchProductCategoryModel model)
        {
            foreach (var attributeModel in model.Attributes)
            {
                var attribute = _customerInformationAttributeService.GetAttributeById(attributeModel.Id);
                switch (attributeModel.AttributeControlTypeId)
                {
                case (int)CustomerInformationProductSearchControlType.Gender:
                {
                    attributeModel.Values = new List <SearchProductAttributeValueModel>();
                    var values = _customerInformationAttributeService.GetAttributeValuesForSearchProduct(attribute.Id);
                    foreach (var val in values)
                    {
                        var attributeValue = new SearchProductAttributeValueModel();
                        var referenceValue = _customerInformationAttributeService.GetValue(val.Id);
                        attributeValue.Id        = val.Id;
                        attributeValue.ValueText = referenceValue.Text;
                        if (attributeModel.SelectedAttributeId != 0)
                        {
                            attributeValue.Selected = attributeValue.Id == attributeModel.SelectedAttributeId;
                        }
                        else
                        {
                            if (_workContext.CurrentCustomer.Gender.HasValue)
                            {
                                attributeValue.Selected = _workContext.CurrentCustomer.Gender == referenceValue.Id;
                            }
                        }

                        attributeModel.Values.Add(attributeValue);
                    }
                    break;
                }
                }
            }

            return(model);
        }
Ejemplo n.º 5
0
        private SearchProductCategoryModel RestoreSearchModel(SearchProductCategoryModel model)
        {
            foreach (var attributeModel in model.Attributes)
            {
                var attribute = _categoryProductAttributeService.GetCategoryProductAttributeById(attributeModel.Id);
                attributeModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(attribute.ProductAttribute.PictureId.GetValueOrDefault(), 100, false);
                attributeModel.Description         = attribute.ProductAttribute.Description;
                switch (attributeModel.AttributeControlTypeId)
                {
                case (int)SearchAttributeControlType.CheckBox:
                case (int)SearchAttributeControlType.CheckBoxGroup:
                {
                    //if(attributeModel
                    break;
                }

                case (int)SearchAttributeControlType.DropDown:
                {
                    var attributeValues = attribute.CategoryProductAttributeValues;
                    if (attributeValues.Count > 0)
                    {
                        attributeModel.Values = new List <SearchProductAttributeValueModel>();

                        if (attributeModel.SelectedAttributeId == 0)
                        {
                            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.ProductAttribute.Name,
                        //            Selected = false
                        //        });
                        //    }
                        //}

                        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
                                });
                        }

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

                case (int)SearchAttributeControlType.ToddlerIntBetween:
                case (int)SearchAttributeControlType.ToddlerMax:
                case (int)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.Count() == 0)
                    {
                        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;
                }
                }
            }

            var currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel()
            {
                Id   = x.Id,
                Name = x.CurrencyCode
            }).ToList();

            model.Currencies = currencies;
            return(model);
        }
Ejemplo n.º 6
0
        private SearchProductCategoryModel PrepareCustomerAttributes()
        {
            var model = new SearchProductCategoryModel();

            model.Currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel()
            {
                Id   = x.Id,
                Name = x.CurrencyCode
            }).ToList();
            model.Attributes = new List <SearchProductAttributeModel>();
            model.Cities     = _cityService.GetAllCities().OrderBy(x => x.Title).Select(x => new CityModel()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();
            var customerAttributes = _customerInformationAttributeService.GetAllAttributes().OrderByDescending(x => x.DisplayOrder);

            foreach (var attribute in customerAttributes)
            {
                var attributeModel = new SearchProductAttributeModel();
                attributeModel.Id = attribute.Id;
                attributeModel.AttributeControlTypeId = attribute.ProductSearchControlTypeId;
                attributeModel.AttributeTitle         = typeof(Customer).GetProperty(attribute.CustomerFieldName)
                                                        .GetCustomAttribute <CustomerFieldIsInProductAttribute>().Alias;
                switch (attribute.ProductSearchControlType)
                {
                case CustomerInformationProductSearchControlType.Gender:
                {
                    attributeModel.Values = new List <SearchProductAttributeValueModel>();
                    var values = _customerInformationAttributeService.GetAttributeValuesForSearchProduct(attribute.Id);
                    foreach (var val in values)
                    {
                        var attributeValue = new SearchProductAttributeValueModel();
                        var referenceValue = _customerInformationAttributeService.GetValue(val.Id);
                        attributeValue.Id        = val.Id;
                        attributeValue.ValueText = referenceValue.Text;
                        if (_workContext.CurrentCustomer.Gender.HasValue)
                        {
                            attributeValue.Selected = _workContext.CurrentCustomer.Gender == referenceValue.Id;
                        }

                        attributeModel.Values.Add(attributeValue);
                    }
                    break;
                }

                case CustomerInformationProductSearchControlType.NumberTextBoxExact:
                case CustomerInformationProductSearchControlType.NumberToddlerBetween:
                case CustomerInformationProductSearchControlType.NumberToddlerLess:
                case CustomerInformationProductSearchControlType.NumberToddlerMore:
                case CustomerInformationProductSearchControlType.MoneyLess:
                case CustomerInformationProductSearchControlType.MoneyMore:
                {
                    if (_workContext.CurrentCustomer.IsRegistered())
                    {
                        var val = _customerInformationAttributeService.GetCustomerAttribute(attribute.Id, _workContext.CurrentCustomer);
                        attributeModel.AttributeValue = val.Text;
                        attributeModel.CurrencyId     = val.Id;
                    }
                    break;
                }
                }

                model.Attributes.Add(attributeModel);
            }

            return(model);
        }