Get Product URL from Guid, id or Code

Vote:
 

Hi, Im using 7.5 and need to get a Products URL by using it's GUID, ID or code or even name.

Is this at all possible?

 

Jon

#80249
Jan 17, 2014 14:21
Vote:
 

Hi

You would use the ReferenceConverter to get the ContentLink for your product. You could then use the CMS API:s to load the the product as content, and get the URL that way.

See the "Load a product" sample in this article, http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce/751/Content/Catalog-content-provider/.

Regards

Per Gunsarfs

#80251
Jan 17, 2014 14:58
Vote:
 

Hi,

EPiServer Commerce support a variable ways to get product url from its GUID, ID or code, but unfortunately not name - as many products can have "similar" name. 

- If you already have GUID, you can use IContentRepository and UrlResolver to get the product link

- If you already have an ID, you can follow instructions from Per above to get the product link

- If you have the code, it's a bit tricky, you we need to use ICatalogSystem.GetCatalogEntryDto to get the CatalogEntryDto, then the Id. In next releases we might add a new, more convinient way to get the id from the code.

- If you have the name, you can use search to get the exact code/id, as name is not required to be unique then there is no direct way to get the url.

Regards.

/Q

#80259
Jan 18, 2014 8:52
Vote:
 

To add to Quan's answer, there is acutally an overload of ReferenceConverter.GetContentLink which accepts the code, so no need to use the DTO:s directly in this case.

#80263
Jan 20, 2014 8:23