Exemple #1
0
        public ActionResult HomePageOffersSlideBlock(int count, bool partialView = false, string categoryId = null)
        {
            var categories = _categoryService.GetAllCategories();

            var model = new OffersModel();

            model.Categories = new List <OffersCategoryModel>();
            foreach (var category in categories)
            {
                var categoryModel = new OffersCategoryModel();
                categoryModel.CateogyTitle = category.Name;
                categoryModel.CategoryId   = category.Id;
                model.Categories.Add(categoryModel);
            }

            var products = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, count, 0, 0, 0, 0, 0, null, null);

            if (!string.IsNullOrEmpty(categoryId))
            {
                products = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, count, 0, Convert.ToInt32(categoryId), 0, 0, 0, null, null);
            }
            model.Products = new List <OffersProductModel>();
            if (products.Any())
            {
                model.Products = new List <OffersProductModel>();
                foreach (var i in products)
                {
                    var productModel = new OffersProductModel()
                    {
                        Id                    = i.Id,
                        Rating                = Math.Round(i.Rating ?? 0),
                        BankRating            = Math.Round(i.Customer.Rating ?? 0),
                        Name                  = i.Name,
                        ProductAttributeValue = i.ProductAttributes.FirstOrDefault(x => x.CategoryProductAttribute.ProductBoxAttribute),
                        MetaTitle             = i.MetaTitle,
                        PictureThumbnailUrl   =
                            _pictureService.GetPictureUrl(i.Customer.ProviderLogoId.GetValueOrDefault(), 100, false),
                        ShortDescription = i.ShortDescription,
                        FullDescription  = i.FullDescription,
                        SeName           = i.GetSeName(),
                        OrderingLink     = i.OrderLink,
                    };
                    model.Products.Add(productModel);
                }
            }
            if (partialView)
            {
                return(PartialView("OffersSlideBox", model));
            }
            else
            {
                return(View(model));
            }
        }
Exemple #2
0
        public ActionResult SearchResultsPage(SearchModel model, bool LowerButtonClick, string CategorySeName, int?tag = null)
        {
            var      categoryId = _urlRecordService.GetBySlug(CategorySeName);
            Category categor;

            if (categoryId == null && model.SelectedCategoryAttributes == null && model.CustomerAttributes == null)
            {
                return(RedirectToAction("HomePage"));
            }
            else
            {
                if (model.SelectedCategoryAttributes != null && model.CustomerAttributes != null)
                {
                    categor = _categoryService.GetCategoryById(model.SelectedCategoryAttributes.CategoryId);
                }
                else
                {
                    categor = _categoryService.GetCategoryById(categoryId.EntityId);
                }
            }

            var a = 10;
            IList <SearchProductAttributeValue> attributesToSearch = null; // = ParceProductAttributesToSearch(model);
            IList <SearchProductAttributeValue> customerAttributes = null; // = ParceCustomerAttributesToSearch(model);

            var searchModelFull = new SearchModelFull();

            searchModelFull.LowerButtonClick = LowerButtonClick;
            if (model.SelectedCategoryAttributes != null)
            {
                attributesToSearch = ParceProductAttributesToSearch(model, true);
                searchModelFull.SelectedCategoryAttributes = RestoreSearchModel(model.SelectedCategoryAttributes);
                if (model.DetailedSelectedCategoryAttributes != null)
                {
                    ((List <SearchProductAttributeValue>)attributesToSearch).AddRange(ParceProductAttributesToSearch(model, false));
                    searchModelFull.DetailedSelectedCategoryAttributes = RestoreSearchModel(model.DetailedSelectedCategoryAttributes);
                }
                else
                {
                    searchModelFull.DetailedSelectedCategoryAttributes            = PrepareSearchCategoryModel(categor.Id, false);
                    searchModelFull.DetailedSelectedCategoryAttributes.CategoryId = categor.Id;
                }

                if (model.SelectedAdditionalCategoryAttributes != null)
                {
                    ((List <SearchProductAttributeValue>)attributesToSearch).AddRange(ParceProductAttributesToSearch(model, false, true));
                    searchModelFull.SelectedAdditionalCategoryAttributes = RestoreSearchModel(model.SelectedAdditionalCategoryAttributes);
                }
                else
                {
                    searchModelFull.SelectedAdditionalCategoryAttributes            = PrepareSearchCategoryModel(categor.Id, false, true);
                    searchModelFull.SelectedAdditionalCategoryAttributes.CategoryId = categor.Id;
                }
            }
            else
            {
                searchModelFull.DetailedSelectedCategoryAttributes              = PrepareSearchCategoryModel(categor.Id, false);
                searchModelFull.DetailedSelectedCategoryAttributes.CategoryId   = categor.Id;
                searchModelFull.SelectedAdditionalCategoryAttributes            = PrepareSearchCategoryModel(categor.Id, false, true);
                searchModelFull.SelectedAdditionalCategoryAttributes.CategoryId = categor.Id;
                searchModelFull.SelectedCategoryAttributes = PrepareSearchCategoryModel(categor.Id, true);
            }

            if (model.CustomerAttributes == null)
            {
                searchModelFull.CustomerAttributes = PrepareCustomerAttributes();
            }
            else
            {
                customerAttributes = ParceCustomerAttributesToSearch(model);
                searchModelFull.CustomerAttributes = RestoreCustomerSearchAttributes(model.CustomerAttributes);
            }

            searchModelFull.CustomerAttributes.Cities = _cityService.GetAllCities().OrderBy(x => x.Title).Select(x => new CityModel()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            searchModelFull.CustomerAttributes.Currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel()
            {
                Id   = x.Id,
                Name = x.CurrencyCode
            }).ToList();
            int regionId = 0;

            if (model.CustomerAttributes != null && model.CustomerAttributes.CityId != 0)
            {
                var city = _cityService.GetById(model.CustomerAttributes.CityId);
                if (city != null)
                {
                    regionId = city.RegionId;
                }
            }

            var bestProducts = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, short.MaxValue, 0, categor.Id, 0, 0, 0, null, null).Where(x => x.FeaturedProduct);


            var products = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, short.MaxValue, tag.GetValueOrDefault(), categor.Id, 0, 0, regionId, attributesToSearch, customerAttributes);//дописать linq фильтр по параметрам


            var searchActivity = _customerActivityService.InsertActivity("PublicStore.SearchProduct", _localizationService.GetResource("ITBSFA.SearchLog.Message"), _workContext.CurrentCustomer, Request.UrlReferrer == null ? "" : Request.UrlReferrer.ToString(), 0);

            _searchLogService.LogSearchQuerryWithParameters(attributesToSearch, customerAttributes, searchActivity.Id, regionId, 0, categor.Id, tag.GetValueOrDefault(), 0, 0);

            var productsTags = products.SelectMany(x => x.ProductTags).DistinctBy(x => x.Name);

            foreach (var productsTag in productsTags)
            {
                searchModelFull.ProductTags.Add(new ProductTagModel()
                {
                    Name = productsTag.Name,
                    Id   = productsTag.Id
                });
            }


            var categories = _categoryService.GetAllCategories();

            searchModelFull.Categories = new List <SearchCategoryModel>();
            foreach (var category in categories)
            {
                var categoryModel = new SearchCategoryModel();
                categoryModel.CateogyTitle = category.Name;
                categoryModel.CategoryId   = category.Id;
                categoryModel.SeName       = category.GetSeName(_workContext.WorkingLanguage.Id);
                searchModelFull.Categories.Add(categoryModel);
            }

            searchModelFull.Products = new List <OffersProductModel>();
            if (products != null && products.Any())
            {
                searchModelFull.Products = new List <OffersProductModel>();
                foreach (var i in products)
                {
                    var productModel = new OffersProductModel()
                    {
                        Id                    = i.Id,
                        Rating                = Math.Round(i.Rating ?? 0),
                        BankRating            = Math.Round(i.Customer.Rating ?? 0),
                        Name                  = i.Name,
                        ProductAttributeValue =
                            i.ProductAttributes.FirstOrDefault(x => x.CategoryProductAttribute.ProductBoxAttribute),
                        MetaTitle           = i.MetaTitle,
                        PictureThumbnailUrl =
                            _pictureService.GetPictureUrl(i.Customer.ProviderLogoId.GetValueOrDefault(), 100, false),
                        ShortDescription = i.ShortDescription,
                        FullDescription  = i.FullDescription,
                        SeName           = i.GetSeName(),
                        OrderingLink     = i.OrderLink,
                    };
                    searchModelFull.Products.Add(productModel);
                }
            }

            if (bestProducts.Any())
            {
                searchModelFull.BestProducts = new List <OffersProductModel>();
                foreach (var i in bestProducts)
                {
                    var productModel = new OffersProductModel()
                    {
                        Id                    = i.Id,
                        Rating                = Math.Round(i.Rating ?? 0),
                        BankRating            = Math.Round(i.Customer.Rating ?? 0),
                        Name                  = i.Name,
                        ProductAttributeValue =
                            i.ProductAttributes.FirstOrDefault(x => x.CategoryProductAttribute.ProductBoxAttribute),
                        MetaTitle           = i.MetaTitle,
                        PictureThumbnailUrl =
                            _pictureService.GetPictureUrl(i.Customer.ProviderLogoId.GetValueOrDefault(), 100, false),
                        ShortDescription = i.ShortDescription,
                        FullDescription  = i.FullDescription,
                        SeName           = i.GetSeName(),
                        OrderingLink     = i.OrderLink,
                    };
                    searchModelFull.BestProducts.Add(productModel);
                }
            }

            return(View(searchModelFull));
        }