November Happy Hour will be moved to Thursday December 5th.

Custom CatalogContentProvider has issues with Node to parent assignment

Vote:
 

Hello,

Based on the code found on the Optimizely support website regarding external CatalogContentProvider I started a small proof-of-concept in order to implement a small custom external CatalogContentProvider. To be sure that I'm not loosing time with deep things, I started very easy with service a generated product category (custom NodeContent class) through my CatalogContentProvider.

The issue that I'm having at this moment is just about the placemanent of the given category in the tree because my custom category appears everywhere:

What do you see in this picture is this:

a) "Primul catalog" and "Al doilea catalog" - they are catalogs created in the interface.

b) "XXX" and "YYY" are categories created in the interface.

c) "Database category 1" is the category that I'm generating in code and I'm serving through the external CatalogContentProvider.

First of all, this is the code that generates this category:

        protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
        {
            // Get the mapped identity, the mapped identity has an external identifier from which we determine the properties.
            MappedIdentity identity = this.identityMappingService.Get(contentLink);

            // Use the identity service to determine the type and identifiers of the requested item.
            NameValueCollection metaData = this.identityService.ParseExternalIdentifier(identity.ExternalIdentifier);

            //// Get the catalog id from the provider name.
            //int catalogNodeId = this.identityService.ParseCatalogNodeIdFromProviderName(contentLink.ProviderName);

            // Construct the catalog content reference from the extracted values.
            //ContentReference catalogContentReference =
            //    ContentReference.Parse($"{catalogNodeId}__{CatalogProvidersConstants.CatalogContentProviderKey}");

            // Get the current catalog node.
            // CatalogContent currentCatalogContent = this.contentLoader.Get<CatalogContent>(catalogContentReference);

            var type = metaData[PatternKeysConstants.Type];

            ContentReference parentContentReference =
                new ContentReference(-2147483647, "CatalogContent");

            ContentReference parentRef = new ContentReference(1, CatalogProvidersConstants.CatalogContentProviderKey);

            List<CultureInfo> existingLanguages = new List<CultureInfo> { new CultureInfo("en") };
            
            StandardNodeModel node = this.contentRepository.GetDefault<StandardNodeModel>(parentContentReference);
            node.ExistingLanguages = existingLanguages;
            node.Language = new CultureInfo("en");
            node.MasterLanguage = new CultureInfo("en");
            node.Name = "Database category 1";
            node.DisplayName = "Database category 1";
            node.RouteSegment = this.segmentGenerator.Create("database category 1", new UrlSegmentOptions());
            //node.SeoUri = "123";
            node.ContentLink = identity.ContentLink;
            node.ContentGuid = identity.ContentGuid;

            node.IsDeleted = false;
            node.IsModified = false;
            node.IsPendingPublish = false;
            node.Status = VersionStatus.Published;
            node.CatalogId = 1;
            node.Code = "DB-CAT-1";
            node.ParentLink = parentContentReference;
            //node.Property.Add("Code", new PropertyString(node.Code));
            //node.Property.Add("CatalogId", new PropertyNumber(2));
            //node.ParentLink = parentContentReference;
            node.StartPublish = DateTime.Now.AddYears(-1);
            node.StopPublish = DateTime.Now.AddYears(1);
            
            MetaClassCollection metaClassCollection = MetaClass.GetList(MetaDataContext.Instance);
            MetaClass metaClassInfo = metaClassCollection["StandardNodeModel"];

            node.MetaClassId = metaClassInfo.Id;

            node.MakeReadOnly();

            return node;
        }

Then, according to the documentation previously mentioned, I need to implement a custom IRelationRepository class and also register it in the DI and intercept all calls to the default one and exchange it with my custom one - I did it and the registration is succesful but the most important method GetChildren is not getting called at all.

Can you please tell me if you have any idea why do I see my custom product category all over the place in the tree?

I'm using Episerver.Commerce 14.11.0.

Thank you,

Evdin

#302228
May 23, 2023 14:07
* 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.