public string CategoryUrlUsingCurrentPath(ICategory category, ILocalization localization) { var path = GetLocalizedCurrentPath(localization); category = _categoryService.Localize(category, localization); if (path != null && !category.ParentCategories.Contains(path.LastOrDefault())) { path = null; } string url; if (path != null && path.Any()) { path = path.Concat(new[] { category }); url = _categoryCatalogUrlService.GetUrlForPath(path); } else { url = _categoryCatalogUrlService.GetCanonicalUrl(category); } return(_urlFormatService.FormatUrl(_urlLocalizationService.LocalizeCatalogUrl(url, localization))); }
public string GetUrlUsingCategoryPathOrCanonical(IProduct product, IEnumerable <ICategory> categoryPath) { var category = categoryPath.LastOrDefault(); if (category != null && product.Categories.Any(c => c.Id == category.Id)) { return(_categoryCatalogUrlService.GetUrlForPath(categoryPath) + "/" + product.UrlName); } category = product.Categories.FirstOrDefault(); // todo: products can get their own url using storeUrl/productUrlName, but resolving and name conflicts need to be fixed if (category == null) { return(product.UrlName); } return(_categoryCatalogUrlService.GetCanonicalUrl(category) + "/" + product.UrlName); }