Nopcommerce Overriding Controller

时间:2015-07-07 08:01:16

标签: c# asp.net-mvc model-view-controller controller nopcommerce

我正在尝试并且未能在Nopcommerce中覆盖产品控制器中的方法。

在我的插件中,我正在成功扩展服务类,但是当涉及到覆盖控制器时,我遇到了问题而且它没有碰到断点。

所以我试图在Nop.Web.Controllers.Product中覆盖虚拟方法PrepareProductDetailsPageModel

    [NonAction]
    protected virtual ProductDetailsModel PrepareProductDetailsPageModel(Product product, 
        ShoppingCartItem updatecartitem = null, bool isAssociatedProduct = false)
    {
    }

我正在创建我的新类ProductController.cs 为:

  public partial class ProductController :      Nop.Web.Controllers.ProductController
     { 

     #region Fields

    private readonly ICategoryService _categoryService;
    private readonly IManufacturerService _manufacturerService;
    private readonly IProductService _productService;
    private readonly IVendorService _vendorService;
    private readonly IProductTemplateService _productTemplateService;
    private readonly IProductAttributeService _productAttributeService;
    private readonly IWorkContext _workContext;
    private readonly IStoreContext _storeContext;
    private readonly ITaxService _taxService;
    private readonly ICurrencyService _currencyService;
    private readonly IPictureService _pictureService;
    private readonly ILocalizationService _localizationService;
    private readonly IPriceCalculationService _priceCalculationService;
    private readonly IPriceFormatter _priceFormatter;
    private readonly IWebHelper _webHelper;
    private readonly ISpecificationAttributeService _specificationAttributeService;
    private readonly IDateTimeHelper _dateTimeHelper;
    private readonly IRecentlyViewedProductsService _recentlyViewedProductsService;
    private readonly ICompareProductsService _compareProductsService;
    private readonly IWorkflowMessageService _workflowMessageService;
    private readonly IProductTagService _productTagService;
    private readonly IOrderReportService _orderReportService;
    private readonly IBackInStockSubscriptionService _backInStockSubscriptionService;
    private readonly IAclService _aclService;
    private readonly IStoreMappingService _storeMappingService;
    private readonly IPermissionService _permissionService;
    private readonly ICustomerActivityService _customerActivityService;
    private readonly IProductAttributeParser _productAttributeParser;
    private readonly IShippingService _shippingService;
    private readonly MediaSettings _mediaSettings;
    private readonly CatalogSettings _catalogSettings;
    private readonly VendorSettings _vendorSettings;
    private readonly ShoppingCartSettings _shoppingCartSettings;
    private readonly LocalizationSettings _localizationSettings;
    private readonly CustomerSettings _customerSettings;
    private readonly CaptchaSettings _captchaSettings;
    private readonly SeoSettings _seoSettings;
    private readonly ICacheManager _cacheManager;

    #endregion

    #region Constructors

    public ProductController(ICategoryService categoryService,
        IManufacturerService manufacturerService,
        IProductService productService,
        IVendorService vendorService,
        IProductTemplateService productTemplateService,
        IProductAttributeService productAttributeService,
        IWorkContext workContext,
        IStoreContext storeContext,
        ITaxService taxService,
        ICurrencyService currencyService,
        IPictureService pictureService,
        ILocalizationService localizationService,
        IPriceCalculationService priceCalculationService,
        IPriceFormatter priceFormatter,
        IWebHelper webHelper,
        ISpecificationAttributeService specificationAttributeService,
        IDateTimeHelper dateTimeHelper,
        IRecentlyViewedProductsService recentlyViewedProductsService,
        ICompareProductsService compareProductsService,
        IWorkflowMessageService workflowMessageService,
        IProductTagService productTagService,
        IOrderReportService orderReportService,
        IBackInStockSubscriptionService backInStockSubscriptionService,
        IAclService aclService,
        IStoreMappingService storeMappingService,
        IPermissionService permissionService,
        ICustomerActivityService customerActivityService,
        IProductAttributeParser productAttributeParser,
        IShippingService shippingService,
        MediaSettings mediaSettings,
        CatalogSettings catalogSettings,
        VendorSettings vendorSettings,
        ShoppingCartSettings shoppingCartSettings,
        LocalizationSettings localizationSettings,
        CustomerSettings customerSettings,
        CaptchaSettings captchaSettings,
        SeoSettings seoSettings,
        ICacheManager cacheManager)
        : base(categoryService, manufacturerService, productService, vendorService, productTemplateService, productAttributeService,
            workContext, storeContext, taxService, currencyService, pictureService, localizationService, priceCalculationService, priceFormatter, webHelper, specificationAttributeService, dateTimeHelper,
            recentlyViewedProductsService, compareProductsService, workflowMessageService, productTagService, orderReportService, backInStockSubscriptionService, aclService, storeMappingService, permissionService,
            customerActivityService, productAttributeParser, shippingService, mediaSettings, catalogSettings, vendorSettings, shoppingCartSettings, localizationSettings, customerSettings, captchaSettings, seoSettings,
            cacheManager)
    {
        this._categoryService = categoryService;
        this._manufacturerService = manufacturerService;
        this._productService = productService;
        this._vendorService = vendorService;
        this._productTemplateService = productTemplateService;
        this._productAttributeService = productAttributeService;
        this._workContext = workContext;
        this._storeContext = storeContext;
        this._taxService = taxService;
        this._currencyService = currencyService;
        this._pictureService = pictureService;
        this._localizationService = localizationService;
        this._priceCalculationService = priceCalculationService;
        this._priceFormatter = priceFormatter;
        this._webHelper = webHelper;
        this._specificationAttributeService = specificationAttributeService;
        this._dateTimeHelper = dateTimeHelper;
        this._recentlyViewedProductsService = recentlyViewedProductsService;
        this._compareProductsService = compareProductsService;
        this._workflowMessageService = workflowMessageService;
        this._productTagService = productTagService;
        this._orderReportService = orderReportService;
        this._backInStockSubscriptionService = backInStockSubscriptionService;
        this._aclService = aclService;
        this._storeMappingService = storeMappingService;
        this._permissionService = permissionService;
        this._customerActivityService = customerActivityService;
        this._productAttributeParser = productAttributeParser;
        this._shippingService = shippingService;
        this._mediaSettings = mediaSettings;
        this._catalogSettings = catalogSettings;
        this._vendorSettings = vendorSettings;
        this._shoppingCartSettings = shoppingCartSettings;
        this._localizationSettings = localizationSettings;
        this._customerSettings = customerSettings;
        this._captchaSettings = captchaSettings;
        this._seoSettings = seoSettings;
        this._cacheManager = cacheManager;
    }

        protected override ProductDetailsModel PrepareProductDetailsPageModel(Product product, ShoppingCartItem updatecartitem = null, bool isAssociatedProduct = false)
        {
           return base.PrepareProductDetailsPageModel(product, 
           updatecartitem, isAssociatedProduct);
        }
     }

但是,这不会影响我的重写方法。

任何人都可以帮忙,请让我知道我做错了什么。

覆盖TaxService.cs时,我在DependencyRegistrar中注册我的TaxService。

我应该为这个控制器做些什么吗?

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

对于遇到此问题的其他人,我现在已经解决了。

您需要在DependencyRegistrar中注册您的控制器,基本上添加此行......

   public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
   {
      builder.RegisterType<YourPlugin.Controllers.
      ProductController>().As<Nop.Web.Controllers.ProductController>();
   }
   public int Order
   {
        get { return 100; }
   }

然后,这将击中被覆盖的方法。

还要记住将订单设置为100.不确定下限是多少。

答案 1 :(得分:0)

使用autofac注册组件是一个很好的解决方案。您也可以在Route.cs中进行更改,以将具有以下url的新控制器指向/ plugin / controller / XXX: