World is now on Opti ID! Learn more

How to restrict Catalog to one site

Vote:
 

We are running CMS 12 / Commerce 14 on the most recent versions(as of about a month ago).

We have multiple site hosted on our CMS. We also have a Catalog with products that should only be available for one of the sites. The catalog pages work and load correctly on the site they are meant to be viewed on. We do not link to any of the catalog pages from any site other than the main site. Somehow some search engines got links to load the catalog pages on a secondary site. The catalog page should not be loadable on this site and should give a 404. The secondary site does not give a 404, it tries to load the page. And as a results it results in an exception because the secondary site does not have all of the data/functionality in place that the catalog page needs. This is producing a lot of exceptions and potentially hurting the stability of our sites/instance.

Example

This works fine and loads as it should: 

This should not load, it should give a 404, but it tries to load and gives an exception:

 

How do i restrict the catalog to only be available for one site and not any of the others?

Thank you,

Calvin

 

#337688
Apr 02, 2025 13:49
Vote:
 

I haven't tried it, but in theory, you can implement your own HierarchicalCatalogPartialRouter, override GetCatalogContentRecursive, and check if CatalogContent is available in the current site, if not, return null which would result in a 404 

#337698
Apr 03, 2025 7:58
Vote:
 

I have a similar concept in a Commerce solution. Two shop brands in the same code base, each selling from their own catalog.

However, my solution also skips the catalog part from the URL. If you want to keep the catalog part of the URL, you can replace point 3 with Quan's suggestion.

This was my approach:

  1. Start page contains a content reference property to select a catalog. And a SelectOne property to select the market of the site.
  2. A custom MarketFilterAttribute, which I applied to all catalog content controllers. In the OnActionExecuting method I check whether IsAvailableInCurrentMarket is false. If it is, it return a NotFoundResult.
  3. A custom HierarchicalCatalogPartialRouter implementation overrides the CommerceRoot property to return the catalog based on the current start page. But you can also return null, if it does not match the catalog link (like Quan suggests).
#338334
May 19, 2025 5:45
* 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.