Posted on 11/03/2021 10:41:43
You can do a url provider:
using System.Collections.Generic;
using System.ComponentModel;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Frontend.UrlProviders;
using License = Dynamicweb.Security.UserManagement.License;
namespace Dynamicweb.Ecommerce.Frontend.UrlProviders
{
/// <summary>
/// Represents the eCommerce products provider.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
[AddInName("Ecommerce products by product number")]
[AddInDescription("Generates urls for Ecommerce products in the format /product-number")]
[AddInActive(true)]
[AddInGroup("Ecommerce products")]
[AddInTarget("eCom_Catalog")]
[AddInOrder(6)]
public class ProductProvider : UrlProvider
{
/// <summary>
/// Gets the mappings.
/// </summary>
/// <returns>The mappings.</returns>
public override List<Mapping> GetMappings()
{
var result = new List<Mapping>();
foreach (var language in Services.Languages.GetLanguages())
{
foreach (var product in Services.Products.GetAllProducts(language.LanguageId, false))
{
if (!string.IsNullOrEmpty(product.Number))
{
//result.Add(new Mapping("ProductID", product.Id, product.Number, language.LanguageId));
result.Add(new Mapping("ProductNumber", product.Number, product.Number, language.LanguageId));
}
}
}
return result;
}
}
}
Then it has to be activated in url settings.
The above will make it possible for you to do this:
URL /products/sku123 - which will be rewritten to: /Default.aspx?ID=123&ProductNumber=sku123
Then you need something on the products page that will take the ProductNumber parameter, use it on a search, and then redirect to the product.
The line that is commented out, will make it possible for you to do this
URL /products/sku123 - which will be rewritten to: /Default.aspx?ID=123&ProductID=Prod123
So no redirects or additional implementation needed. But it might cause other issues since you now have both /productname and /productnumber pointing to the same URL.
BR Nicolai