Developer forum

Forum » Development » Product detail URL based on ProductNumber

Product detail URL based on ProductNumber

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I need to create a simple and stable way of accessing a ProductDetail page using the ProductNumber.

What would be the best way to achieve that? I don't want to affect the current friendlyUrls. they need to work in parallel.

Thank you,


Adrian


Replies

 
Martin Vang
Martin Vang
Reply

Hi Adrian,

How about making a search box for products that redirects to a details page if only 1 hit is found?

BR

Martin

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Martin.

This seems like a neat suggestion. I have never thought about it.

I will ask the customer if this works for them.

I might still need a suggestion for my initial approach as a Plan B.

Thank you very much for the fresh approach :)

Adrian

 
Nicolai Pedersen
Reply

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

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Understood. I believe I now have 2 very valid options for my problem.

Thank you both for the fast responses.

Adrian

 

You must be logged in to post in the forum