Try our conversational search powered by Generative AI!

Commerce Catalog UI not showing properties when using batch api

Vote:
 

I am seeing some unexpected behavior when using the content batch api. I have prepared some sample code to explain what I’m doing and the results I’m getting:

[ScheduledPlugIn(DisplayName = "Create sample product", SortIndex = 10000)]
public class CreateSampleProduct : ScheduledJobBase
{
    public Injected<IContentRepository> ContentRepository;
    public Injected<ReferenceConverter> ReferenceConverter;

    public override string Execute()
    {
        var rootLink = ReferenceConverter.Service.GetRootLink();
        var catalog = ContentRepository
            .Service
            .GetChildren<CatalogContent>(rootLink)
            .First();

        var productContentLink = ReferenceConverter.Service.GetContentLink("sample_product");
        WebProduct product;

        if (ContentReference.IsNullOrEmpty(productContentLink))
        {
            product = ContentRepository.Service.GetDefault<WebProduct>(catalog.ContentLink);
            product.Code = "sample_product";
        }
        else
        {
            product = ContentRepository.Service.Get<WebProduct>(productContentLink);
            product = (WebProduct) product.CreateWritableClone();
        }

        product.Name = "Sample product";
        product.DisplayName = "Sample product";
        product.IsPendingPublish = false;
        product.StopPublish = DateTime.Today.AddYears(10);

        var useBatchApi = true;

        if (useBatchApi)
        {
            var products = new List<CatalogContentBase> { product };
            ContentRepository.Service.Publish(products, PublishAction.SyncDraft);
        }
        else
        {
            ContentRepository.Service.Save(product, SaveAction.Publish, AccessLevel.NoAccess);
        }
        
        return string.Empty;
    }
}

I’m using the debugger to test different combinations of the batch api and the standard api.

The problem is that the content api and the commerce catalog ui doesn’t seem to be in sync. If I create a new product through the batch api it’s missing properties such as display name in the commerce catalog ui. I’ve run different tests, but here’s a test sequence that shows the problem:

  1. Create through batch api -> display name not set
  2. Update through batch api -> display name still not set
  3. Update through standard api -> display name is now set
  4. Update through batch api -> display name updated 

It looks like something happens when the product is created or updated through the standard api. All subsequent calls to the batch api work as expected. If I don’t create/update the product through the standard api the display name never gets set. I have restarted several times to get around potential caching and I’m still getting the same results.

Am I doing something wrong?

Thanks

#264105
Sep 29, 2021 11:43
Vote:
 

Hello @Daniel Lindberg

You are right. There seems to be miss. Any update or publish we make using standard API, it usually updates the data in two tables CatalogContentProperty and ecfVersionProperty. In the case of batch API because it does not add a new version, it never updated the version table and as a result we dont see the data for DisplayName accurately.

Hello @Quan Mai Please confirm if there is any workaround to trigger the change accurately? 

NOTE: Quan, Mentioning your name as I had seen the feature on your blog https://world.optimizely.com/blogs/Quan-Mai/Dates/2019/10/new-simple-batch-saving-api-for-commerce/

~ Sujit

#264206
Edited, Sep 30, 2021 2:09
Vote:
 

@Daniel Linberg: I previously reported 2 bugs related to batch api, one of them: https://world.optimizely.com/support/bug-list/bug/COM-10634

I've tried using api a couple of times in different versions, but I have seen same issue arise with values not reflected in catalog UI.

#264219
Sep 30, 2021 14:38
Sujit Senapati - Sep 30, 2021 14:43
Thanks @Mari for sharing the defect. It says it is already resolved in 13.16. But it still seems to be an issue. Would you know how to reopen the bug?
Vote:
 

Update: I just ran a new test in commerce 13.28 - and it seems both issues are resolved, COM-10634 and COM-10609.

Changes on existing items are reflected in UI and I don't get errors creating new products.

#264221
Sep 30, 2021 15:50
Vote:
 

@Mari Jørgensen I'm getting this error on commerce 13.31.1, so maybe there are some other packages and/or configuration at play.

#264269
Oct 01, 2021 8:14
Vote:
 

It should work, for both creating and updating catalog contents. IIRC (yes I wrote those code, but it has been 2 years now), if the content is new (i.e. being created), it will fall back to the normal content creation path. I can ask the QAs to look into this however.

#264275
Oct 01, 2021 12:59
Sujit Senapati - Oct 01, 2021 16:56
Hi @Quan, I just tested on Commerce UI 13.30.0 and it is still an issue. Please note the display name properly reflects in product listing view, but not in All properties view of the product, that is usually retrieved from ecfVersionProperty table, which I dont see being updated when we publish using batch API.
Vote:
 

QAs looked into this, and it looks like you will need this setting (you are probably setting it to true)

<add key="DisableVersionSync" value="false" /> 

#264395
Oct 04, 2021 8:49
Sujit Senapati - Oct 04, 2021 20:11
Thanks @Quan! That did the trick. Thanks for sharing!

@Daniel Lindberg, please confirm if that resolves it for you.
Vote:
 

It didn't work for me. I'm still getting the same result. I didn't have DisableVersionSync in my config at all, but I added it just to be sure that it didn't default to "true". I also injected IApplicationContext to verify that IApplicationContext.DisableVersionSync was false when running.

#264502
Oct 05, 2021 8:32
Vote:
 

If you just use the normal non batch API to create a new content, does it work for you?

#264504
Oct 05, 2021 12:25
Vote:
 

Yes it works. And as soon as I create or update a product through the standard API the batch API seems to work too. It can be verified through my sample code above. And through this set of steps:

  1. Create through batch api -> display name not set
  2. Update through batch api -> display name still not set
  3. Update through standard api -> display name is now set
  4. Update through batch api -> display name updated 
#264505
Oct 05, 2021 12:42
Vote:
 

When I tested create through the batch api, I could see that item was not published (just created) - could the publish state be a factor?

#264506
Oct 05, 2021 12:44
Daniel Lindberg - Oct 05, 2021 12:48
Did you set these flags in your test?:
product.IsPendingPublish = false;
product.StopPublish = DateTime.Today.AddYears(10);
My test product wasn't published until I did, but I was missing the display name regardless of the publishing status
Vote:
 

We have still not found any solution to this, any idea @Quan Mai ?

#267384
Nov 25, 2021 13:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.