Price change notification

один месяц назад
Hi!
We are trying to implement a plugin which sends emails to the customers who have a product in their wishlist if the price for that product changes.

What we tried so far was to override the Edit from ProductController:

    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class ProductController : Nop.Web.Areas.Admin.Controllers.ProductController
    {
        private readonly IBackInStockSubscriptionService _backInStockSubscriptionService;
        private readonly ICustomerActivityService _customerActivityService;
        ...

        public ProductController(...)
            : base(...)
        {
            ....
        }

        [HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
        public async override Task<IActionResult> Edit(ProductModel model, bool continueEditing)
        {
            ....
        }



    public class RouteProvider : IRouteProvider
    {
        public int Priority => int.MaxValue;

        public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
            endpointRouteBuilder.MapControllerRoute(Constants.ConfigurationRouteName,
                "~/Admin/Product/Edit",
                new { controller = "Product", action = "Edit", area = AreaNames.Admin });
        }
    }


But we are getting an error


AmbiguousMatchException: The request matched multiple endpoints. Matches:

Nop.Web.Areas.Admin.Controllers.ProductController.List (Nop.Web)
<pluginName>.Areas.Admin.Controllers.ProductController.List (<pluginName>)

but shouldn`t the plugin override just that method? If not, how can it be done?

Is there a way to achieve this via a plugin without editing the core code? (nopCommerce 4.50)
Thank you in advance!
один месяц назад
You should be able to do this by creating an EventConsumer plugin consuming the ModelReceivedEvent.   That event should occur before the EntityUpdatedEvent<Product> so that you can then use the ProductService to get the prior price and compare it to the new price in the ProductModel.

Look at the
\Plugins\Nop.Plugin.Tax.Avalara\Services\EventConsumer.cs

Yours won't be nearly as complicated ;)  You just need to handle/consume one event, and you don't need the switch, just use "is" (pattern match) in a regular if-statement:
    public class EventConsumer :
        IConsumer<ModelReceivedEvent<BaseNopModel>>,
...

        public async Task HandleEventAsync(ModelReceivedEvent<BaseNopModel> eventMessage)
        {
            //get entity by received model
            var entity = eventMessage.Model switch
            {
...
                ProductModel productModel => await _productService.GetProductByIdAsync(productModel.Id),


(However, if you want to "sends emails to the customers", I assume you know there is no Message Template for "Price change", so you'll need to deal with that.)
один месяц назад
The EventConsumer approach you suggested was just what I needed, thank you!