Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there a way to change the name of the generated invoice.
Ex : store-name-facture-1234 instead of 1234-fr-paid.pdf ?
Thanks in advance
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff_15-17.txt | 3.58 KB | jsacksick |
#17 | 3106014-17.patch | 9.06 KB | jsacksick |
|
Comments
Comment #2
jsacksick CreditAttribution: jsacksick at Centarro commentedUnfortunately, this isn't configurable atm (patches are welcome)... In the meantime, you could swap the commerce_invoice.print_builder service with your own, and just override the
generateFilename()
method.Comment #3
selinav CreditAttribution: selinav commentedok thank you
Comment #4
archnode CreditAttribution: archnode at Signal commentedThe attached patch adds a hook to alter the filename on invoice generation.
Currently the generated filename is used to determine if an invoice already has an invoice file generated. This seems a bit brittle and could lead to orphaned files if the name generation changes. This patch also adds a new invoice file reference to the invoice entity that saves the file reference.
Comment #6
archnode CreditAttribution: archnode at Signal commentedUpdated patch to use entityreference field type.
Comment #7
fagoThis misses the descriptoin of the params.
Tests fail with this message. I'd guess that the new entity reference to files makes the file entity type to be required in tests now. Thus the test cases need to be updated to install/add the file entity type in the setup routine.
Comment #8
jsacksick CreditAttribution: jsacksick at Centarro commentedThis mentions the paragraphs module.
Why is this line commented out?
Here the $file_name has the .pdf suffix but yet we append it to the $file_name variable returned.
Commerce tends to use events rather than alter hooks, but maybe for this "simple" need we could make an exception, not sure.
Also, for alter hooks, we're supposed to be using the
alter()
method and not invokeAll().Comment #9
jsacksick CreditAttribution: jsacksick at Centarro commentedWe should probably create a separate issue for adding the field that stores the reference to the invoice PDF, since that most probably requires writing a post update function for existing invoices...
Comment #10
archnode CreditAttribution: archnode at Signal commentedThank you for the reviews! - I updated the patch accordingly. Concerning the additional post update function: This is not needed for the functionality of this patch (as the reference will be generated if none is present).
Generally it could be handy to make sure that an invoice file exists for every invoice, no matter if it is ever explicitly downloaded.
Comment #12
jsacksick CreditAttribution: jsacksick at Centarro commentedI'm not against storing a reference to the invoice PDF, but altering the filename and adding the file reference field should be handled 2 separate issues.
Also, we don't really use alter hooks anywhere in Commerce. And we should inject the module handler if we decide to stick with the alter hook.
And we're also missing getters/setters for the field added + tests.
Comment #13
jsacksick CreditAttribution: jsacksick at Centarro commentedSee #3129042: Store a reference to the generated PDF.
Comment #14
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #15
lisastreeter CreditAttribution: lisastreeter at Centarro commentedI switched the patch from a hook to an event. I tested locally but didn't add any test coverage specific to the event since I didn't see similar testing in Commerce core.
Comment #16
jsacksick CreditAttribution: jsacksick at Centarro commentedoops :).
Patch looks good, we can test this pretty easily by adding an event subscriber in our test module, and then we can test the behavior in InvoicePrintBuilderTest.
I'm wondering if we should expand the event to allow overriding the print engine and/or the file scheme though I'm not sure that is necessary.
Comment #17
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #19
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted, thanks everyone!