title: Very Close but not quite able to override core view nopcommerce
body: <p>I have been reading some very good post from <a href="https://stackoverflow.com/users/342067/wooncherk">Wooncherk</a>, <a href="https://stackoverflow.com/users/439535/twisted-whisper">Twisted Whisperer</a>, and <a href="https://stackoverflow.com/users/3194536/alex-wolf">Alex Wolf</a>. Their articles respectively <a href="http://www.pronopcommerce.com/3-ways-to-display-views-in-your-nopcommerce-plugins-embedded-resource-theme-override-and-custom-view-engine" rel="nofollow noreferrer">(Wooncherk)</a>, <a href="https://stackoverflow.com/questions/17321898/how-to-override-a-nopcommerce-view-file-with-a-view-file-inside-the-plugin/25482308#25482308">(Twisted Whisperer)</a>, and <a href="http://alexwolfthoughts.com/overriding-views-in-a-nopcommerce-plugin" rel="nofollow noreferrer">(Alex Wolf)</a> have been extremely informative but alas I'm just not as smart as the rest of the SO community and can't quite piece together what I'm missing. </p>
  
  <p>I am overriding a core view in the admin area...specifically the order edit view. The behavior I am seeing is that it does <strong>NOT</strong> hit the controller in my plugin but it <strong>DOES</strong> display my custom view. Problem is that the custom view is in the Admin project and this really confuses me. How can I have a self-contained plugin yet have to install my custom view into the core Admin area?</p>
  
  <p>I thought, perhaps incorrectly, that what would happen is that my controller would be hit first when paths are being searched because of my higher defined priority.</p>
  
  <p>So following the directions here is my code.</p>
  
  <p><strong>CustomViewEngine:</strong></p>
  
  <hr>
  
  <pre><code>private readonly string[] _emptyLocations = null;
  
      public CustomViewEngine()
      {
          PartialViewLocationFormats = new[]
          {
              "~/Administration/MyExtension/Views/{1}/{0}.cshtml",
              "~/Administration/MyExtension/Views/Shared/{0}.cshtml"
          };
  
          ViewLocationFormats = new[]
          {
              "~/Administration/MyExtension/Views/{1}/{0}.cshtml",
              "~/Administration/MyExtension/Views/Shared/{0}.cshtml"
          };
      }
  
  
      protected override string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string theme, string cacheKeyPrefix, bool useCache, out string[] searchedLocations) 
      {
          searchedLocations = _emptyLocations;
          if (string.IsNullOrEmpty(name)) 
          {
              return string.Empty;
          }
  
          string areaName = GetAreaName(controllerContext.RouteData);
  
          //little hack to get nop's admin area to be in /Administration/ instead of /Nop/Admin/ or Areas/Admin/
          if (!string.IsNullOrEmpty(areaName) &amp;&amp; areaName.Equals("admin", StringComparison.InvariantCultureIgnoreCase)) 
          {
              var newLocations = areaLocations.ToList();
              newLocations.Insert(0, "~/Administration/Views/{1}/{0}.cshtml");
              newLocations.Insert(0, "~/Administration/Views/Shared/{0}.cshtml");
  
              //Insert your custom View locations to the top of the list to be given a higher precedence
              newLocations.Insert(0, "~/Administration/MyExtension/Views/{1}/{0}.cshtml");
              newLocations.Insert(0, "~/Administration/MyExtension/Views/Shared/{0}.cshtml");
  
              areaLocations = newLocations.ToArray();
          }
  
          bool flag = !string.IsNullOrEmpty(areaName);
          List&lt;ViewLocation&gt; viewLocations = GetViewLocations(locations, flag ? areaLocations : null);
  
          if (viewLocations.Count == 0) 
          {
              throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty.", new object[] { locationsPropertyName }));
          }
  
          bool flag2 = IsSpecificPath(name);
          string key = CreateCacheKey(cacheKeyPrefix, name, flag2 ? string.Empty : controllerName, areaName, theme);
  
          if (useCache) 
          {
              var cached = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, key);
              if (cached != null) 
              {
                  return cached;
              }
          }
  
          if (!flag2) 
          {
              return GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, theme, key, ref searchedLocations);
          }
  
      return GetPathFromSpecificName(controllerContext, name, key, ref searchedLocations);
  }
  </code></pre>
  
  <p><strong>Route Provider See Comments</strong>
  <em>Trying to override the core url ~/Admin/Order/Edit/1</em></p>
  
  <hr>
  
  <pre><code>public void RegisterRoutes(RouteCollection routes)
      {
          ViewEngines.Engines.Insert(0, new CustomViewEngine());
  
  //the articles above did NOT mention adding a path but it seemed like I needed to in order for my override path to be included???
          routes.MapRoute("Plugin...OrderDetailsOverride", "Order/Edit/{id}",
               new { controller = "MyOrder", action = "Edit" },
               new { id = @"\d+" },
               new[] { "MyPlugin.Controllers" }
          );            
  
      }
  
      public int Priority
      {
          get
          {
              return 1;
          }
      }
  </code></pre>
  
  <p>I was getting a 404 error and carefully rereading Twisted Whisperer he(I assume he) states:</p>
  
  <blockquote>
    <p>For example, if you are overrding Nop.Admin/Views/Category/Tree.cshtml, place your custom Tree.cshtml in Nop.Admin/CustomExtension/Views/Category/Tree.cshtml</p>
  </blockquote>
  
  <p>Well if I interpret that literally I would do this in the <strong>CORE ADMIN</strong> project:</p>
  
  <p><img src="https://i.stack.imgur.com/SEyxM.png" alt="enter image description here"></p>
  
  <p>I obviously did this and it worked...sorta.</p>
  
  <p>So in summary my questions / issues are:</p>
  
  <ol>
  <li><p>My Order Override Controller in the plugin isn't hit....(not interested in using ActionFilters as they don't give me what I need...I don't think).</p></li>
  <li><p>The view in my plugin isn't hit but the one added to the admin project is hit?</p></li>
  <li><p>Somewhat related to 2. If two is correct then how is that a viable plugin solution? For a production push, updates, etc. I would potentially have to touch the NopCommerce core projects....well why bother with a plugin then?</p></li>
  </ol>
  
  <p>Now the NOP guys as well as SO Community are far wiser than I so I'm sure I just don't understand properly.</p>