Product Adapters

Converting product sources into understandable products for Umbraco Commerce.

The role of a Product Adapter in Umbraco Commerce is to provide an interface between a product information source and convert it into a standardized format. This is done to prevent the need for Umbraco Commerce to be tied to that source.

What this means for developers is that Product Adapters allow you to hook in alternative product information sources that may not be Umbraco node-based. You may hold your product information in a third-party database table. A custom Product Adapter would then allow Umbraco Commerce to interface with that custom data in the same way it would the default Umbraco node data.

Example Product Adapter

An example of a Product Adapter would look something like this:

public class MyCustomProductAdapter : ProductAdapterBase
{
    public IProductSnapshot GetProductSnapshot(string productReference, string productVariantReference, string languageIsoCode)
    {
        // Lookup a product by productVariantReference and convert to IProductSnapshot
    }

    public bool TryGetProductReference(Guid storeId, string sku, out string productReference, out string productVariantReference)
    {
        // Try lookup a product / variant reference by store + sku
    }
}

All Product Adapters implement the ProductAdapterBase base class which requires two method implementations:

  • A GetProductSnapshot method that retrieves a Product Snapshot for either a product or a product variant by reference parameters.

  • A TryGetProductReference method which retrieves a product/variant reference for a product that belongs to a given storeId and has the given sku.

A Product Snapshot consists of the following properties in order to present a Product to Umbraco Commerce in a standard way.

Support editable carts

To allow Umbraco Commerce to search for products/variants to add to a cart via the backoffice, Product Adapters can implement 3 additional methods. This can also be done to support editable carts.

The IProductSummary, Attribute and IProductVariantSummary consists of the following properties in order to present a Product to Umbraco Commerce in a standard way.

Registering a Product Adapter

Product Adapters are registered via the IUmbracoCommerceBuilder interface using the AddUnique<IProductAdapter, TReplacementAdapter>() method on the Services property. The TReplacementAdapter parameter is the type of our custom Product Adapter implementation.

It is important that you register your product adapter via the IProductAdapter interface rather than the ProductAdapterBase class. If the IProductAdapter displays an obsolete warning, kindly ignore this. It is used to promote the use of the ProductAdapterBase base class.

Last updated

Was this helpful?