Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
asvishnyakov committed Apr 11, 2017
2 parents 49be089 + c464af4 commit 08cee42
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 71 deletions.
16 changes: 0 additions & 16 deletions VirtoCommerce.OrderModule.Data/Notifications/Invoice.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using VirtoCommerce.Domain.Order.Model;
using VirtoCommerce.Platform.Core.Notifications;

namespace VirtoCommerce.OrderModule.Data.Notifications
{
public class InvoiceEmailNotification : OrderEmailNotificationBase
{
public InvoiceEmailNotification(IEmailNotificationSendingGateway gateway)
: base(gateway)
{
}

/// <summary>
/// For templates back compatibility
/// </summary>
[NotificationParameter("Order")]
public CustomerOrder Order
{
get
{
return base.CustomerOrder;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public NewOrderStatusEmailNotification(IEmailNotificationSendingGateway gateway)

[NotificationParameter("New order status")]
public string NewStatus { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace VirtoCommerce.OrderModule.Data.Notifications
{
public class OrderEmailNotificationBase : EmailNotification
public abstract class OrderEmailNotificationBase : EmailNotification
{
public OrderEmailNotificationBase(IEmailNotificationSendingGateway gateway) : base(gateway) { }

[NotificationParameter("CustomerOrder")]
public CustomerOrder CustomerOrder { get; set; }
[NotificationParameter("Customer Order")]
public CustomerOrder CustomerOrder { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public OrderPaidEmailNotification(IEmailNotificationSendingGateway gateway)
: base(gateway)
{
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public void OnNext(OrderChangedEvent changeEvent)
//Collection of order notifications
var notifications = new List<OrderEmailNotificationBase>();

if(IsOrderCanceled(changeEvent))
if (IsOrderCanceled(changeEvent))
{
var notification = _notificationManager.GetNewNotification<CancelOrderEmailNotification>(changeEvent.ModifiedOrder.StoreId, "Store", changeEvent.ModifiedOrder.LanguageCode);
notifications.Add(notification);
}

if(changeEvent.ChangeState == EntryState.Added && !changeEvent.ModifiedOrder.IsPrototype)
if (changeEvent.ChangeState == EntryState.Added && !changeEvent.ModifiedOrder.IsPrototype)
{
var notification = _notificationManager.GetNewNotification<OrderCreateEmailNotification>(changeEvent.ModifiedOrder.StoreId, "Store", changeEvent.ModifiedOrder.LanguageCode);
notifications.Add(notification);
}

if(IsNewStatus(changeEvent))
if (IsNewStatus(changeEvent))
{
var notification = _notificationManager.GetNewNotification<NewOrderStatusEmailNotification>(changeEvent.ModifiedOrder.StoreId, "Store", changeEvent.ModifiedOrder.LanguageCode);

Expand All @@ -68,19 +68,19 @@ public void OnNext(OrderChangedEvent changeEvent)
notifications.Add(notification);
}

if(IsOrderPaid(changeEvent))
if (IsOrderPaid(changeEvent))
{
var notification = _notificationManager.GetNewNotification<OrderPaidEmailNotification>(changeEvent.ModifiedOrder.StoreId, "Store", changeEvent.ModifiedOrder.LanguageCode);
notifications.Add(notification);
}

if(IsOrderSent(changeEvent))
if (IsOrderSent(changeEvent))
{
var notification = _notificationManager.GetNewNotification<OrderSentEmailNotification>(changeEvent.ModifiedOrder.StoreId, "Store", changeEvent.ModifiedOrder.LanguageCode);
notifications.Add(notification);
}

foreach(var notification in notifications)
foreach (var notification in notifications)
{
notification.CustomerOrder = changeEvent.ModifiedOrder;
SetNotificationParameters(notification, changeEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<Compile Include="Model\ShipmentItemEntity.cs" />
<Compile Include="Model\TaxDetailEntity.cs" />
<Compile Include="Notifications\CancelOrderEmailNotification.cs" />
<Compile Include="Notifications\Invoice.cs" />
<Compile Include="Notifications\InvoiceEmailNotification.cs" />
<Compile Include="Notifications\NewOrderStatusEmailNotification.cs" />
<Compile Include="Notifications\OrderCreateEmailNotification.cs" />
<Compile Include="Notifications\OrderEmailNotificationBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,32 +440,33 @@ public IHttpActionResult PostProcessPayment(webModel.PaymentCallbackParameters c
[HttpGet]
[Route("invoice/{orderNumber}")]
[SwaggerFileResponse]
public HttpResponseMessage GetInvoicePdf(string orderNumber)
public IHttpActionResult GetInvoicePdf(string orderNumber)
{
var oderSearchResult = _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria
{
Number = orderNumber,
Take = 1
});

var order = oderSearchResult.Results.FirstOrDefault();

var invoice = _notificationManager.GetNewNotification("Invoice", null, null, "en-US") as Invoice;
if (invoice != null)
{
invoice.Order = order;
_notificationTemplateResolver.ResolveTemplate(invoice);
}
if (order == null)
throw new NullReferenceException("order not found");

var pdf = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4);
var stream = new MemoryStream();
var invoice = _notificationManager.GetNewNotification<InvoiceEmailNotification>(order.StoreId, "Store", order.LanguageCode);

((InvoiceEmailNotification)invoice).CustomerOrder = order;
_notificationTemplateResolver.ResolveTemplate(invoice);

var stream = new MemoryStream();
var pdf = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4);
pdf.Save(stream, false);
stream.Seek(0, SeekOrigin.Begin);

var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

return result;
return ResponseMessage(result);
}

private CustomerOrderSearchCriteria FilterOrderSearchCriteria(string userName, CustomerOrderSearchCriteria criteria)
Expand All @@ -475,16 +476,16 @@ private CustomerOrderSearchCriteria FilterOrderSearchCriteria(string userName, C
{
//Get defined user 'read' permission scopes
var readPermissionScopes = _securityService.GetUserPermissions(userName)
.Where(x => x.Id.StartsWith(OrderPredefinedPermissions.Read))
.SelectMany(x => x.AssignedScopes)
.ToList();
.Where(x => x.Id.StartsWith(OrderPredefinedPermissions.Read))
.SelectMany(x => x.AssignedScopes)
.ToList();

//Check user has a scopes
//Stores
criteria.StoreIds = readPermissionScopes.OfType<OrderStoreScope>()
.Select(x => x.Scope)
.Where(x => !String.IsNullOrEmpty(x))
.ToArray();
.Select(x => x.Scope)
.Where(x => !String.IsNullOrEmpty(x))
.ToArray();

var responsibleScope = readPermissionScopes.OfType<OrderResponsibleScope>().FirstOrDefault();
//employee id
Expand Down
27 changes: 13 additions & 14 deletions VirtoCommerce.OrderModule.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,7 @@ public override void Initialize()
_container.RegisterType<ICustomerOrderService, CustomerOrderServiceImpl>();
_container.RegisterType<ICustomerOrderSearchService, CustomerOrderServiceImpl>();
_container.RegisterType<ICustomerOrderBuilder, CustomerOrderBuilderImpl>();

var emailNotificationSendingGateway = _container.Resolve<IEmailNotificationSendingGateway>();
var notificationManager = _container.Resolve<INotificationManager>();
notificationManager.RegisterNotificationType(() => new Invoice(emailNotificationSendingGateway)
{
Description = "The invoice for order",
DisplayName = "The invoice for order",
Type = "Invoice",
NotificationTemplate = new NotificationTemplate
{
Body = InvoiceResource.Body,
Language = "en-US"
}
});

}

public override void PostInitialize()
Expand Down Expand Up @@ -157,6 +144,18 @@ public override void PostInitialize()
}
});

notificationManager.RegisterNotificationType(() => new InvoiceEmailNotification(_container.Resolve<IEmailNotificationSendingGateway>())
{
Description = "The template for for customer order invoice (used for PDF generation)",
DisplayName = "The invoice for customer order",
NotificationTemplate = new NotificationTemplate
{
Body = InvoiceResource.Body,
Subject = InvoiceResource.Subject,
Language = "en-US"
}
});

var securityScopeService = _container.Resolve<IPermissionScopeService>();
securityScopeService.RegisterSope(() => new OrderStoreScope());
securityScopeService.RegisterSope(() => new OrderResponsibleScope());
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions VirtoCommerce.OrderModule.Web/Resources/InvoiceResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
&lt;body style="font-family: Arial, Helvetica, sans-serif;"&gt;
&lt;div style="border: 1px solid #E0DCDA;"&gt;
&lt;div style="background-color: #E0DCDA; margin: 2px; padding: 10px;"&gt;
&lt;span style="width: 400px;"&gt;Invoice Details {{ order.number }}&lt;/span&gt;
&lt;span style="width: 400px;"&gt;Status: {{ order.status }}&lt;/span&gt;
&lt;span style="width: 400px;"&gt;Invoice Details {{ customer_order.number }}&lt;/span&gt;
&lt;span style="width: 400px;"&gt;Status: {{ customer_order.status }}&lt;/span&gt;
&lt;/div&gt;
&lt;img src="http://www.startupguys.net/wp-content/uploads/2016/03/virto-commerce-logo.png" width="150" /&gt;
&lt;div style="font-size: 12px; padding: 10px;"&gt;
Expand All @@ -134,8 +134,8 @@
&lt;span style="width: 150px;"&gt;&lt;strong&gt;Order Number&lt;/strong&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="width: 150px;"&gt;{{ order.created_date }}&lt;/span&gt;
&lt;span style="width: 150px;"&gt;{{ order.number }}&lt;/span&gt;
&lt;span style="width: 150px;"&gt;{{ customer_order.created_date }}&lt;/span&gt;
&lt;span style="width: 150px;"&gt;{{ customer_order.number }}&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="padding: 10px;"&gt;
Expand All @@ -149,7 +149,7 @@
&lt;span style="width: 100px;"&gt;&lt;strong&gt;Line Price&lt;/strong&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;table style="font-size: 12px;"&gt;
{% for line_item in order.items %}
{% for line_item in customer_order.items %}
&lt;tr&gt;
&lt;td style="text-align: center; vertical-align: top; width: 30px;"&gt;&lt;p&gt;{{ forloop.index }}&lt;/p&gt;&lt;/td&gt;
&lt;td style="vertical-align: top; width: 200px;"&gt;&lt;p&gt;{{ line_item.name }}&lt;/p&gt;&lt;p style="color: #999; font-size: 11px;"&gt;SKU: {{ line_item.sku }}&lt;/p&gt;&lt;/td&gt;
Expand All @@ -163,38 +163,41 @@
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="width: 100px;"&gt;Shipping:&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ order.shipping_total | round: 2 }}&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ customer_order.shipping_total | round: 2 }}&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="width: 100px;"&gt;Total Fees:&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ order.fee_total | round: 2 }}&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ customer_order.fee_total | round: 2 }}&lt;/span&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="width: 100px;"&gt;Order Subtotal:&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ order.sub_total | round: 2 }}&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ customer_order.sub_total | round: 2 }}&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="width: 100px;"&gt;GST:&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ order.tax_total | round: 2 }}&lt;/span&gt;
&lt;span style="width: 100px;"&gt;${{ customer_order.tax_total | round: 2 }}&lt;/span&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="font-size: 14px; width: 100px;"&gt;&lt;strong&gt;Total:&lt;/strong&gt;&lt;/span&gt;
&lt;span style="font-size: 14px; width: 100px;"&gt;&lt;strong&gt;${{ order.total | round: 2 }}&lt;/strong&gt;&lt;/span&gt;
&lt;span style="font-size: 14px; width: 100px;"&gt;&lt;strong&gt;${{ customer_order.total | round: 2 }}&lt;/strong&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="width: 300px;"&gt;&lt;/span&gt;
&lt;span style="width: 100px;"&gt;Currency:&lt;/span&gt;
&lt;span style="width: 100px;"&gt;{{ order.currency }}&lt;/span&gt;
&lt;span style="width: 100px;"&gt;{{ customer_order.currency }}&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</value>
</data>
<data name="Subject" xml:space="preserve">
<value>Invoice for order - &lt;strong&gt;{{ customer_order.number }}&lt;/strong&gt;</value>
</data>
</root>

0 comments on commit 08cee42

Please sign in to comment.