Skip to content

Commerce: ProductAdapterBase Documentation out of date - provide a working example #7872

@cheeseytoastie

Description

@cheeseytoastie

Wrong documentation

What article/section is this about?

[(https://docs.umbraco.com/umbraco-commerce/key-concepts/product-adapters)]

Describe the issue

Would be useful to update the Product Adaptor docs so that a working example is provided that matches the correct methods and ideally with the expected return value examples (which I've done commented out - however my product service is not async (yet!). Had a few goes before my Product Adaptor would "take".

Something like:

namespace MyCustom.Code.Adaptors
{
    public class MyCustomProductAdapter : ProductAdapterBase
    {
        // Overload 1: product only (no variant) - might not actually be used anymore? Does this have to be here?
        public override async Task<IProductSnapshot> GetProductSnapshotAsync(Guid storeId, string productReference, string languageIsoCode, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();

            //var product = _productsService.GetProductByReference(productReference);
            //
            //if (product == null)
            //{
            //    _logger.LogWarning($"Product not found for store {storeId}, reference {productReference}");
            //    return null;
            //}
            //
            //return product;
        }

        // Overload 2: product + variant - note ensure you check for both a product with no variant and only a product variant?
        public override async Task<IProductSnapshot> GetProductSnapshotAsync(Guid storeId, string productReference, string productVariantReference, string languageIsoCode, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();

            //var product = !string.IsNullOrEmpty(productVariantReference) ? _productsService.GetProductByReference(productVariantReference) : _productsService.GetProductByReference(productReference);

            //if (product == null)
            //{
            //    _logger.LogWarning($"Product not found for store {storeId}, reference {productReference} {productVariantReference}");
            //    return null;
            //}


            //return product;
        }


        // Overload 3: Resolves a product/variant reference pair from a store ID + SKU.
        public override async Task<Attempt<(string ProductReference, string ProductVariantReference)>> TryGetProductReferenceAsync(Guid storeId, string sku, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();
            //try
            //{
            //    var product = _productsService.GetProductBySku(sku);

            //    if (product == null)
            //    {
            //        return Attempt<(string, string)>.Fail();
            //    }

            //    return Attempt<(string, string)>.Succeed((product.ProductReference, product.ProductVariantReference));
            //}
            //catch (Exception ex)
            //{
            //    _logger.LogError(ex, "Error resolving product reference for SKU {Sku}", sku);
            //    return Attempt<(string, string)>.Fail();
            //}
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions