Posted on 11/04/2019 08:58:57
Hi Jens
There is no simple way to do that.
You can create a notification subscriber on the email sending of the order () and then create a PDF document using AbcPdf found in Dynamicweb - something like this:
using Dynamicweb.Core;
using WebSupergoo.ABCpdf9;
namespace Dynamicweb.Ecommerce.Examples.Notifications
{
[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.SendingConfirmationMail)]
public class EcomCartSendingConfirmationMailObserver : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
{
Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.SendingConfirmationMailArgs sendingConfirmationMailArgs = args as Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.SendingConfirmationMailArgs;
//EXAMPLE with inline markup
//Dynamicweb.Rendering.Template htmlForPdfTemplate = new Rendering.Template();
//tmlForPdfTemplate.Html = "<html><body><h1>Receipt</h1>@SomeRazorCode and regular Dynamicweb template language</body></html>";
//EXAMPLE with a razor template
//Load a template - with full html, including html, body, inline css etc. IE browser compatible
Dynamicweb.Rendering.Template htmlForPdfTemplate = new Rendering.Template("/eCom7/CartV2/Mail/pdfReceipt.cshtml");
//Create an order renderer instance
Dynamicweb.Ecommerce.Frontend.Renderer orderRenderer = new Frontend.Renderer();
//Render all order tags
orderRenderer.RenderOrder(sendingConfirmationMailArgs.Order, htmlForPdfTemplate);
//Add custom tags to the template
htmlForPdfTemplate.SetTag("RecipientEmail", sendingConfirmationMailArgs.Recipient.Address);
htmlForPdfTemplate.SetTag("ReceiptSubject", sendingConfirmationMailArgs.MailMessage.Subject);
//Create a pdf from the template - use another path for security reasons
string pathToOrderConfirmation = SystemInformation.MapPath($"/Files/System/OrderExport/Order{sendingConfirmationMailArgs.Order.Id}.pdf");
Doc theDoc = new Doc();
theDoc.AddImageHtml(htmlForPdfTemplate.Output());
theDoc.Save(pathToOrderConfirmation);
theDoc.Clear();
//Better delete the generated pdf after this...;
//Attach the pdf to the email
sendingConfirmationMailArgs.MailMessage.Attachments.Add(new System.Net.Mail.Attachment(pathToOrderConfirmation));
}
}
}
BR Nicolai