Skip to content

Commit

Permalink
Extend Queued Email entity - add Reference Object and key, admin pane…
Browse files Browse the repository at this point in the history
…l - add a new tab on the order - Notifications
  • Loading branch information
KrzysztofPajak committed Sep 15, 2021
1 parent 0a2a1c0 commit c6fcb34
Show file tree
Hide file tree
Showing 23 changed files with 296 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Grand.Business.Common.Interfaces.Pdf;
using Grand.Business.Customers.Interfaces;
using Grand.Business.Messages.Interfaces;
using Grand.Domain.Customers;
using Grand.Domain.Orders;
using MediatR;
using System;
Expand Down Expand Up @@ -58,8 +57,7 @@ public async Task<bool> Handle(SetOrderStatusCommand request, CancellationToken
await _orderService.UpdateOrder(request.Order);

//order notes, notifications
await _orderService.InsertOrderNote(new OrderNote
{
await _orderService.InsertOrderNote(new OrderNote {
Note = string.Format("Order status has been changed to {0}", request.Os.ToString()),
DisplayToCustomer = false,
OrderId = request.Order.Id,
Expand All @@ -82,37 +80,18 @@ public async Task<bool> Handle(SetOrderStatusCommand request, CancellationToken
var orderCompletedAttachments = _orderSettings.AttachPdfInvoiceToOrderCompletedEmail && _orderSettings.AttachPdfInvoiceToBinary ?
new List<string> { await _pdfService.SaveOrderToBinary(request.Order, "") } : new List<string>();

int orderCompletedCustomerNotificationQueuedEmailId = await _messageProviderService
await _messageProviderService
.SendOrderCompletedCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId, orderCompletedAttachmentFilePath,
orderCompletedAttachmentFileName, orderCompletedAttachments);
if (orderCompletedCustomerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "\"Order completed\" email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id,
});
}
}

if (prevOrderStatus != (int)OrderStatusSystem.Cancelled &&
request.Os == OrderStatusSystem.Cancelled
&& request.NotifyCustomer)
{
//notification customer
int orderCancelledCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderCancelledCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId);
if (orderCancelledCustomerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "\"Order cancelled\" email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id,
});
}
await _messageProviderService.SendOrderCancelledCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId);

//notification for vendor
await VendorNotification(request.Order);
}
Expand All @@ -125,8 +104,7 @@ public async Task<bool> Handle(SetOrderStatusCommand request, CancellationToken
var orderCancelledStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderCancelledStoreOwnerMessage(request.Order, customer, request.Order.CustomerLanguageId);
if (orderCancelledStoreOwnerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
await _orderService.InsertOrderNote(new OrderNote {
Note = "\"Order cancelled\" by customer.",
DisplayToCustomer = true,
CreatedOnUtc = DateTime.UtcNow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Grand.Business.Messages.Interfaces;
using Grand.Domain.Localization;
using Grand.Domain.Logging;
using Grand.Domain.Orders;
using Grand.SharedKernel;
using MediatR;
using System;
Expand Down Expand Up @@ -92,30 +91,10 @@ public async Task<IList<string>> Handle(PartiallyRefundCommand command, Cancella
await _mediator.Send(new CheckOrderStatusCommand() { Order = order });

//notifications
var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);
if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order refunded email (to store owner) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}


var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);
if (orderRefundedCustomerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order refunded email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);

await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);

}
//raise event
await _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, amountToRefund));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,19 +1141,8 @@ protected virtual async Task SendNotification(IServiceScopeFactory scopeFactory,
}

//send email notifications
int orderPlacedStoreOwnerNotificationQueuedEmailId = await messageProviderService.SendOrderPlacedStoreOwnerMessage(order, customer, languageSettings.DefaultAdminLanguageId);
if (orderPlacedStoreOwnerNotificationQueuedEmailId > 0)
{
await orderService.InsertOrderNote(new OrderNote
{
Note = "Order placed email (to store owner) has been queued",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,

});
}

await messageProviderService.SendOrderPlacedStoreOwnerMessage(order, customer, languageSettings.DefaultAdminLanguageId);

string orderPlacedAttachmentFilePath = string.Empty, orderPlacedAttachmentFileName = string.Empty;
var orderPlacedAttachments = new List<string>();

Expand All @@ -1171,36 +1160,15 @@ protected virtual async Task SendNotification(IServiceScopeFactory scopeFactory,
_logger.Error($"Error - order placed attachment file {order.OrderNumber}", ex);
}

int orderPlacedCustomerNotificationQueuedEmailId = await messageProviderService
await messageProviderService
.SendOrderPlacedCustomerMessage(order, customer, order.CustomerLanguageId, orderPlacedAttachmentFilePath, orderPlacedAttachmentFileName, orderPlacedAttachments);

if (orderPlacedCustomerNotificationQueuedEmailId > 0)
{
await orderService.InsertOrderNote(new OrderNote
{
Note = "Order placed email (to customer) has been queued",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,

});
}
if (order.OrderItems.Any(x => !string.IsNullOrEmpty(x.VendorId)))
{
var vendors = await mediator.Send(new GetVendorsInOrderQuery() { Order = order });
foreach (var vendor in vendors)
{
int orderPlacedVendorNotificationQueuedEmailId = await messageProviderService.SendOrderPlacedVendorMessage(order, customer, vendor, languageSettings.DefaultAdminLanguageId);
if (orderPlacedVendorNotificationQueuedEmailId > 0)
{
await orderService.InsertOrderNote(new OrderNote
{
Note = "Order placed email (to vendor) has been queued",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
await messageProviderService.SendOrderPlacedVendorMessage(order, customer, vendor, languageSettings.DefaultAdminLanguageId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Grand.Business.Messages.Interfaces;
using Grand.Domain.Localization;
using Grand.Domain.Logging;
using Grand.Domain.Orders;
using MediatR;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -82,31 +81,11 @@ public async Task<IList<string>> Handle(RefundCommand command, CancellationToken
//check order status
await _mediator.Send(new CheckOrderStatusCommand() { Order = order });

//notifications
var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, request.AmountToRefund, _languageSettings.DefaultAdminLanguageId);
if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order refunded email (to store owner) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}

//notifications
var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, request.AmountToRefund, order.CustomerLanguageId);
if (orderRefundedCustomerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order refunded email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
//notifications for store owner
await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, request.AmountToRefund, _languageSettings.DefaultAdminLanguageId);

//notifications for customer
await _messageProviderService.SendOrderRefundedCustomerMessage(order, request.AmountToRefund, order.CustomerLanguageId);

//raise event
await _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, request.AmountToRefund));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Grand.Business.Checkout.Queries.Models.Orders;
using Grand.Business.Messages.Interfaces;
using Grand.Domain.Localization;
using Grand.Domain.Orders;
using Grand.Domain.Payments;
using Grand.SharedKernel;
using MediatR;
Expand All @@ -24,10 +23,10 @@ public class RefundOfflineCommandHandler : IRequestHandler<RefundOfflineCommand,
private readonly LanguageSettings _languageSettings;

public RefundOfflineCommandHandler(
IMediator mediator,
IMediator mediator,
IOrderService orderService,
IPaymentTransactionService paymentTransactionService,
IMessageProviderService messageProviderService,
IMessageProviderService messageProviderService,
LanguageSettings languageSettings)
{
_mediator = mediator;
Expand Down Expand Up @@ -72,32 +71,11 @@ public async Task<bool> Handle(RefundOfflineCommand request, CancellationToken c
//check order status
await _mediator.Send(new CheckOrderStatusCommand() { Order = order });

//notifications
var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);
if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order refunded email (to store owner) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});

}


var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);
if (orderRefundedCustomerNotificationQueuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "\"Order refunded\" email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
//notifications for store owner
await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);

//notifications for customer
await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);

//raise event
await _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, amountToRefund));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Commands.Models.Shipping;
using Grand.Business.Checkout.Extensions;
using Grand.Business.Checkout.Interfaces.Orders;
Expand Down Expand Up @@ -60,8 +59,7 @@ public async Task<bool> Handle(DeliveryCommand request, CancellationToken cancel
}

//add a note
await _orderService.InsertOrderNote(new OrderNote
{
await _orderService.InsertOrderNote(new OrderNote {
Note = $"Shipment #{request.Shipment.ShipmentNumber} has been delivered",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
Expand All @@ -70,17 +68,7 @@ public async Task<bool> Handle(DeliveryCommand request, CancellationToken cancel
if (request.NotifyCustomer)
{
//send email notification
int queuedEmailId = await _messageProviderService.SendShipmentDeliveredCustomerMessage(request.Shipment, order);
if (queuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "\"Delivered\" email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
await _messageProviderService.SendShipmentDeliveredCustomerMessage(request.Shipment, order);
}
//event
await _mediator.PublishShipmentDelivered(request.Shipment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Commands.Models.Shipping;
using Grand.Business.Checkout.Extensions;
using Grand.Business.Checkout.Interfaces.Orders;
Expand All @@ -20,23 +19,17 @@ public class ShipCommandHandler : IRequestHandler<ShipCommand, bool>
private readonly IMediator _mediator;
private readonly IOrderService _orderService;
private readonly IShipmentService _shipmentService;
private readonly IProductService _productService;
private readonly IInventoryManageService _inventoryManageService;
private readonly IMessageProviderService _messageProviderService;

public ShipCommandHandler(
IMediator mediator,
IOrderService orderService,
IShipmentService shipmentService,
IProductService productService,
IInventoryManageService inventoryManageService,
IMessageProviderService messageProviderService)
{
_mediator = mediator;
_orderService = orderService;
_shipmentService = shipmentService;
_productService = productService;
_inventoryManageService = inventoryManageService;
_messageProviderService = messageProviderService;
}

Expand Down Expand Up @@ -69,8 +62,7 @@ public async Task<bool> Handle(ShipCommand request, CancellationToken cancellati
await _orderService.UpdateOrder(order);

//add a note
await _orderService.InsertOrderNote(new OrderNote
{
await _orderService.InsertOrderNote(new OrderNote {
Note = $"Shipment #{request.Shipment.ShipmentNumber} has been sent",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
Expand All @@ -80,17 +72,7 @@ public async Task<bool> Handle(ShipCommand request, CancellationToken cancellati
if (request.NotifyCustomer)
{
//notify customer
int queuedEmailId = await _messageProviderService.SendShipmentSentCustomerMessage(request.Shipment, order);
if (queuedEmailId > 0)
{
await _orderService.InsertOrderNote(new OrderNote
{
Note = "\"Shipped\" email (to customer) has been queued.",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id,
});
}
await _messageProviderService.SendShipmentSentCustomerMessage(request.Shipment, order);
}
//event
await _mediator.PublishShipmentSent(request.Shipment);
Expand Down
Loading

0 comments on commit c6fcb34

Please sign in to comment.