Page tree view is not visible when default language is set (Episerver cms mvc + commerce 1R3)

Vote:
 

Hi All,


we have developed custom Episerver mvc solution by integrating Episerver cms with commerce 1R3.
Initially we have developed CMS pages under , default language enabled is "en".But since eCommerce 1R3 is integrated we have enabled "en-US" language in the CMS (as ecommerce takes 4 letter language key).
After enabling "en-US"(english - united states). our "localsite" url stopped unless "en" word is appended at the end.
for example :
site name before enabling extra language : http://localhost:40000
after enabling we had to browse the site with http://localhost:40000/en

To make "en" as default language we added << language="en" >> attribute in episerverframework.config file  ( under siteHosts modified <add name="localhost:40000" /> tag to <add name="localhost:40000" language = "en"/>

then our problem solved all the urls are working as expected. But we got a new problem

- when we go to edit mode pagetree structure is not visible , as well as blocks are also not visible.

if we remove extra language "en-US" then while adding internal webpage link to "linkcollection property" on any page it open a pop up with error message "object reference not set to instance"
Detailed message :
{ NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.Business.Commerce.Providers.CatalogEntryPageRoute.OnVirtualPathCreated(Object sender, UrlBuilderEventArgs e)} ( so it needs extra language that is  to be enabled(which is used in ecommerce))

So how can i make page tree structure work in edit mode when multiple languages are enabled

please help me to resolve this issue.

Thanks in advance,
nani

#76728
Oct 31, 2013 16:47
Vote:
 

Hi, I think I have a solutiono for you.


First you should have the en-US or what ever language you have (the 4 letter language/languages) as your CMS site master language in the config file for the site, you shouldn't use the 'en' as master language.

Secondly you need to fix an issue that has already been solved by some nice person but I can't find the thread currently.

Below is the code we have used to get around the issue. You need an initialization module and a fixed CatalogEntryPageRoute. I suggest you have this in a separate project so you can easily remove the assembly from the bin when an official fix is release.

Initialization module:

using EPiServer.Business.Commerce;
using EPiServer.Business.Commerce.HttpModules;
using EPiServer.Business.Commerce.Providers;
using EPiServer.Framework;
using EPiServer.Web.Routing;
using log4net;
using Mediachase.Commerce.Engine.Navigation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Creuna.Commerce.EntryPageFix
{
	[ModuleDependency(typeof(InitializeCommerceManagerModule))]
	public class CommerceEntryPageFixInitialization : IInitializableModule
	{
		private static readonly ILog Logger = LogManager.GetLogger(typeof(CommerceEntryPageFixInitialization));

		private bool _isInitialized;

		public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
		{
			if (!this._isInitialized)
			{
				var entryViewUrl = UrlService.GetUrl(Constants.EntryViewCommandName);

				if (!string.IsNullOrEmpty(entryViewUrl) && !entryViewUrl.StartsWith("~"))
				{
					entryViewUrl = "~" + entryViewUrl;
				}

				var defaultRoute = new FixedCatalogEntryPageRoute("{seourl}.aspx", entryViewUrl);

				Type typeToRemove = typeof(CatalogEntryPageRoute);

				foreach (Delegate d in ContentRoute.CreatedVirtualPath.GetInvocationList())
				{
					// remove only the delegates that are a match to the faulting original implementation of CatalogEntryPageRoute.OnVirtualPathCreated
					if (typeToRemove.Equals(d.Target.GetType()) && string.Compare("OnVirtualPathCreated", d.Method.Name, StringComparison.OrdinalIgnoreCase) == 0)
					{
						ContentRoute.CreatedVirtualPath -= (EventHandler<UrlBuilderEventArgs>)d;

						CommerceEntryPageFixInitialization.Logger.Info(string.Format("Removing delegate, class '{0}' and method '{1}'.", d.Target.ToString(), d.Method.Name));
					}
				}

				ContentRoute.CreatedVirtualPath = (EventHandler<UrlBuilderEventArgs>)Delegate.Combine(ContentRoute.CreatedVirtualPath, new EventHandler<UrlBuilderEventArgs>(defaultRoute.OnVirtualPathCreated));

				this._isInitialized = true;
			}
		}

		public void Preload(string[] parameters)
		{
		}

		public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
		{
		}
	}
}

    And the fixed CatalogEntryPageRoute class

using EPiServer.Business.Commerce.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Creuna.Commerce.EntryPageFix
{
	/// <summary>
	/// Fixes the base implementation not handling null return value from VirtualPathUtility.RemoveTrailingSlash(e.UrlBuilder.Path) in the OnVirtualPathCreated method.
	///  If the result from the method is null nothing is done otherwise the base implementation is called.
	/// </summary>
	public class FixedCatalogEntryPageRoute : CatalogEntryPageRoute
    {
		public FixedCatalogEntryPageRoute(string url, string physicalFile) : base(url, physicalFile) { }

		public override void OnVirtualPathCreated(object sender, EPiServer.Web.Routing.UrlBuilderEventArgs e)
		{
			string vp = VirtualPathUtility.RemoveTrailingSlash(e.UrlBuilder.Path);

			if (!string.IsNullOrWhiteSpace(vp))
			{
				base.OnVirtualPathCreated(sender, e);
			}
		}
    }
}

    

#76844
Nov 04, 2013 18:01
Vote:
 

Hi @Antti Alasvuo , Thanks for solution. Sorry for late reply.

  • I did some work around for that issue , I enabled "en-AU" language in cms with out disabling "en",
  • Then I added "en-AU" in ecommerce manager >Administration>System settings>Dictionaries>Languages ,
  • I marked en-AU as "Default" language in ecommerce by setting "Is default" property enabled for en-AU and disabled for "en"
  • Then I set en-AU(English (Australia)) as default language in ecommerce manager >Administration>System settings>common settings >default language
  • Now I am able to browse site normally and page tree view is working fine in edit mode and link collection property is also working fine.

I will try your solution and let you know the result. once again thanks for sharing detailed code.


Thanks

nani

 

 

#77158
Nov 12, 2013 8:52
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.