Exemple #1
0
        public ActionResult AjaxPaint(FormCollection formCollection = null)
        {
            var productSearchViewModel = new ProductSearchViewModel {
                IsAjax = Request.IsAjaxRequest()
            };

            if (formCollection != null)
            {
                TryUpdateModel(productSearchViewModel, formCollection);
            }

            var keywords = Request.QueryString["keywords"];

            if (!string.IsNullOrWhiteSpace(keywords))
            {
                productSearchViewModel.Keywords = keywords;
            }

            productSearchViewModel.IsB2B = B2BCheckoutService.IsB2BUserLoggedIn(HttpContext);

            var pc =
                _productCategoriesService.GetForFrontEnd(
                    new { ShopId = CommerceContext.Shop.CurrentShop.Id, Uri = "paint" }).FirstOrDefault();

            if (pc != null)
            {
                productSearchViewModel.ProductCategory = new List <string>
                {
                    pc.Id.ToString(CultureInfo.InvariantCulture)
                };

                var searchCriteria = GetSearchCriteria(productSearchViewModel);

                var results = _skuProductsService.ProductCatalogue.Products.PerformAjaxSearch(searchCriteria);
                productSearchViewModel.ProductSearchResults = results.SearchResults.Select(t =>
                {
                    if (t.Images.Any())
                    {
                        t.ImageUri = Url.ImageUrl(t.Images.First().ImageAssetID, "productcatalogue", "productthumbnail");
                    }
                    return(t);
                });
                productSearchViewModel.ProductCategories = results.AvailableProductCategories.ToList();
                productSearchViewModel.Options           =
                    _skuAttributeOptionsService.GetAll()
                    .Where(t => results.AvailableSkuAttributeOptionIds.Contains(t.Id))
                    .ToList();
            }
            return(Json(productSearchViewModel, JsonRequestBehavior.AllowGet));
        }