public static string BuildOutline(this Product product, string language, Collection collection)
        {
            var outline = String.Empty;
            if (product.Keywords != null)
            {
                var keyword = product.Keywords.SeoKeyword(Thread.CurrentThread.CurrentUICulture.Name);
                if (keyword != null)
                {
                }
            }

            return outline;
        }
        public async Task<ActionResult> AllAsync(
            string tags,
            string view = "",
            int page = 1,
            string sort_by = "manual")
        {
            var collection = new Collection() { Id = "All", SortBy = sort_by };

            Context.Set("Collection", collection);
            Context.Set("current_page", page);
            Context.Set("current_tags", ParseTags(tags));

            var template = await Task.FromResult("collection");
            if (!string.IsNullOrEmpty(view))
            {
                template = string.Format("{0}.{1}", template, view);
            }

            return View(template);
        }
        public static Collection AsWebModel(this Data.Category category)
        {
            var collection = new Collection();

            var urlTemplate = VirtualPathUtility.ToAbsolute("~/collections/{0}");

            collection.AllTypes = null; // TODO
            collection.AllVendors = null; // TODO
            collection.CurrentType = null; // TODO
            collection.CurrentVendor = null; // TODO
            collection.DefaultSortBy = "manual";
            collection.Description = null; // TODO
            collection.Handle = category.Code;
            collection.Id = category.Id;

            if (category.Image != null)
            {
                collection.Image = category.Image.AsWebModel(category.Image.Name, category.Id);
            }

            collection.Keywords = category.Seo != null ? category.Seo.Select(k => k.AsWebModel()) : null;
            collection.NextProduct = null; // TODO
            collection.Parents = category.Parents != null ? category.Parents.Select(p => p.AsWebModel()) : null;
            collection.PreviousProduct = null; // TODO
            collection.TemplateSuffix = null; // TODO
            collection.Title = category.Name;
            collection.Url = string.Format(urlTemplate, category.Code);

            // specify SEO based url
            var outline = collection.BuildOutline(Thread.CurrentThread.CurrentUICulture.Name).Select(x => x.Value);
            if (outline.Any())
            {
                var urlHelper = UrlHelperExtensions.GetUrlHelper();
                collection.Outline = string.Join("/", outline);
                collection.Url = urlHelper.CategoryUrl(collection.Outline);
            }

            return collection;
        }
Exemplo n.º 4
0
        public static Product AsWebModel(
            this Data.Product product, IEnumerable<Data.Price> prices,
            IEnumerable<Data.Marketing.PromotionReward> rewards, IEnumerable<Data.InventoryInfo> inventories, Collection collection = null)
        {
            var productModel = new Product();

            var pathTemplate = VirtualPathUtility.ToAbsolute("~/products/{0}");
            var description = product.EditorialReviews != null ?
                product.EditorialReviews.FirstOrDefault(er => er.ReviewType != null && er.ReviewType.Equals("quickreview", StringComparison.OrdinalIgnoreCase)) : null;

            var fieldsCollection = new MetafieldsCollection("global", product.Properties);
            var options = GetOptions(product.VariationProperties);

            var keywords = product.Seo != null ? product.Seo.Select(k => k.AsWebModel()) : null;

            var primaryImage = product.PrimaryImage ?? product.Images.FirstOrDefault();

            productModel.Description = description != null ? description.Content : null;
            productModel.Handle = product.Code;
            productModel.Id = product.Id;
            productModel.Images = new ItemCollection<Image>(product.Images.Select(i => i.AsWebModel(product.Name, product.Id)));
            productModel.FeaturedImage = primaryImage.AsWebModel(primaryImage.Name, product.Id);
            productModel.Keywords = keywords;
            productModel.Metafields = new MetaFieldNamespacesCollection(new[] { fieldsCollection });
            productModel.Options = options;
            productModel.Tags = null; // TODO
            productModel.TemplateSuffix = null; // TODO
            productModel.Title = product.Name;
            productModel.Type = product.ProductType;
            productModel.Url = string.Format(pathTemplate, product.Code);
            productModel.Vendor = fieldsCollection.ContainsKey("brand") ? fieldsCollection["brand"] as string : null;

            // form url
            // "/products/code" or "/en-us/store/collection/outline" 

            // specify SEO based url
            var urlHelper = GetUrlHelper();
            var url = String.Empty;
            if (urlHelper != null && productModel.Keywords != null && productModel.Keywords.Any())
            {
                var keyword = productModel.Keywords.SeoKeyword(Thread.CurrentThread.CurrentUICulture.Name);
                if (keyword != null)
                {
                    url = urlHelper.ItemUrl(keyword.Keyword, collection == null ? "" : collection.Outline);
                    if (!String.IsNullOrEmpty(url))
                        productModel.Url = url;
                }
            }

            if (String.IsNullOrEmpty(url) && urlHelper != null)
            {
                url = urlHelper.ItemUrl(productModel.Handle, collection == null ? "" : collection.Outline);
                if (!String.IsNullOrEmpty(url))
                    productModel.Url = url;
            }

            var productRewards = rewards.Where(r => r.RewardType == "CatalogItemAmountReward" && r.ProductId == product.Id);

            if (product.Variations != null)
            {
                foreach (var variation in product.Variations)
                {
                    var price = prices.FirstOrDefault(p => p.ProductId == variation.Id);

                    var variantInventory = inventories != null ?
                        inventories.FirstOrDefault(i => i.ProductId == variation.Id) : null;

                    productModel.Variants.Add(variation.AsVariantWebModel(price, options, productRewards, variantInventory));
                }
            }

            var productPrice = prices.FirstOrDefault(p => p.ProductId == product.Id);

            var productInventory = inventories != null ?
                inventories.FirstOrDefault(i => i.ProductId == product.Id) : null;

            var variant = product.AsVariantWebModel(productPrice, options, productRewards, productInventory);

            variant.Title = "Default Title";

            productModel.Variants.Add(variant);

            return productModel;
        }