Nopcommerce 重写控制器
Nopcommerce Overriding Controller
我正在尝试覆盖 Nopcommerce 产品控制器中的方法,但失败了。
在我的插件中,我成功地扩展了服务 classes,但是当涉及到覆盖控制器时,我遇到了问题并且它没有到达断点。
所以我试图重写 Nop.Web.Controllers.Product
中的虚方法 PrepareProductDetailsPageModel
[NonAction]
protected virtual ProductDetailsModel PrepareProductDetailsPageModel(Product product,
ShoppingCartItem updatecartitem = null, bool isAssociatedProduct = false)
{
}
我正在创建我的新 class 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。
我应该为这个控制器做些什么吗?
感谢您的帮助。
对于遇到此问题的任何其他人,我现在已经解决了。
您需要在 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,不知道下限是多少。
使用 autofac 注册组件是一个很好的解决方案。您还可以在 Route.cs 中进行更改,以便将具有 url : /plugin/controller/XXX 的新控制器指向前一个
我正在尝试覆盖 Nopcommerce 产品控制器中的方法,但失败了。
在我的插件中,我成功地扩展了服务 classes,但是当涉及到覆盖控制器时,我遇到了问题并且它没有到达断点。
所以我试图重写 Nop.Web.Controllers.Product
中的虚方法 PrepareProductDetailsPageModel [NonAction]
protected virtual ProductDetailsModel PrepareProductDetailsPageModel(Product product,
ShoppingCartItem updatecartitem = null, bool isAssociatedProduct = false)
{
}
我正在创建我的新 class 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。
我应该为这个控制器做些什么吗?
感谢您的帮助。
对于遇到此问题的任何其他人,我现在已经解决了。
您需要在 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,不知道下限是多少。
使用 autofac 注册组件是一个很好的解决方案。您还可以在 Route.cs 中进行更改,以便将具有 url : /plugin/controller/XXX 的新控制器指向前一个