public async Task <ActionResult> ProductDetails(string productId)
        {
            var product = (await _catalogSearchService.GetProductsAsync(new[] { productId }, WorkContext.CurrentProductResponseGroup)).FirstOrDefault();

            WorkContext.CurrentProduct = product;

            if (product != null)
            {
                WorkContext.CurrentPageSeo = product.SeoInfo;

                if (product.CategoryId != null)
                {
                    var category = (await _catalogSearchService.GetCategoriesAsync(new[] { product.CategoryId }, CategoryResponseGroup.Full)).FirstOrDefault();
                    WorkContext.CurrentCategory = category;

                    if (category != null)
                    {
                        category.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                        {
                            var criteria        = WorkContext.CurrentCatalogSearchCriteria.Clone();
                            criteria.CategoryId = product.CategoryId;
                            criteria.PageNumber = pageNumber;
                            criteria.PageSize   = pageSize;
                            if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty())
                            {
                                criteria.SortBy = SortInfo.ToString(sortInfos);
                            }
                            return(_catalogSearchService.SearchProducts(criteria).Products);
                        });
                    }
                }
            }

            return(View("product", WorkContext));
        }
Beispiel #2
0
        public async Task <ActionResult> ProductDetails(string productId)
        {
            var product = (await _catalogSearchService.GetProductsAsync(new[] { productId },
                                                                        Model.Catalog.ItemResponseGroup.Variations |
                                                                        Model.Catalog.ItemResponseGroup.ItemProperties |
                                                                        Model.Catalog.ItemResponseGroup.ItemSmall |
                                                                        Model.Catalog.ItemResponseGroup.ItemWithPrices)).FirstOrDefault();

            WorkContext.CurrentProduct = product;
            if (product.CategoryId != null)
            {
                var category = (await _catalogSearchService.GetCategoriesAsync(new[] { product.CategoryId }, Model.Catalog.CategoryResponseGroup.Full)).FirstOrDefault();
                WorkContext.CurrentCategory = category;
                category.Products           = new MutablePagedList <Product>((pageNumber, pageSize) =>
                {
                    var criteria        = WorkContext.CurrentCatalogSearchCriteria.Clone();
                    criteria.CategoryId = product.CategoryId;
                    criteria.PageNumber = pageNumber;
                    criteria.PageSize   = pageSize;
                    return(_catalogSearchService.SearchProducts(criteria).Products);
                });
            }

            return(View("product", WorkContext));
        }
        public async Task <ActionResult> VendorDetails(string vendorId)
        {
            var vendor = (await _customerService.GetVendorsByIdsAsync(vendorId)).FirstOrDefault();

            if (vendor != null)
            {
                vendor.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    var criteria = new ProductSearchCriteria
                    {
                        VendorId      = vendorId,
                        PageNumber    = pageNumber,
                        PageSize      = pageSize,
                        SortBy        = SortInfo.ToString(sortInfos),
                        ResponseGroup = ItemResponseGroup.ItemSmall
                    };

                    var searchResult = _catalogSearchService.SearchProducts(criteria);
                    return(searchResult.Products);
                });

                WorkContext.CurrentPageSeo = vendor.SeoInfo;
                WorkContext.CurrentVendor  = vendor;

                return(View("vendor", WorkContext));
            }

            throw new HttpException(404, "Vendor not found. Vendor ID: '" + vendorId + "'");
        }
Beispiel #4
0
        public async Task <ActionResult> VendorDetails(string vendorId)
        {
            var vendor = await _customerService.GetVendorByIdAsync(vendorId);

            if (vendor != null)
            {
                vendor.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    var criteria = new CatalogSearchCriteria
                    {
                        CatalogId        = base.WorkContext.CurrentStore.Catalog,
                        VendorId         = vendorId,
                        SearchInChildren = true,
                        PageNumber       = pageNumber,
                        PageSize         = pageSize,
                        SortBy           = SortInfo.ToString(sortInfos),
                        ResponseGroup    = CatalogSearchResponseGroup.WithProducts
                    };
                    var searchResult = _catalogSearchService.SearchProducts(criteria);
                    return(searchResult.Products);
                });

                WorkContext.CurrentPageSeo = vendor.SeoInfo;
                WorkContext.CurrentVendor  = vendor;

                return(View("vendor", WorkContext));
            }

            throw new HttpException(404, "Vendor not found. Vendor ID: '" + vendorId + "'");
        }
Beispiel #5
0
        /// <summary>
        /// GET search/{categoryId}?view=...
        /// This method called from SeoRoute when url contains slug for category
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        public async Task <ActionResult> CategoryBrowsing(string categoryId, string view)
        {
            var category = (await _searchService.GetCategoriesAsync(new[] { categoryId }, CategoryResponseGroup.Full)).FirstOrDefault();

            if (category == null)
            {
                throw new HttpException(404, String.Format("Category {0} not found.", categoryId));
            }

            WorkContext.CurrentCategory     = category;
            WorkContext.CurrentPageSeo      = category.SeoInfo.JsonClone();
            WorkContext.CurrentPageSeo.Slug = category.Url;

            var criteria = WorkContext.CurrentProductSearchCriteria.Clone();

            criteria.Outline = string.Format("{0}*", category.Outline); // should we simply take it from current category?

            if (category != null)
            {
                category.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) =>
                {
                    criteria.PageNumber = pageNumber;
                    criteria.PageSize   = pageSize;
                    if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty())
                    {
                        criteria.SortBy = SortInfo.ToString(sortInfos);
                    }
                    var result = _searchService.SearchProducts(criteria);
                    //Prevent double api request for get aggregations
                    //Because catalog search products returns also aggregations we can use it to populate workContext using C# closure
                    //now workContext.Aggregation will be contains preloaded aggregations for current search criteria
                    WorkContext.Aggregations = new MutablePagedList <Aggregation>(result.Aggregations);
                    return(result.Products);
                }, 1, ProductSearchCriteria.DefaultPageSize);


                // make sure title is set
                if (string.IsNullOrEmpty(WorkContext.CurrentPageSeo.Title))
                {
                    WorkContext.CurrentPageSeo.Title = category.Name;
                }
            }

            if (string.IsNullOrEmpty(view))
            {
                view = "grid";
            }

            if (view.Equals("list", StringComparison.OrdinalIgnoreCase))
            {
                return(View("collection.list", WorkContext));
            }

            return(View("collection", WorkContext));
        }