Custom view engine cannot find views in plugin if same view exists in theme or default view

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I'm creating a plugin for multiple wishlists per customer, and I want to override the view "HeaderLinks" so that I can link to my own wishlists instead of the default ones.

I followed Woon Cherk's guide in order to implement the custom view engine: http://www.pronopcommerce.com/3-ways-to-display-views-in-your-nopcommerce-plugins-embedded-resource-theme-override-and-custom-view-engine.

I have stepped through the program during debugging, and I found out that the HeaderLinks method in the CommonController uses my own view engine first as it should, but it only checks the location with the "useCache" parameter set to true. It does not find the view, and continues to search the other default locations with useCache set to first true, and then false. This is where it then returns the view I want to override. If I remove the other views, then it will not return at this point, but instead as a last step, check my own custom view engine path again with the useCache parameter set to false. In this final step, it finds the view I want it to return.

What i'm wondering is why it doesn't check my custom path with useCache set to false until the very end.


My custom view engine:
namespace Nop.Plugin.Misc.MultipleWishlists.Infrastructure
{
    public class MultipleWishlistsViewEngine : ThemeableRazorViewEngine
    {
        public MultipleWishlistsViewEngine()
        {
            ViewLocationFormats = new[] { "~/Plugins/Misc.MultipleWishlists/Views/{1}/{0}.cshtml" };
            PartialViewLocationFormats = new[] { "~/Plugins/Misc.MultipleWishlists/Views/{1}/{0}.cshtml" };
        }
    }
}


My route provider:

public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            ViewEngines.Engines.Insert(0, new MultipleWishlistsViewEngine());

            routes.MapRoute("Wishlist",
                "wishlists/{wishlistId}",
                new { controller = "MultipleWishlists", action = "Wishlist" },
                new { wishlistId = @"\d+" },
                new[] { "Nop.Plugin.Misc.MultipleWishlists.Controllers" });

            routes.MapRoute("Wishlists",
                "wishlists",
                new { controller = "MultipleWishlists", action = "Wishlists" },
                new[] { "Nop.Plugin.Misc.MultipleWishlists.Controllers" });

        }
        public int Priority
        {
            get
            {
                return 1;
            }
        }
    }


Thanks in advance
7 years ago
Any new thoughts on this matter?
6 years ago
I have same problem , any solution ??
6 years ago
Same Issue
6 years ago
Should this line really be in a RouteProvider?

ViewEngines.Engines.Insert(0, new MultipleWishlistsViewEngine());


It seems like it would be better to put this in a DependencyRegistrar, and set the Priority to a value which causes it to execute after the plugin's DependencyRegistrar
4 years ago
hiteshvaghasiya wrote:
Same Issue


Was your problem solved? I have the same problem
please help me
thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.