Exemplo n.º 1
0
 public BrandModel()
 {
     Categories             = new List <BrandCategoryModel>();
     PagingFilteringContext = new ProductPagingFilteringModel();
     Products = new List <ProductBoxModel>();
     Banners  = new List <BannerModel>();
 }
Exemplo n.º 2
0
        public ActionResult Brand(string urlKey, ProductPagingFilteringModel command)
        {
            if (string.IsNullOrEmpty(urlKey))
            {
                return(RedirectToAction("ShopByBrand", "Brand"));
            }

            var brand = _brandService.GetBrandByUrlKey(urlKey);

            if (brand == null)
            {
                return(InvokeHttp404());
            }

            BrandModel model;

            if (brand.HasMicrosite == true)
            {
                var key = string.Format(CacheKey.BRAND_MODEL_URL_KEY, urlKey);

                model = _cacheManager.Get(key, delegate()
                {
                    return(PrepareBrandModel(brand, includeProductsIfNoCategory: true));
                });
            }
            else
            {
                model = PrepareBrandModelWithProducts(brand, command);
            }

            return(View(model));
        }
Exemplo n.º 3
0
        protected BrandModel PrepareBrandModelWithProducts(Brand brand, ProductPagingFilteringModel command, string top = null, string second = null, string third = null)
        {
            decimal price;
            decimal?priceMin = null;

            if (!string.IsNullOrEmpty(command.From) && decimal.TryParse(command.From, out price))
            {
                priceMin = price;
            }
            decimal?priceMax = null;

            if (!string.IsNullOrEmpty(command.To) && decimal.TryParse(command.To, out price))
            {
                priceMax = price;
            }

            var result = _productService.GetPagedProductOverviewModelsByBrandCategory(
                pageIndex: command.PageNumber - 1,
                pageSize: command.PageSize,
                brandId: brand.Id,
                topUrlKey: top,
                secondUrlKey: second,
                thirdUrlKey: third,
                priceMin: priceMin,
                priceMax: priceMax,
                enabled: true,
                includeDiscontinuedButInStock: true,
                orderBy: command.OrderBy);

            var model = PrepareBrandModel(
                brand,
                topUrlKey: string.IsNullOrEmpty(top) ? string.Empty : top,
                secondUrlKey: string.IsNullOrEmpty(second) ? string.Empty : second,
                thirdUrlKey: string.IsNullOrEmpty(third) ? string.Empty : third);

            model.Products = result.Items.PrepareProductBoxModels();
            model.PagingFilteringContext.LoadPagedList(result);
            model.PagingFilteringContext.PriceRangeFilter = new PriceRangeFilterModel
            {
                Min  = Math.Round(result.MinPriceFilterByKeyword).ToString(),
                Max  = Math.Ceiling(result.MaxPriceFilterByKeyword).ToString(),
                From = (command.From == string.Empty) ? Math.Round(result.MinPriceFilterByKeyword).ToString() : command.From,
                To   = (command.To == string.Empty) ? Math.Ceiling(result.MaxPriceFilterByKeyword).ToString() : command.To
            };
            model.PagingFilteringContext.SelectedPageSize = command.PageSize;
            model.PagingFilteringContext.OrderBy          = command.OrderBy;
            model.PagingFilteringContext.PrepareSortingOptions();
            model.PagingFilteringContext.ViewMode = command.ViewMode;
            model.PagingFilteringContext.PrepareViewModeOptions();

            return(model);
        }
Exemplo n.º 4
0
        public ActionResult BrandWithProducts(string urlKey, string top, string second, string third, ProductPagingFilteringModel command)
        {
            var brand = _brandService.GetBrandByUrlKey(urlKey);

            if (brand == null)
            {
                return(InvokeHttp404());
            }

            var model = PrepareBrandModelWithProducts(brand, command, top, second, third);

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Search(SearchModel model, ProductPagingFilteringModel command)
        {
            decimal price;
            decimal?priceMin = null;

            if (!string.IsNullOrEmpty(command.From) && decimal.TryParse(command.From, out price))
            {
                priceMin = price;
            }
            decimal?priceMax = null;

            if (!string.IsNullOrEmpty(command.To) && decimal.TryParse(command.To, out price))
            {
                priceMax = price;
            }

            var brandList = new List <int>();

            if (!string.IsNullOrEmpty(command.Brands))
            {
                var brandStringArray = command.Brands.Split(',');
                if (brandStringArray.Length > 0)
                {
                    int[] brandArray = Array.ConvertAll(brandStringArray, int.Parse);
                    brandList = new List <int>(brandArray);
                }
            }

            var    productId        = 0;
            string keywords         = null;
            string originalKeywords = model.q;

            if (int.TryParse(model.q, out productId) == false)
            {
                keywords = model.q;
            }

            if (!string.IsNullOrEmpty(keywords))
            {
                keywords = keywords.Trim();
            }

            var result = _searchService.SearchProduct(
                pageIndex: command.PageNumber - 1,
                pageSize: command.PageSize,
                brandIds: brandList.Count > 0 ? brandList : null,
                productIds: productId != 0 ? new int[] { productId } : null,
                enabled: true,
                visibleIndividually: true,
                includeDiscontinuedButInStock: true,
                priceMin: priceMin,
                priceMax: priceMax,
                keywords: keywords,
                searchDescriptions: false,
                useFullTextSearch: true,
                fullTextMode: FulltextSearchMode.Or,
                applySearchAnalysis: true,
                applyKeywordSuggestion: true,
                orderBy: command.OrderBy);

            //If we have predefined search term, we would like to bring customers to this url.
            if (result.HasSearchTerm)
            {
                return(Redirect(result.SearchTerm.RedirectUrl));
            }

            //If we only have one product, redirect to product page.
            if (result.Items.Count == 1 && command.PageNumber == 1)
            {
                return(RedirectToRoute("Product", new { urlkey = result.Items[0].UrlKey }));
            }

            model = new SearchModel();
            model.OriginalKeywords = string.IsNullOrEmpty(keywords) ? originalKeywords : keywords;
            model.q = model.OriginalKeywords;
            if (!string.IsNullOrEmpty(result.SuggestedKeywords))
            {
                model.SuggestedKeywords = result.SuggestedKeywords.ToLower() != keywords.ToLower() ? result.SuggestedKeywords : string.Empty;
            }

            //If we have no result, redirect to empty result page.
            if (result.Items.Count == 0 &&
                result.MinPriceFilterByKeyword == 0M &&
                result.MaxPriceFilterByKeyword == 0M)
            {
                return(View("SearchResultNotFound", model));
            }

            model.Products = result.Items.PrepareProductBoxModels();
            model.PagingFilteringContext.LoadPagedList(result);

            string min = Math.Round(result.MinPriceFilterByKeyword).ToString();
            string max = Math.Ceiling(result.MaxPriceFilterByKeyword).ToString();

            model.PagingFilteringContext.PriceRangeFilter = new PriceRangeFilterModel()
            {
                Min  = min,
                Max  = max,
                From = (command.From == string.Empty) ? min : command.From,
                To   = (command.To == string.Empty) ? max : command.To
            };

            //model.PagingFilteringContext.BrandRangeFilter.Brands = brandRange;
            model.PagingFilteringContext.BrandRangeFilter.SelectedBrands = brandList.ToArray();
            model.PagingFilteringContext.SelectedPageSize = command.PageSize;
            model.PagingFilteringContext.OrderBy          = command.OrderBy;
            model.PagingFilteringContext.PrepareSortingOptions();
            model.PagingFilteringContext.ViewMode = command.ViewMode;
            model.PagingFilteringContext.Brands   = command.Brands;
            model.PagingFilteringContext.PrepareViewModeOptions();

            return(View(model));
        }