I am working on nopCommerce v3.90. I have a requirement to a plugin which would update the original Price of the Product by some percentage ratio based on the settings performed within plugin settings section, without altering the existing nopCommerce model structure.
Hence, each time the product's price is displayed, one should be able to see the new updated price (based on the action performed in a plugin) instead of the price from the database.
Can anyone help me with this?
Existing Model class in nopCommerce
public partial class ProductPriceModel : BaseNopModel
{
//block of statements
public string Price { get; set; } //the property whose value need to be changed from plugin
//block of statements
}
In 3.9 the options I know are
PrepareProductPriceModelmethod inIProductModelFactoryclass and provide your custom implementation using dependency overrideActionFilterto customize theProductPriceModelbefore it gets used in the view.In 4.0 this is very easy. You only have to subscribe to
ModelPreparedEventand then customize theProductPriceModel.Override
IProductModelFactoryIn your plugin dependency registrar
Implement
ActionFilterAnd to dynamically provide your ActionFilter
In your plugin dependency registrar
Subscribe to
ModelPreparedEvent<ProductDetailsModel>(nopCommerce 4.0)