Close

Working With Another Plugin

ierhalim
7 years ago
#13307 Quote
Avatar
  • 5
Hi,
I try to use Pavilion theme with my custom (heavy) plugin and try to override some views and controllers. And i dont want  to change thirty part code(nopCommerce or any plugin,theme code).

So i was write a CustomViewEngine which insert some PartialViewLocationFormats and ViewLocationFormats.

In RouteProvider i'm insert this ViewEngine as a first Engine.



  public int Priority
        {
            get
            {
                return int.MaxValue;
            }
        }


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




Also i override ShoppingCartController.AddProductToCart_Details and ShoppingCartController.AddProductToCart_Catalog  (they are still use base methods but i manage some form data before and after Add operation.)




public class ShoppingCartOverridesController : Nop.Web.Controllers.ShoppingCartController
{
public override ActionResult AddProductToCart_Details(int productId, int shoppingCartTypeId, FormCollection form)
{
//Some code which use RequestFormData

  var result =  base.AddProductToCart_Details(productId,shoppingCartTypeId,form);

//Some code

return result;


}

}






public override ActionResult AddProductToCart_Catalog(int productId, int shoppingCartTypeId, int quantity, bool forceredirection = false)
{
   //Some code which use RequestFormData
  var result =   AddProductToCart_Catalog(productId, shoppingCartTypeId, quantity, forceredirection)
   //Some code

return result;

}



And ofcourse i create new route on my routeprovider.



   //add product to cart (without any attributes and options). used on catalog pages.
            routes.MapLocalizedRoute("XXX.YYY.Integration.Override.AddProductToCart-Catalog",
                            "addproducttocart/catalog/{productId}/{shoppingCartTypeId}/{quantity}",
                            new { controller = "ShoppingCartOverrides", action = "AddProductToCart_Catalog" },
                            new { productId = @"\d+", shoppingCartTypeId = @"\d+", quantity = @"\d+" },
                            new[] { "XXX.YYY.Integration.Controllers" });


            //add product to cart (with attributes and options). used on the product details pages.
            routes.MapLocalizedRoute("XXX.YYY.Integration.Override.AddProductToCart-Details",
                            "addproducttocart/details/{productId}/{shoppingCartTypeId}",
                            new { controller = "ShoppingCartOverrides", action = "AddProductToCart_Details" },
                            new { productId = @"\d+", shoppingCartTypeId = @"\d+" },
                            new[] { "XXX.YYY.Integration.Controllers" });



But after installation of Pavilion theme my all overrides blow up.

My CustomViewEngine does not work. (I wan't to check my custom folders first if there is a file with same name should use my view.)

My Controllers does not work cause the request adress is diffrent new requests urls are AddProductToCartAjax,AddProductFromProductDetailsPageToCartAjax so i should override this rotues and override methods but plugins probanbly(SevenSpikes.Nop.Plugins.AjaxCart) are not open source and i would like to inheritance from original controller and use original base.methods after my custom work).

Thank You



hristian.dimov
7 years ago
#13311 Quote
Avatar
  • Moderator
  • 386
ierhalim wrote:
Hi,
...


Hi,

Lets start with the Custom View Engine. Can you make sure that you after you insert it, it is at position 0? We also have a Custom View Engine on position 0, so this might be the issue. Just debug the code and see if everything is correct with that.

Looking forward to your reply!
Regards,
Hristian Dimov
Nop-Templates.com
ierhalim
7 years ago
#13315 Quote
Avatar
  • 5
hristian.dimov wrote:



Hi,
Lets start with the Custom View Engine. ..


Hi hristian thanks for attention,

I found a some hacky way for ensuring myviewengine is the first viewengine. Ofcourse this is only for debugging i have a  good idea for this.

End of the Global_asax.Application_Start i change the ViewEngines



            var xxxViewEngine = ViewEngines.Engines[1];
            var pluginViewEngine = ViewEngines.Engines[0];

            ViewEngines.Engines[0] = xxxViewEngine;
            ViewEngines.Engines[1] = pluginViewEngine;
              


But it still does not work, i think it's not about the theme, it's about the ThemeableVirtualPathProviderViewEngine

ThemeableVirtualPathProviderViewEngine.FindView method called with parameter useCache = true and pass this parameter to ThemeableVirtualPathProviderViewEngine.GetPath in this method looking for cached view (i don't understand how i put view to cache) and return null.

I try to set useCache false on debugging and it work well.

I know it's not about theme but any help would be appreciated.

hristian.dimov
7 years ago
#13316 Quote
Avatar
  • Moderator
  • 386
ierhalim wrote:

...


Hi,

You can override the FindPartialView and FindView methods to ensure that your view will be found from your view locations. Something like this:

public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
{
  ViewEngineResult viewEngineResult = base.FindPartialView(controllerContext, partialViewName, useCache);

  if (useCache && viewEngineResult.View == null)
  {
    viewEngineResult = base.FindPartialView(controllerContext, partialViewName, false);
  }

  return viewEngineResult;
}

public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
  ViewEngineResult viewEngineResult = base.FindView(controllerContext, viewName, masterName, useCache);

  if (useCache && viewEngineResult.View == null)
  {
    viewEngineResult = base.FindView(controllerContext, viewName, masterName, false);
  }

  return viewEngineResult;
}

Regards,
Hristian Dimov
Nop-Templates.com
ierhalim
7 years ago
#13317 Quote
Avatar
  • 5
hristian.dimov wrote:

...

Hi,
You can override the FindPartialView and FindView

Hi,
Thanks a lot it worked well.

Now i can develop custom views.

But still having trouble with adding item to cart. Dou you have any recommendation for that?
hristian.dimov
7 years ago
#13318 Quote
Avatar
  • Moderator
  • 386
ierhalim wrote:

...

Hi,
You can override the FindPartialView and FindView

Hi,
Thanks a lot it worked well.

Now i can develop custom views.

But still having trouble with adding item to cart. Dou you have any recommendation for that?


Hi,

maybe you can use ActionFilters to change the logic in the AddToCart actions instead of overriding them? Our AjaxCart plugin has its own routes and probably that's why your own actions are not called.
Regards,
Hristian Dimov
Nop-Templates.com
ierhalim
7 years ago
#13322 Quote
Avatar
  • 5
hristian.dimov wrote:

Hi hristian,
maybe you can use ActionFilters ...


Hi, i was think about ActionFilters before posting this topic but it was just feelt wrong.
But i have to focus deadline, so i'll use action filters.
Thanks a lot.