While working on nopCommerce plugins and themes we constantly encounter one and the same problem. Let me try to describe it.
You know how sometimes you need to customize some view in a nopCommerce theme and you cannot just do it with css or razor.
For example we want to change the RecentlyViewedProductsBlock.cshtml to contain not only the product titles but also the product images and prices. Now the Nop.Web.CatalogController.RecentlyViewedProductsBlock action prepares the product models like this:
foreach (var product in products)
model.Add(PrepareProductOverviewModel(product, false, false));
which means that the pictures and prices are not put into the model (the two false flags define if pictures and prices should be put into the mdoel).
So we created a plugin for the theme, and in this plugin we added our own CatalogController.RecentlyViewProductsBlock action which overrides the default one from Nop.Web.CatalogController. The code in this action is pretty much the same with some minor changes but most importantly it prepares the product models like this:
foreach (var product in products)
model.Add(PrepareProductOverviewModel(product, true, true));
The problem is however that the Nop.Web.Controllers.CatalogController.PreparedProductOverviewModel method is private. So we need to rewrite it in the plugin. If we rewrite the PrepareProductOverviewModel method, this has a ripple effect as this method uses methods like PrepareProductPriceModel, which is private too and the PrepareProductPriceModel uses other private methods. So you can see how this becomes a problem for the plugin. We could rewrite all of them but upgrading later to new versions of nopCommerce will be difficult. We could change them directly in the Nop.Web.CatalogController class but this is not what we want for the same upgraded reasons and also because we loose the pluggable nature of the theme.
So we were wondering if in the CatalogController the PrepareModel private methods could be made protected or extracted somehow to a separate public Interface so that they can be used by third party plugins.
We believe that such methods are:
1. Nop.Web.Controllers.CatalogController.PrepareProductDetailsPageModel
2. Nop.Web.Controllers.CatalogController.PrepareProductOverviewModel
3. Nop.Web.Controllers.CatalogController.PrepareProductPriceModel
4. Nop.Web.Controllers.CatalogController.PrepareProductReviewsModel
5. Nop.Web.Controllers.CatalogController.PrepareProductVariantModel
These are the methods for the CatalogController but every controller in the Nop.Web namespace has such PreparedModel methods, which are private and could be made accessible so that the views returned from the controller actions can be customized easier.
If this could be done in some of the coming versions of nopCommerce it would be great help for third party plugin development!
Many Thanks