Ejemplo n.º 1
0
        public virtual string GetProductUrl(GetProductUrlParam parameters)
        {
            Assert(parameters);

            var productName = string.IsNullOrWhiteSpace(parameters.ProductName)
                ? parameters.ProductId
                : parameters.ProductName;
            var formattedProductName = UrlFormatter.FormatProductName(productName);

            var httpContext = !string.IsNullOrEmpty(parameters.BaseUrl) ? new HttpContext(
                new HttpRequest(string.Empty, parameters.BaseUrl, string.Empty),
                new HttpResponse(new StringWriter())
                ) : null;

            var homeUrl = PageService.GetPageUrl(WebsiteContext.WebsiteId, parameters.CultureInfo, httpContext)?.Trim('/');

            string productPath = "";

            if (!string.IsNullOrWhiteSpace(homeUrl))
            {
                productPath += $"/{homeUrl}";
            }

            productPath += $"/p-{formattedProductName}/{parameters.ProductId}";

            if (!string.IsNullOrWhiteSpace(parameters.VariantId))
            {
                productPath += $"/{parameters.VariantId}";
            }

            var uri = new Uri(productPath, UriKind.Relative);

            return(uri.ToString());
        }
        public string GetProductUrl(GetProductUrlParam parameters)
        {
            if (parameters is WebsiteGetProductUrlParam websitesParameters)
            {
                var provider = new ProductUrlProvider(PageService,
                                                      new Sitemap.WebsiteContextWrapper(websitesParameters.WebsiteId), SiteConfiguration);
                return(provider.GetProductUrl(parameters));
            }

            return(null);
        }
Ejemplo n.º 3
0
        protected virtual string GetProductUrl(Uri baseUrl, CultureInfo cultureInfo, string productId, string variantId, string productName, string sku)
        {
            var param = new GetProductUrlParam
            {
                CultureInfo = cultureInfo,
                ProductId   = productId,
                VariantId   = variantId,
                ProductName = productName,
                SKU         = sku
            };

            return(ProductUrlProvider.GetProductUrl(param));
        }
Ejemplo n.º 4
0
 private void Assert(GetProductUrlParam parameters)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException(nameof(parameters));
     }
     if (string.IsNullOrWhiteSpace(parameters.ProductId))
     {
         throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("ProductId"), nameof(parameters));
     }
     if (parameters.CultureInfo == null)
     {
         throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), nameof(parameters));
     }
 }