Ejemplo n.º 1
0
        public virtual Search ToLiquidSearch(IMutablePagedList <storefrontModel.Product> products, WorkContext workContext)
        {
            var factory = ServiceLocator.Current.GetInstance <ShopifyModelFactory>();
            var result  = factory.CreateSearch();

            result.Performed = true;
            result.Terms     = workContext.CurrentProductSearchCriteria.Keyword;

            result.Results = new MutablePagedList <dotLiquid.Drop>((pageNumber, pageSize, sortInfos) =>
            {
                products.Slice(pageNumber, pageSize, sortInfos);
                return(new StaticPagedList <dotLiquid.Drop>(products.Select(x => x.ToShopifyModel()), products));
            });

            if (workContext.Aggregations != null)
            {
                result.AllTags = new TagCollection(new MutablePagedList <Tag>((pageNumber, pageSize, sortInfos) =>
                {
                    workContext.Aggregations.Slice(pageNumber, pageSize, sortInfos);
                    var tags = workContext.Aggregations
                               .Where(a => a.Items != null)
                               .SelectMany(a => a.Items.Select(item => item.ToShopifyModel(a.Field, a.Label)));
                    return(new StaticPagedList <Tag>(tags, workContext.Aggregations));
                }, workContext.Aggregations.PageNumber, workContext.Aggregations.PageSize));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static Search ToShopifyModel(this IMutablePagedList <Storefront.Model.Catalog.Product> products, string terms)
        {
            var retVal = new Search
            {
                Results = new MutablePagedList <Drop>((pageNumber, pageSize) =>
                {
                    products.Slice(pageNumber, pageSize);
                    return(new StaticPagedList <Drop>(products.Select(x => x.ToShopifyModel()).OfType <Drop>(), products));
                }),
                Terms     = terms,
                Performed = true
            };

            return(retVal);
        }