Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Philip Hayton 98 posts 435 karma points
    Feb 27, 2023 @ 12:48
    Philip Hayton
    0

    How to add a VirtualSubTree to Vendr Store

    Hi Matt,

    Do you have any sample code to show how to implement a VirtualSubTree for a Vendr store, like the one shown in this example?

    https://docs.getkonstrukt.net/advanced/virtual-sub-trees

    I'm trying to add it like this but I keep getting an Could not retreive Tree alias error.

        builder.WithSection(Vendr.Umbraco.Constants.Sections.Commerce)
            .WithTree(Vendr.Umbraco.Constants.Trees.Stores.Alias)
            .AddVirtualSubTree(ctx =>
            {
                if (!Guid.TryParse(ctx.Source.Id, out var id)) return false;
                var store = VendrApi.Instance.GetStores().SingleOrDefault(store => store.Id == id);
    
                return store is not null;
            })
            .SetAlias("testVirtualSubTree")
            .AddCollection<Asset>(x => x.Id, x => x.StoreId, "Asset", "Assets",
                "This is a description")
            .SetAlias("test")
            .SetNameProperty(x => x.InternalRef);
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Feb 27, 2023 @ 14:08
    Matt Brailsford
    0

    Hey Philip,

    Here's one that I created in a demo for a presentation. Hopefully this helps.

    builder.AddKonstrukt(k => k
        .WithSection("commerce", sectionConfig => sectionConfig
            .WithTree("vendr", treeConfig => treeConfig
    
                .AddVirtualSubTreeAfter(ctx => Guid.TryParse(ctx.Source.Id, out _), tn => tn.Name == "Analytics", virtualTreeConfig => virtualTreeConfig
                    .AddCollection<Notification>(x => x.Id, x => x.StoreId, "Notification", "Notifications", "A product notification", "icon-bell", "icon-bell", collectionConfig => collectionConfig
                        .SetNameFormat(p => p.Email)
                        .SetDateCreatedProperty(x => x.DateCreated)
                        .DisableCreate()
                        .AddDataView("Pending", x => x.Status == NotificationStatus.Pending)
                        .AddDataView("Notified", x => x.Status == NotificationStatus.Notified)
                        .AddAction<ChangeStatusAction>()
                        .AddAction<NotifyAction>()
                        .ListView(listViewConfig => listViewConfig
                            .AddField(x => x.ProductReference).SetHeading("Product").SetView<ProductNameFieldViewViewComponent>()
                            .AddField(x => x.Status)
                        )
                        .Editor(editorConfig => editorConfig
                            .AddTab("General", tabConfig => tabConfig
                                .Sidebar(sidebarConfig => sidebarConfig
                                    .AddFieldset("Info", fieldsetConfig => fieldsetConfig
                                        .AddField(p => p.DateCreated).MakeReadOnly()
                                    )
                                )
                                .AddFieldset("General", fieldsetConfig => fieldsetConfig
                                    .AddField(p => p.ProductReference).SetDataType("Product Picker").SetValueMapper<ProductPickerValueMapper>()
                                    .AddField(p => p.Email).SetValidationRegex("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+")
                                    .AddField(p => p.Status).SetDataType("Notification Status").SetValueMapper<EnumDropdownValueMapper<NotificationStatus>>()
                                )
                            )
                        )
                    )
                )
    
            )
        )
    );
    
  • Philip Hayton 98 posts 435 karma points
    Feb 27, 2023 @ 14:45
    Philip Hayton
    0

    Hi Matt,

    Thanks for the quick reply. Unfortunately that code produces the same error, it could possibly be a bug. I'll raise an issue on GitHub.

    Cheers

    Phil

Please Sign in or register to post replies

Write your reply to:

Draft