Attaching invoice to email?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi guys,

Is there any easy way or any setting to attach the generated PDF invoice to the email so the user receives it when the order is done?

If there is no setting, is there any intention to include this in a feature release? I have a feeling that customizations for this in the code are not very easy...
11 years ago
Does anyone know how to do something like this?  I am interested as well...  Thanks!
11 years ago
My approach to this situation was not to attach directly the pdf to the email because this require some headache (emails being saved in DB means you need to save pdf in DB which is ugly) but:

1. Include a link in the orderConfirmationEmail like this:

Please download your invoice from <a href="http://www.myshop.com/orderdetails/pdfasguest/%Order.OrderId%">here</a>

(you do this in admin - messages template)

2. Add a new route for this link in RouterProvider.cs in //orders section


routes.MapLocalizedRoute("GetOrderPdfInvoiceAsGuest",
                           "orderdetails/pdfasguest/{orderId}",
                           new { controller = "Order", action = "GetPdfInvoiceAsGuest" },
                           new[] { "Nop.Web.Controllers" });


3. Add a method for this route in OrderController.cs

public ActionResult GetPdfInvoiceAsGuest(string orderId)
        {
            string orderIdDecoded = DecodeFrom64(orderId.ToString());

            var order = _orderService.GetOrderById(Int32.Parse(orderIdDecoded));
            if (order == null || order.Deleted)
                return new HttpUnauthorizedResult();

            string fileName = string.Format("order_{0}_{1}.pdf", order.OrderGuid, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
            string filePath = string.Format("{0}content\\files\\ExportImport\\{1}", this.Request.PhysicalApplicationPath, fileName);
            _pdfService.PrintOrderToPdf(order, _workContext.WorkingLanguage, filePath);
            var pdfBytes = System.IO.File.ReadAllBytes(filePath);
            return File(pdfBytes, "application/pdf", fileName);
        }


- as you notice, the order id in the link is decoded from base64 because I put orderId in the link to be base64 encoded to not be plain text easy-readable by a user (of couse, you can increase the security here if you want)

4. Last step, build Order.Id parameter for the link where rest of the parameters are built: MessageTokenProviders.cs, AddOrderTokes method:

 tokens.Add(new Token("Order.OrderId", EncodeTo64(order.Id.ToString())));


That's all....

Hope to be helpfull for someone.
8 years ago
Hi,

I'm trying to implement this solution.
In the MessageTokenProvider I've added "tokens.Add(new Token("Order.OrderId", EncodeTo64(order.Id.ToString())));"

which gives me the following error:
Error  CS0103  The name 'EncodeTo64' does not exist in the current context

Also "DecodeFrom64(orderId.ToString());"
responds with The name 'EncodeTo64' does not exist in the current context

I'm using NopCommerce 3.40
running Visual Studio 2015

Am I missing something?

Kind regards
8 years ago
Add the reference or Implement  of the following method
DecodeFrom64(orderId.ToString());
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.