Class ReferenceConverter
Converts between catalog object ID:s and types and EPiServer.Core.ContentReferences.
Inheritance
Inherited Members
Namespace: Mediachase.Commerce.Catalog
Assembly: Mediachase.Commerce.dll
Version: 13.30.0Syntax
public class ReferenceConverter
Constructors
ReferenceConverter(EntryIdentityResolver, NodeIdentityResolver)
Initializes a new instance of the ReferenceConverter class.
Declaration
public ReferenceConverter(EntryIdentityResolver entryIdentityResolver, NodeIdentityResolver nodeIdentityResolver)
Parameters
Type | Name | Description |
---|---|---|
EntryIdentityResolver | entryIdentityResolver | The Entry identity resolver. |
NodeIdentityResolver | nodeIdentityResolver | The Node identity resolver. |
Fields
CatalogProviderKey
Default key of the CatalogContentProvider, used in the automatic registration of the content provider and in in creating EPiServer.Core.ContentReferences to catalog content in it.
Declaration
public const string CatalogProviderKey = "CatalogContent"
Field Value
Type | Description |
---|---|
System.String |
Methods
GetCode(ContentReference)
Gets the code for an entry/node EPiServer.Core.ContentReference.
Declaration
public virtual string GetCode(ContentReference contentLink)
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Core.ContentReference | contentLink | The content link. |
Returns
Type | Description |
---|---|
System.String | The code, or null if the |
Remarks
Codes used on specific versions of content are not taken into account, i.e. only the code which the node/entry was last published (or created) with will be a match.
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if |
GetCodes(IEnumerable<ContentReference>, CatalogContentType)
Gets list of code for the entries or nodes with the specified list of EPiServer.Core.ContentReference.
Declaration
public virtual IDictionary<ContentReference, string> GetCodes(IEnumerable<ContentReference> contentLinks, CatalogContentType catalogContentType)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<EPiServer.Core.ContentReference> | contentLinks | The content links. |
CatalogContentType | catalogContentType | The catalog content type. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<EPiServer.Core.ContentReference, System.String> | The dictionary maps between the EPiServer.Core.ContentReference(s) and the codes. |
GetCodes(IEnumerable<Guid>)
Gets the entry codes from the content guids
Declaration
public virtual IEnumerable<string> GetCodes(IEnumerable<Guid> contentGuids)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Guid> | contentGuids | The content guids. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> | The entry codes, or empty list. |
GetContentLink(Int32, CatalogContentType, Int32)
Gets a EPiServer.Core.ContentReference instance with the specified commerce object ID and type encoded in the content ID.
Declaration
public virtual ContentReference GetContentLink(int objectId, CatalogContentType contentType, int versionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | objectId | The ID of the commerce object. |
CatalogContentType | contentType | Type of the commerce object. |
System.Int32 | versionId | The version ID to set in the EPiServer.Core.ContentReference instance. |
Returns
Type | Description |
---|---|
EPiServer.Core.ContentReference | The content link. |
Remarks
The content ID will contain the content type information in two most significant bits.
GetContentLink(String)
Gets a EPiServer.Core.ContentReference for the entry or node with the specified code.
Declaration
public virtual ContentReference GetContentLink(string code)
Parameters
Type | Name | Description |
---|---|---|
System.String | code | The code. |
Returns
Type | Description |
---|---|
EPiServer.Core.ContentReference | The content link. |
GetContentLink(String, CatalogContentType)
Gets a EPiServer.Core.ContentReference for the content with the specified code and type.
Declaration
public virtual ContentReference GetContentLink(string code, CatalogContentType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | code | The code. |
CatalogContentType | type | The type of content (entry or node) which has the code. |
Returns
Type | Description |
---|---|
EPiServer.Core.ContentReference | The content link. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if a type other than entry or node is specified. |
GetContentLinks(IEnumerable<String>)
Gets list of EPiServer.Core.ContentReference for the contents with the specified codes
Declaration
public virtual IDictionary<string, ContentReference> GetContentLinks(IEnumerable<string> codes)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | codes | The list of catalog content code. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, EPiServer.Core.ContentReference> | The list of content link. |
GetContentLinks(IEnumerable<String>, CatalogContentType)
Gets list of EPiServer.Core.ContentReference for the contents with the specified codes and type.
Declaration
public virtual IDictionary<string, ContentReference> GetContentLinks(IEnumerable<string> codes, CatalogContentType type)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | codes | The list of catalog content code. |
CatalogContentType | type | The type of content (entry or node) which has the code. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, EPiServer.Core.ContentReference> | The list of content link. |
GetContentType(ContentReference)
Gets the type of the commerce object. Parse the content ID to take two most significant bits to determine CatalogContentType.
Declaration
public virtual CatalogContentType GetContentType(ContentReference contentLink)
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Core.ContentReference | contentLink | The content link. |
Returns
Type | Description |
---|---|
CatalogContentType | The type of commerce object. |
Examples
public void ConversionEntryContentLink(EntryContentBase entryContent)
{
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
// Convert from ContentReference to catalog entry id
var entryId = referenceConverter.GetObjectId(entryContent.ContentLink);
// Convert from catalog entry id to ContentReference
var entryContentLink = referenceConverter.GetEntryContentLink(entryId);
// or with version id
var sameEntryContentLink = referenceConverter.GetEntryContentLink(entryId, 0);
}
public void ConversionNodeContentLink(NodeContent nodeContent)
{
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
// Convert from ContentReference to catalog node id
var nodeId = referenceConverter.GetObjectId(nodeContent.ContentLink);
// Convert from catalog node id to ContentReference
var nodeContentLink = referenceConverter.GetNodeContentLink(nodeId);
// or with version id
var sameNodeContentLink = referenceConverter.GetNodeContentLink(nodeId, 0);
}
GetObjectId(ContentReference)
Gets the actual id of commerce object.
Declaration
public virtual int GetObjectId(ContentReference contentLink)
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Core.ContentReference | contentLink | The content link. |
Returns
Type | Description |
---|---|
System.Int32 | The ID of the commerce object. |
Remarks
Clears the two most significant bits (for CatalogContentType) of the content ID.
Examples
public void ConversionEntryContentLink(EntryContentBase entryContent)
{
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
// Convert from ContentReference to catalog entry id
var entryId = referenceConverter.GetObjectId(entryContent.ContentLink);
// Convert from catalog entry id to ContentReference
var entryContentLink = referenceConverter.GetEntryContentLink(entryId);
// or with version id
var sameEntryContentLink = referenceConverter.GetEntryContentLink(entryId, 0);
}
public void ConversionNodeContentLink(NodeContent nodeContent)
{
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
// Convert from ContentReference to catalog node id
var nodeId = referenceConverter.GetObjectId(nodeContent.ContentLink);
// Convert from catalog node id to ContentReference
var nodeContentLink = referenceConverter.GetNodeContentLink(nodeId);
// or with version id
var sameNodeContentLink = referenceConverter.GetNodeContentLink(nodeId, 0);
}
GetRootLink()
Returns the EPiServer.Core.ContentReference to the root content of the CatalogContentProvider.
Declaration
public virtual ContentReference GetRootLink()
Returns
Type | Description |
---|---|
EPiServer.Core.ContentReference | The root link. |