an abstract image of a grid adhering to waves with various spotlights of teal and purple

Sitecore MVC Testing Hotfix



Ben Golden
Ben Golden

Learn how to fix the A/B and MV testing bug in Sitecore 7.

A/B and MV testing don't work in Sitecore 7.x when using MVC. You will always see the original content, not the variations configured for your test. I logged this issue with the Sitecore support and they confirmed that it is a bug. This is an unofficial hotfix.

There is really only one line of code that needed changing, but because that line was in a pipeline processor that was inherited by another processor, both had to be fixed. The problem is in the Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering.SelectVariation class. The evaluate method tries to get the test variable item with this line of code:

Item variableItem = args.PageContext.Database.GetItem(renderingReference.Settings.MultiVariateTest);

However, renderingReference.Settings.MultiVariateTest is not a simple ID, it is actually a query string language names as keys and IDs as values. The variable item is always null as a result and the method aborts. This problem can be fixed by using the APIs from the core library:

Item variableItem = args.PageContext.Database.GetItem(renderingReference.Settings.GetMultiVariateTestForLanguage(Context.Language));

Please have a look at the code or download the package from my GitHub repository.

Let's Get Started

We'd love to hear from you. We probably have a lot in common. I mean, you like chatting about data-binding, UX patterns, and javascript functions, right?

X

Cookies help us improve your website experience. By using our website, you agree to our use of cookies and our privacy policy.

Accept