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?
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/.
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.
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.