Quantcast
Channel: Customized Commerce 13 and earlier versions
Viewing all articles
Browse latest Browse all 9642

CustomContentLoaderService disables variants from being returned from content delivery api

$
0
0

Hi all,

We have created an enhanced content loader service that enables draft content to be returned from the content delivery api. The enhanced content loader is working fine as expected. However, we noticed that when we inject the service to be used in our project it breaks the ability for variants to be retrieved from the commerce side of things using /children by only recieving an empty array as a response. Ex request url:

https://localhost:5000/catalog/category/product/children

We used this link as a reference to build our service:
https://docs.developers.optimizely.com/content-management-system/v1.5.0-content-delivery-api/docs/customizing-content-delivery-api-for-edit-view#return-draft-and-expired-content

here is the code for our enhanced content loader service:

public class EnhancedContentLoaderService(
    IContentLoader contentLoader,
    IHttpContextAccessor httpContextAccessor,
    IPublishedStateAssessor publishedStateAssessor,
    IPermanentLinkMapper permanentLinkMapper,
    IContentProviderManager providerManager
        ) : ContentLoaderService(
            contentLoader,
            permanentLinkMapper,
            providerManager,
            publishedStateAssessor)
{
    protected override bool ShouldContentBeExposed(IContent content)
    {
        // In EditMode, unpublished or expired content is still returned
        return GetContextMode() == ContextMode.Edit || base.ShouldContentBeExposed(content);
    }
    private ContextMode GetContextMode()
    {
        var httpCtx = httpContextAccessor.HttpContext;
        if (httpCtx?.Request is null || !httpCtx.Request.Query.ContainsKey(PageEditing.EpiEditMode))
        {
            return ContextMode.Default;
        }
        if (bool.TryParse(httpCtx.Request.Query[PageEditing.EpiEditMode], out var editMode))
        {
            return editMode ? ContextMode.Edit : ContextMode.Preview;
        }
        return ContextMode.Undefined;
    }
}

The service is being injected like this:

        context.ConfigurationComplete += (o, e) =>
        {
            context.Services.AddSingleton<ContentLoaderService, EnhancedContentLoaderService>();
        };


Any ideas on what could be the issue?
Thanks in advance


Viewing all articles
Browse latest Browse all 9642

Trending Articles