Comments

akalyptos created an issue. See original summary.

jsacksick’s picture

We could probably create a service for that, but not sure what action would call it... We probably need to expose a checkbox on the order invoice generate page that says "Email the invoice to the customer" or something.

Patches are welcome :).

archnode’s picture

Status: Active » Needs review
StatusFileSize
new12.45 KB

I prepared a patch that adds an option to the generate form to send an email with attached pdf to the invoice email.

Maybe this could be coupled to a new workflow transition "confirm" which sits between "draft" and "pending"? We could use the transition to make triggering the mail optional per invoice type (analogous to order type and notification).

jsacksick’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This needs tests and a few changes:

  1. We should add a setting on the invoice type to allow sending an email automatically when an invoice is being generated
  2. This need tests
  3. Unsure whether "confirmation" makes sense, but probably...

I haven't manually had time to manually test the patch yet.

czigor’s picture

StatusFileSize
new12.43 KB
new468 bytes

Fixing a typo. Tested the patch locally manually with Mail Safety module, it works as expected.

jsacksick’s picture

Is this the wrong interdiff/patch? I don't really see any change there?

czigor’s picture

The patch just removes an excess comma after the last argument that caused some syntax error.

archnode’s picture

I made following further additions:

  • Added the "confirm" state transition (triggered on invoice creation) - analogous to commerce order mail notification (also triggered by a state transition from draft).
  • Added settings to invoice type
  • Added event subscriber to trigger the mail
  • Use filename generation for mail attachment filename
lisastreeter’s picture

@archnode Sorry I didn't see your new patch until just now. I've been mostly working on test coverage, but it looks like there's considerable overlap in our two updates. I can review your patch and work on combining the two, but for now I'm just going to post this patch as-is so that I can verify that the tests work here and not just locally.

lisastreeter’s picture

StatusFileSize
new55.17 KB
new3.34 KB
new49.05 KB

I've reviewed patches 8 and 9 for differences and fixed coding standards issues. I'll attach that interdiff.

In patch 9, the invoice confirmation email is sent when an invoice is inserted (created and saved). In patch 8, the email is sent when a new "confirm" transition is executed. I started to change patch 9 to use the new workflow transition but then I realized that in the invoice generation method, the "confirm" transition is automatically triggered right before the newly generated invoice is saved. So I'm not sure we actually need the new transition when the "insert" event occurs at the same time.

In comparing the two patches, I also found a bug in patch 9 related to how the attachment was added to the email params. I updated that to match patch 8. Automated tests are working correctly, but it would be great to have someone confirm that the email is properly generated on an actual site. (I haven't yet set up a print engine on my local dev site.)

Patch 9 also pulls some of the code into a new service that can be used by both the Download controller and the Email confirmation service. Otherwise, most of the differences seem to be mostly naming.

lisastreeter’s picture

Issue tags: -Needs tests

Removing the "needs tests" tag.

jsacksick’s picture

The problem with sending the invoice email on insert is that we don't even check the invoice state, so the transition might make sense after all...

I won't have time to review this today, but hoping to do that at the end of this week.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new53.33 KB
new22.01 KB

Ok, I've been reviewing this and made some changed to the patch. I refactored the tests, I'm now using the transition, but the only problem I see with using the transition is that we might also want to send the invoice when it's paid... But if we react to the "confirm" transition, and the "paid" transition at the same time, two emails could be sent for the same invoice during the same request...

I've been trying to test this manually, but couldn't for some reason.

jsacksick’s picture

ok, I'm not getting the attachment with the email.

jsacksick’s picture

StatusFileSize
new54.55 KB
new9.24 KB
new146.3 KB

Ok, I fixed several issues, and managed to get the invoice confirmation email.

Sending the email right away from the subscriber was causing issues, because it's sent during a transition, and calling savePrintable() would save the invoice causing the transition to be triggered twice (2 emails were sent, and sometimes none)...

So I copied the PaymentOrderUpdated approach, and also fixed the attachments...

jsacksick’s picture

Issue summary: View changes
StatusFileSize
new49.25 KB

jsacksick’s picture

Status: Needs review » Fixed

Committed, thanks everyone!

  • jsacksick committed 2f9e03e on 8.x-2.x
    Issue #3089861 by jsacksick, lisastreeter, archnode, czigor: Provide an...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mandus.cz’s picture

Issue summary: View changes

I get emails when the invoice is not paid.
Once the payment is marked as complete and I create an invoice, the email is not sent.
How do I fix it? (invoice should always be sent)

mindhunter75’s picture

Issue summary: View changes

Thank you very much for this great patch!

When i generate an invoice manually, the invoice is send immediately, which is very nice. I'm very glad with it!

But when activate "Invoice when the order is placed" on /admin/commerce/config/order-types/default/edit, no invoice is send to the customer.

Is there a way to achieve this? So that customers get the invoice right after the placed an order?

Thank you in advance and kind regards!

filipetakanap’s picture

I need for the module to auto-send invoices only when "paid"... any help?

rgeerolf’s picture

I just discovered that the auto-send invoices do work for me but only when I use a default commerce payment gateway. If I use the gateway provided by commerce_mollie, it does not auto-send the invoice. Not sure if this is an issue related to commerce_invoice or to commerce_mollie.

Maroela’s picture

Component: Code » Miscellaneous
Category: Feature request » Support request
Priority: Normal » Critical

Okay so let me rephrase ... So when my site is in maintenance mode and a purchase is made on the site, the site sends an email with the attached invoice "invoicenumber-en-pending.pdf".

But when in live mode testing, nothing is send.

When i go to the "Invoices" and download an invoice that has state "paid" the invoice is name "invoicenumber-en-paid.pdf". I need this to be sent after successfull payment to the client, instead now i have to maually download this pdf after every payment.

Any help!!

marcom2021’s picture

@rgeerolf
I'm having the same issue as you, did you find a solution?

Default payment auto sends the invoice, but when I use Commerce Mollie it does not.