【问题标题】:Nopcommerce Overriding ControllerNopcommerce 压倒一切的控制器
【发布时间】:2015-09-24 14:37:33
【问题描述】:

我正在尝试覆盖 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。

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

感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

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

    你需要在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; }
       }
    

    然后这将影响您覆盖的方法。

    还记得将 Order 设置为 100。不确定下限是多少。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多