Assets and media in EpiServer Commerce 7.5

Asset management in Commerce

By default the new content-based asset management system with the blob provider model  is used for adding assets to the catalog nodes and entries when manging catalogs. All files are stored in the same location as the EPiServer CMS files, providing a more unified user experience.

In a Commerce installation, products and product variants from the product catalog can be accessed from the Catalogs gadget in the Assets pane, with general support for drag and drop of content items into CMS pages and blocks. The integration is done using content type classes EPiServer.Commerce.Catalog,

EPiServer.Commerce.Catalog.ContentTypes and EPiServer.Commerce.Catalog.Provider.
Configuration of asset management systemThe legacy Asset Management system for Commerce Manager is still available in EPiServer Commerce, but by default the new asset management system is configured to be used. A notification message with this information is displayed.
The configuration setting UseLegacyAssetSystem specifies the asset management system to be used, if set to “true” the legacy ECF asset system in Commerce Manager will be used. The setting is configured as follows in the web.config files of both the Commerce Manager and the front-end sites:
 <appSettings>
  <add key=”UseLegacyAssetSystem” value=”” />
  …
</appSettings>

VPP system in Episerver CMS 7.5

The VPP system is no longer used for storing editor generated content, which means that all CMS extensions to the VPP system are being phased out. The VPP API defined in EPiServer Framework will continue to be used for mapping in folders such as add-ons.
By default the new content-based asset management system with the blob provider model is used for adding assets to the catalog nodes and entries when manging catalogs. All files are stored in the same location as the EPiServer CMS files, providing a more unified user experience.

Blob Storage and Blob providers in Episerver CMS 7.5

BLOB (Binary Large Object) providers is a framework designed to store large amounts of binary data in a more optimized and cost-effective solution such as cloud storage, instead of in the database. The EPiServer platform supports BLOB storage of assets using a provider-based setup, and has a built-in file BLOB provider. You have the following options:
Built-in BLOB provider. EPiServer has a built-in BLOB provider for media files such as images, videos and documents. By default this provider will store files on local disc or a file share which will be defined during installation.
Customized BLOB provider. You can also develop and configure your own customized BLOB provider for your specific hosting environment. As an example, an Azure BLOB provider for EPiServer is available via Nuget.

A provider is responsible for storing a stream of data and associate it with a unique identifier. BLOBs are grouped into containers which is a logical name for a set of BLOBs, that for example can be deleted using a single API call. The unique identifier is exposed as an URI in the format epi.fx.blob://[provider]/[container]/[blob]] to make it easy to store a reference to a BLOB in for example a database.
Most methods in the API will always return a reference even though the actual BLOB does not exists, since it would be too costly to go out to a cloud service everytime, for example, a call to GetBlob is made, and it is assumed that the caller keeps track of BLOB identifiers.

Please Note we can’t use Unified File any more to find the physical locations of files, Science have been moved in BLOBFactory classes. There are few example helper functions that you may require in your projects regarding product images.

/// <summary>
/// Get absolute Path Of File
/// </summary>
/// <param name=”assetKey”></param>
/// <returns></returns>
public static string GetAbsolutePath(string assetKey)
{
var contentReference = PermanentLinkUtility.FindContentReference(new Guid(assetKey));
if (contentReference != null)
{
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var blobFactory = ServiceLocator.Current.GetInstance<BlobFactory>();
var fileID = new ContentReference(contentReference.ID);
//Get the file
var file = contentRepository.Get<MediaData>(fileID).BinaryData;
return file.ID.AbsolutePath;
}
return string.Empty;
}


private static string GetVirtualPath(string assetKey)
{
    var contentReference = PermanentLinkUtility.FindContentReference(new Guid(assetKey));
    return new UrlResolver().GetVirtualPath(contentReference, “en”);
}
public static string GetAssetUrl(Entry entry)
{
if (entry.Assets != null)
{
var assetKey = entry.Assets.OrderBy(a => a.SortOrder).FirstOrDefault().AssetKey;
return GetVirtualPath(assetKey);
}
return DefaultUrl;
}
public static string GetAssetUrl(CatalogNode node)
{
if (node.Assets != null)
{
var assetKey = node.Assets.OrderBy(a => a.SortOrder).FirstOrDefault().AssetKey;
return GetVirtualPath(assetKey);
}
return DefaultUrl;

}