Share

LinkedIn

Sitecore MVC Testing Hotfix

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.

Sitecore development, Sitecore custom code, Sitecore MVC

Comments

Add a Comment

*
*

Please confirm you are human by typing the text you see in this image: