Department and Product URL rewrite

Posted by Community Admin on 03-Aug-2018 15:08

Department and Product URL rewrite

All Replies

Posted by Community Admin on 14-Jul-2015 00:00

I've created some ecommerce products and I would liek to display them as normal pages (with the future option of turning them into ecommerce pages). For this I have the following page structure

Products (widgets: Departments, Product List)
- Product Detail (widgets: Product List - Single Item)

As part of this requirement I would like specific URLs for the departments and products.

For the department URL I would like the following

www.domain.com/.../

I have the following URL rewrite to handle this scenario

<rule name="Product Explorer Department Rewrite" stopProcessing="true">
    <match url="^products/([^$]+)" />
    <conditions>
        <add input="URL" negate="true" pattern="action/edit" />
    </conditions>
    <action type="Rewrite" url="products/-in-department/departments/R:1" />
</rule>

For the product URL I would like the following

www.domain.com/.../product-name

Not sure how to approach this one.

I would also like these URLs to appear in any search results in the required format.

Thanks in advance for any ideas about how any of the above can be achieved.

Posted by Community Admin on 17-Jul-2015 00:00

Hello Sean,

I think you will find useful the following blog post where we provide more details about the custom url formats:

Custom URL Formats for Sitefinity Content Modules

The approach should be the same for the Products. In the Advanced settings, the module is called Catalog, there you will find the provider.

Here is also a sample which is based on the above blog post which you may find useful. The sample demonstrates how to achieve this by creating a custom provider for CatalogsModule (managing products). Please follow the below steps to register one:

1.Create a class inheriting OpenAccessCatalogDataprovider and override the GetUrlFormat like below, for the UrlFormat use the names of the fields available for products surrounded by square braces "[..]", this is how the url will be constructed:

using Telerik.Sitefinity.Ecommerce.Catalog.Model;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Ecommerce.Catalog.Data;
  
namespace SitefinityWebApp
    public class CustomOpenAccessCatalogDataProvider : OpenAccessCatalogDataProvider
    
        public override string GetUrlFormat(ILocatable item)
        
            Type itemType = item.GetType();
            if (typeof(Product).IsAssignableFrom(itemType))
            
                //the url format is controlled here
                return "/[Price]/[UrlName]";
            
            return base.GetUrlFormat(item);
        
  
    

2. Go to Administration->Settings->Advanced->Catalog->Providers and delete the currently existing provider.

3. Crete new provider with the below settings:

Name: OpenAccessDataProvider
Title: Default Ecommerce products
Description: The data provider for catalog module based on the Telerik OpenAccess ORM.
ProviderType: SitefinityWebApp.CustomOpenAccessCatalogDataProvider, SitefinityWebApp (change the type here to match the namespace of the project you work on).

Please save the changes.

4. Go to Parameters for this new provider and add new parameter:
Key: applicationName
Value: /Catalog

Please save the changes and after performing the above the products will use the new provider url format.
Please note all products need to be republished to use the new provider settings.

This will change the url for all products as well as the urls shown in search results.

Please note to test the above sample on a backup of your project and database.

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed