product on multiple urls, with different content but coming from a single product node

Vote:
 

I am working on the episerver rebuild of a sitecore e-commerce website for a client and i am not sure how to recreate a particular piece of functionality they have. In their current site they can create a type of content node that works as a sort of wildcard for requests for product urls.

For instance, an editor could create a tree structure like this:

  • Home1
    • Shop
      • Product

And then any request to “home1/shop/*” will go to the controller for ‘Product’ (such as “home1/shop/productOne”, “home1/shop/productTwo”).

They also need to do the same for different sites within the same solution, so a simplified version of the content tree would be:

  • Home1
    • Shop
      • Product
    • Home2
      • Shop2
        • Product

So that any request to “home1/shop/*” and “home2/shop2/*” will go to the relevant controller. This means that both “home1/shop/productOne” and “home2/shop2/productOne” will return the product page but a url like “home2/shop3/productOne” will return a 404.

To be clear these two pages will show slightly different versions of the content for the product, so it is not just a case of a product being available in two different urls.

In addition this routing can’t be hard coded because it is based on the content type of the nodes. It must still be possible for an editor to create this in the content tree:

  • Home1
    • Shop
      • Product
    • Shop2
      • Product

and then for a request to “home1/shop2/*” to return the correct product details.

does anyone know how best to receate this in episerver?

#230092
Oct 29, 2020 17:04
Vote:
 

you can create this structure as follows

Multiple Home pages

1 Catalogue

Your purposed structure is like below

Home1

  • Shop (Starting node)
    • Product 1
  • Home2
    • Shop2 (starting node)
      • Product

If you create a property in Site Settings that just take Starting node against each home page

Product-1 can be in multiple categories (Shop & Shop2)

Now in the Commerce Initialization module, you can define how your commerce Urls rendered. You can specify like

{Home page}/{Starting Node}/

All products in starting nodes and sub-nodes will work and use your Product controller. 

#249292
Feb 26, 2021 17:13
Vote:
 

forgot to add a code snippet 

    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class InitializationModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {

            var referenceConverter = context.Locate.Advanced.GetInstance<Mediachase.Commerce.Catalog.ReferenceConverter>();
            var contentLoader = context.Locate.Advanced.GetInstance<IContentLoader>();

            var catalogs = contentLoader.GetChildren<CatalogContentBase>(referenceConverter.GetRootLink()).ToList();
            if (!catalogs.Any()) return;

            var siteDefinitionRepository = context.Locate.Advanced.GetInstance<ISiteDefinitionRepository>();
            var siteDefinitions = siteDefinitionRepository.List();
            foreach (var siteDefinition in siteDefinitions)
            {
// Get your node from catalogue based on site defination
                var catalogPartialRouter = new HierarchicalCatalogPartialRouter(() => siteDefinition.StartPage, your-desired-node, false);
                RouteTable.Routes.RegisterPartialRouter(catalogPartialRouter);
            }
        }
     public void Preload(string[] parameters) { }

        public void Uninitialize(InitializationEngine context)
        {
     
      }
    }
#249300
Feb 26, 2021 21:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.