Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate invoice to string for e-mail attachment #60

Open
lilith opened this issue Oct 3, 2014 · 15 comments
Open

Generate invoice to string for e-mail attachment #60

lilith opened this issue Oct 3, 2014 · 15 comments

Comments

@lilith
Copy link

lilith commented Oct 3, 2014

How can this system be called to generate a binary string of the PDF from an arbitrary ActionMailer?

@davekiss
Copy link

davekiss commented Nov 6, 2014

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

@futhr
Copy link
Contributor

futhr commented Dec 17, 2014

You welcome to add it to the wiki if you found a good solution.

@lilith
Copy link
Author

lilith commented Dec 17, 2014

Thanks, this helped us a lot!

@paulhuisman
Copy link

Nice one, thanks!

@alepore
Copy link
Member

alepore commented Apr 3, 2015

👍 on wiki, but this could also become an optional built-in feature with a enabling preference!

@tvdeyen
Copy link
Contributor

tvdeyen commented Apr 3, 2015

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.

@alepore
Copy link
Member

alepore commented Apr 3, 2015

nice, but it will need to stay in sync with order changes (like a cache..)

@tvdeyen
Copy link
Contributor

tvdeyen commented Apr 3, 2015

What do you exactly mean by that? Could you provide an example? That would be great. Thanks

@alepore
Copy link
Member

alepore commented Apr 3, 2015

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.

@tvdeyen
Copy link
Contributor

tvdeyen commented Apr 3, 2015

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 ;)

@alepore
Copy link
Member

alepore commented Apr 3, 2015

Yes, makes sense.
I was thinking using it just like the pdf render of the order details and not as a legal document...

@tvdeyen
Copy link
Contributor

tvdeyen commented Apr 3, 2015

Yes. It makes definitely sense to have two different emails.

@tvdeyen
Copy link
Contributor

tvdeyen commented Apr 7, 2015

@alepore I published my PR, please review and provide feedback. Thanks

@rposborne
Copy link

@tvdeyen How did you all ensure that these files were available over multiple nodes? I need to comply with german laws as well :(

@tvdeyen
Copy link
Contributor

tvdeyen commented May 7, 2015

@rposborne Do you mean multiple app servers? Then, I would prefer to use an NFS mount to store the files on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants