public IHttpActionResult GetVariantSkuFromSelectionRequest([FromBody] GetVariantSkuFromSelectionRequest request)
        {
            var     product = CatalogLibrary.GetProduct(request.ProductSku);
            Product variant = null;

            if (product.ProductType == ProductType.ProductFamily && request.VariantProperties.Any()
                ) // If there are variant values we'll need to find the selected variant
            {
                var query = ProductsIndex.Find().Where(p => p.Sku == request.ProductSku && p.ProductType == ProductType.Variant);
                request.VariantProperties.ForEach(property =>
                {
                    query = query.Where(p => p[property.Key] == property.Value);
                });
                variant = query.FirstOrDefault();
            }
            else if (!product.Variants.Any()) // Only use the current product where there are no variants
            {
                variant = product;
            }

            if (variant == null)
            {
                return(NotFound());
            }

            var variantModel = new ProductVariation
            {
                Sku         = variant.Sku,
                VariantSku  = variant.VariantSku,
                ProductName = variant.Name,
            };

            return(Json(new { Variant = variantModel }));
        }
예제 #2
0
        public ActionResult Index()
        {
            IList <BreadcrumbsViewModel> breadcrumbs = new List <BreadcrumbsViewModel>();
            Category lastCategory = null;
            Product  product      = CatalogContext.CurrentProduct;

            foreach (var category in CatalogContext.CurrentCategories)
            {
                var breadcrumb = new BreadcrumbsViewModel
                {
                    BreadcrumbName = category.DisplayName,
                    BreadcrumbUrl  = UrlService.GetUrl(CatalogContext.CurrentCatalog, new[] { category })
                };
                lastCategory = category;
                breadcrumbs.Add(breadcrumb);
            }

            if (product != null)
            {
                var breadcrumb = new BreadcrumbsViewModel
                {
                    BreadcrumbName = product.DisplayName,
                    BreadcrumbUrl  = UrlService.GetUrl(CatalogContext.CurrentCatalog,
                                                       new[] { lastCategory }.Compact().ToArray(),
                                                       product)
                };
                breadcrumbs.Add(breadcrumb);
            }

            if (product == null && lastCategory == null)
            {
                var currentNode = CurrentPage;
                foreach (var level in currentNode.Ancestors().Where(IsVisible))
                {
                    var breadcrumb = new BreadcrumbsViewModel()
                    {
                        BreadcrumbName = level.Name,
                        BreadcrumbUrl  = level.Url
                    };
                    breadcrumbs.Add(breadcrumb);
                }

                var currentBreadcrumb = new BreadcrumbsViewModel()
                {
                    BreadcrumbName = currentNode.Name,
                    BreadcrumbUrl  = currentNode.Url
                };
                breadcrumbs.Add(currentBreadcrumb);
            }

            return(View("/Views/PartialView/Breadcrumbs.cshtml", breadcrumbs));
        }
        public virtual string GetProductUrl(Ucommerce.Search.Models.Category category,
                                            Ucommerce.Search.Models.Product product, bool openInSamePage, Guid detailPageId)
        {
            var baseUrl = string.Empty;

            if (openInSamePage)
            {
                baseUrl = UrlResolver.GetCurrentPageNodeUrl();
            }
            else
            {
                baseUrl = UrlResolver.GetPageNodeUrl(detailPageId);
            }

            string catUrl;
            var    productCategory = category?.Guid ?? product?.Categories.FirstOrDefault();

            if (productCategory == null)
            {
                catUrl = CategoryModel.DefaultCategoryName;
            }
            else
            {
                catUrl = CategoryModel.GetCategoryPath(CatalogLibrary.GetCategory(productCategory));
            }

            var    rawtUrl     = string.Format("{0}/p/{1}", catUrl, product.Slug);
            string relativeUrl = string.Concat(VirtualPathUtility.RemoveTrailingSlash(baseUrl), "/", rawtUrl);

            string url;

            if (SystemManager.CurrentHttpContext.Request.Url != null)
            {
                url = UrlPath.ResolveUrl(relativeUrl, true);
            }
            else
            {
                url = UrlResolver.GetAbsoluteUrl(relativeUrl);
            }

            return(url);
        }