How to override shoppingcart route without increase priority

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
Can anybody tell me how I can override shopping cart rout without increase priority.I can not increase priority because I implement a "GenericRoute" for override ProductDetails functionality at my plugin.If I increase the priority it shows a exception at checkout page.

The error message is

"Multiple types were found that match the controller named 'Common'. This can happen if the route that services this request ('{generic_se_name}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter."
8 years ago
I am looking for any infos and materials about views and override for cart and how make correctly other cart with checkout. But about it is not so much on website NOPCOMERCE.  

I need it customize for Czech enviroment, because there is more special method and reqiurements according to law of Czech Republic.
8 years ago
If you want to override "cart" without increase priority.You can use this code


         var route = routes.CustomMapLocalizedRoute("Plugin.Misc.MyPlugin.ShoppingCartUrl",
            "cart/",
            new { controller = "ShoppingCart", action = "Cart" },
            new[] { "Nop.Plugin.Misc.MyPlugin.Controllers" });
            routes.Remove(route);
            routes.Insert(0, route);


It works for me.
7 years ago
sina.islam wrote:
If you want to override "cart" without increase priority.You can use this code


         var route = routes.CustomMapLocalizedRoute("Plugin.Misc.MyPlugin.ShoppingCartUrl",
            "cart/",
            new { controller = "ShoppingCart", action = "Cart" },
            new[] { "Nop.Plugin.Misc.MyPlugin.Controllers" });
            routes.Remove(route);
            routes.Insert(0, route);


It works for me.



Some people ask me about CustomMapLocalizedRoute.

Here is the Class :


using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace Nop.Plugin.Misc.AvenirTelecom
{
    public static class LocalizedRouteExtensions
    {
        //Override for localized route
        public static Route CustomMapLocalizedRoute(this RouteCollection routes, string name, string url, object defaults, string[] namespaces)
        {
            return MapLocalizedRoute(routes, name, url, defaults, null /* constraints */, namespaces);
        }
        public static Route MapLocalizedRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            var route = new LocalizedRoute(url, new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(defaults),
                //Constraints = new RouteValueDictionary(constraints),
                DataTokens = new RouteValueDictionary()
            };

            if ((namespaces != null) && (namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            routes.Add(name, route);

            return route;
        }
        
        public static void ClearSeoFriendlyUrlsCachedValueForRoutes(this RouteCollection routes)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            foreach (var route in routes)
            {
                if (route is LocalizedRoute)
                {
                    ((LocalizedRoute) route).ClearSeoFriendlyUrlsCachedValue();
                }
            }
        }
    }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.