Open lilith opened 10 years ago
This probably isn't the best way of doing it, but here's what I have implemented as a decorator.
def confirm_email(order, resend = false)
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
filename = "Invoice_#{@order.number}_#{Time.now.strftime('%Y%m%d')}.pdf"
admin_controller = Spree::Admin::OrdersController.new
invoice = admin_controller.render_to_string(:layout => false , :template => "spree/admin/orders/invoice.pdf.prawn", :type => :prawn, :locals => {:@order => @order})
attachments[filename] = {
mime_type: 'application/pdf',
content: invoice
}
subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}"
headers = {to: @order.email, from: from_address, subject: subject}
mail(headers)
end
You welcome to add it to the wiki if you found a good solution.
Thanks, this helped us a lot!
Nice one, thanks!
:+1: on wiki, but this could also become an optional built-in feature with a enabling preference!
I am currently working on a feature that has an option to store pdf as file on disk. This can then be attached to an email.
nice, but it will need to stay in sync with order changes (like a cache..)
What do you exactly mean by that? Could you provide an example? That would be great. Thanks
i mean.. orders can change after completion (think of admins manual intervention, or payment states..), and the pdf should always reflect those changes, so the old file should be invalidated and a new one created.
An Invoice must never change after sending it to the user. So the invoice may only send to the user after it is finished (the user has payed it). After that it must not change. Only if a refund happens, then the original invoice needs to be invalidated and a refund invoice has to be send to the user. German laws ;)
Yes, makes sense. I was thinking using it just like the pdf render of the order details and not as a legal document...
Yes. It makes definitely sense to have two different emails.
@alepore I published my PR, please review and provide feedback. Thanks
@tvdeyen How did you all ensure that these files were available over multiple nodes? I need to comply with german laws as well :(
@rposborne Do you mean multiple app servers? Then, I would prefer to use an NFS mount to store the files on.
How can this system be called to generate a binary string of the PDF from an arbitrary ActionMailer?