Glass.Mapper icon indicating copy to clipboard operation
Glass.Mapper copied to clipboard

ABTesting between two different versions of the same item doesn't work when using Glass.

Open batista16 opened this issue 4 years ago • 4 comments

Hi, After a lot of investigation, we've found out that when we use glass, we can't AB Test different versions of an item. We had a SC ticket for this and they've also provided other examples of other customers facing the same issue. https://community.sitecore.net/general/f/11/t/10773 They also said that were were other tickets with the same issue but they can't share them because they are private tickets.

That link explained it really well so I'll just use their explanation.

The scenario is,

Case 1: While using GlassMapper : I created 2 versions of an item and version test is created for the same item, web has both version (only for item that has an active test) while on front-end only latest version is visible when browsed from different browsers. For eg : Chrome renders –version2, edge renders –version 2

Case 2 : Without using GlassMapper : I created 2 versions of an item and version test is created for the same item, web has both version (only for item that has an active test) while on front-end both versions are visible when browsed from different browsers. For eg : Chrome renders –version2, edge renders –version 1.

So, apparently Glass always uses the latest version of the item in the web database, when in this specific case, it shouldn't.

In my case we're using SC 9.0.2 and GlassMapper 5.4.18

batista16 avatar Apr 17 '20 11:04 batista16

Have you seen #395 it does seem like a similar issue where you need to add properties for version and language.

markgibbons25 avatar May 06 '20 03:05 markgibbons25

Hi, sorry for the delay, I checked and I do have the version and language in there.

batista16 avatar May 14 '20 14:05 batista16

Can you give an example of the Glass model and code you used and the Sitecore equivalent code you tested against?

mikeedwards83 avatar May 15 '20 07:05 mikeedwards83

yes, in a view I have these 3 ways to get the field value:

                   <h1>Glass title</h1>
                    <h1>
                        @Html.Glass().Editable(Model.ContentPage, _ => _.Title)
                    </h1>
                    <h1>Sitecore title Sitecore.Context.Item.Fields["title"]</h1>
                    <h1>
                        @Sitecore.Context.Item.Fields["title"];
                    </h1>
                    <h1>Sitecore title Html.Sitecore().Field("title")</h1>
                    <h1>
                        @Html.Sitecore().Field("title")
                    </h1>

(only the last one works as it should)

This is the controller action:

[AllowAnonymous] public ActionResult PublicContentPage_ABTESTING() { Templates.IPublicContentPage contentPage = GetContext<Templates.IPublicContentPage>(); List<NavigationSectionModel> sectionList = buildNavigationSection(contentPage);

        var model = new ContentPageModel
        {
            ContentPage = contentPage,
            NavigationModel = new NavigationModel
            {
                Sections = sectionList
            },
            ContentPageRenderingParameters = GetRenderingParameters<Templates.IContentPageRenderingParameters>()
        };

        return View(model);
    }

This is the Templates.IPublicContentPage:

    [SitecoreType(TemplateId = "{4B0B5F4E-28C7-449A-9532-47215F29B81C}", AutoMap = true)]
    public interface IPublicContentPage : IContentPage { }


    [SitecoreType(TemplateId = "{DEF64426-D801-429E-AA3B-7A777B800874}", AutoMap = true)]
    public interface IContentPage : IBaseItem
    {
        [SitecoreField("Title")]
        string Title { get; set; }

        [SitecoreField("Subtitle")]
        string Subtitle { get; set; }

        [SitecoreField("Introduction")]
        string Introduction { get; set; }

        [SitecoreField("Page date")]
        DateTime PageDate { get; set; }

        [SitecoreField("Author")]
        IAuthor Author { get; set; }

        [SitecoreChildren(InferType = true)]
        IEnumerable<IContentPage> ChildPages { get; set; }            
        
        [SitecoreField("Content Thumbnail")]
        Image Thumbnail { get; set; }

        [SitecoreField("Category")]
        IContentSubcategory Category { get; set; }

        [SitecoreField("Navigation Folder")]
        INavigationFolder NavigationFolder { get; set; }
    }

public interface IBaseItem { [SitecoreId] ID Id { get; set; } string Url { get; set; }

  [SitecoreInfo(SitecoreInfoType.DisplayName)]
  string DisplayName { get; set; }

  [SitecoreInfo(SitecoreInfoType.Language)]
  Language Language { get; set; }

  [SitecoreInfo(SitecoreInfoType.Version)]
  int Version { get; set; }

}

The github markdown is showing weird formatting, I hope you can still understand what I'm pasting..

batista16 avatar Jun 26 '20 08:06 batista16