-
Notifications
You must be signed in to change notification settings - Fork 5
/
OrderPlacedEventConsumer.cs
56 lines (49 loc) · 1.87 KB
/
OrderPlacedEventConsumer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using Nop.Core.Domain.Orders;
using Nop.Core.Plugins;
using Nop.Services.Events;
using Nop.Services.Orders;
namespace Nop.Plugin.SMS.Verizon
{
public class OrderPlacedEventConsumer : IConsumer<OrderPlacedEvent>
{
private readonly VerizonSettings _verizonSettings;
private readonly IPluginFinder _pluginFinder;
private readonly IOrderService _orderService;
public OrderPlacedEventConsumer(VerizonSettings verizonSettings,
IPluginFinder pluginFinder, IOrderService orderService)
{
this._verizonSettings = verizonSettings;
this._pluginFinder = pluginFinder;
this._orderService = orderService;
}
/// <summary>
/// Handles the event.
/// </summary>
/// <param name="eventMessage">The event message.</param>
public void HandleEvent(OrderPlacedEvent eventMessage)
{
//is enabled?
if (!_verizonSettings.Enabled)
return;
var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("Mobile.SMS.Verizon");
if (pluginDescriptor == null)
return;
var plugin = pluginDescriptor.Instance() as VerizonSmsProvider;
if (plugin == null)
return;
var order = eventMessage.Order;
//send SMS
if (plugin.SendSms(String.Format("New order(#{0}) has been placed.", order.Id)))
{
order.OrderNotes.Add(new OrderNote()
{
Note = "\"Order placed\" SMS alert (to store owner) has been sent",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow
});
_orderService.UpdateOrder(order);
}
}
}
}