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.
Problem/Motivation
When an order receipt is sent, the mail created always gets themed by the active theme. This results in the mail being different depending on whether the order is placed on the front, or created via the admin interface.
Proposed resolution
While not technically a dependency, the most common setup to send the HTML mails, including the receipt, is with Shiftmailer and MailSystem. MailSystem's mail manager service has a getMailTheme() method. We can check if such a method exists and use its theme setting with the same code to get the mail body themed.
Remaining tasks
User interface changes
API changes
Data model changes
Original report by [username]
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff-2984098-13-17.txt | 5.96 KB | lisastreeter |
#17 | use_mail_system_theme_for_receipt-2984098-17.patch | 17.59 KB | lisastreeter |
| |||
#5 | use_mail_system_theme_for_receipt-2984098-5.patch | 5.02 KB | s.messaris |
Comments
Comment #2
s.messaris CreditAttribution: s.messaris commentedHere is a patch implementing the proposed resolution.
Comment #4
s.messaris CreditAttribution: s.messaris commentedComment #5
s.messaris CreditAttribution: s.messaris commentedWas working in an unclean repo, this patch should apply now.
Comment #6
s.messaris CreditAttribution: s.messaris commentedComment #7
simgui8 CreditAttribution: simgui8 as a volunteer and commentedI can't reproduce,
every order I have created:
-programmatically
-anonymously
-or via admin/commerce/orders/add
are themed with with my active theme template commerce-order-receipt.html.twig
Comment #8
simgui8 CreditAttribution: simgui8 as a volunteer and commentedForget about my last comment... I must have applied #5 over some leftover...
#5 fixes the receipt theme rendering when order is placed via admin interface.
thanks
Comment #9
s.messaris CreditAttribution: s.messaris commentedChanging to rtbc as by #8.
Comment #10
mglamanIt's a bummer the mailsystem module doesn't have an interface we can check against.
Can we document that's why we have a method_exists?
I was perplexed why we'd check a method versus an instance. Then I realized it is because of \Drupal\mailsystem\MailsystemManager::getMailTheme.
\Drupal\mailsystem\MailsystemServiceProvider swaps the mail plugin manager.
Feel free to fix and put back to RTBC.
Comment #11
bojanz CreditAttribution: bojanz at Centarro commentedHow can we write a test for this?
Comment #12
mglamanWe'd need to uhh. Add
@requires mailsystem
to a test. And. I really don't know, I guess. This requires a theme having an overridden template.So we would need to:
- Provide a custom theme in the test directory
- Provide an overridden template which has some kind of custom adjustments
- Set the mailsystem to be the custom template, but the current / default template is bartik
- Send email
- Assert content has custom adjustment in template
Comment #13
lisastreeter CreditAttribution: lisastreeter at Centarro commentedIn this patch, I've added a comment in OrderReceiptSubscriber for the method_exists() usage and written a test, as described in Matt's comment #12.
Interdiff is doing weird things when I try to create the file the correct way, so I'm attaching a "backwards" interdiff for the changes "from" patch #13 "to" patch #5. I've only added to the patch, so just read all the "-" lines as "+" lines. Sorry about that...
Comment #14
lisastreeter CreditAttribution: lisastreeter at Centarro commentedComment #15
mglamanInstead of false, I feel like we could just do
NULL
. That way we can remove$mail_theme &&
checks and it's just "did this equal the returned string".Yay, we have a test! However, the test needs to be run locally and we need manual testing, anyways from subscribers of this issue.
Comment #16
bojanz CreditAttribution: bojanz at Centarro commentedMissing one-line description.
Two new arguments were added to the constructor, but the docblock wasn't expanded with new @param lines.
I agree with Matt, NULL is a more natural default.
This still didn't make it clear to me. Let's do:
Nesting two long statements inside each other impacts readability for no gain. Let's do initTheme() on its own line.
I don't think we should explain PHP syntax here (why/how finally works).
Needs better description.
Class properties cannot be snake_case. And we aren't even using it in setUp(), so we don't actually need a class property.
This is repeated in both tests, we can just set order_number when constructing the order in setUp().
Comment #17
lisastreeter CreditAttribution: lisastreeter at Centarro commentedThanks Matt and Bojan. Here is the updated patch.
Comment #18
bojanz CreditAttribution: bojanz at Centarro commentedThanks, looks good now.
I need to fix this pre-commit. assertEqual() is deprecated, we need to use assertEquals() like elsewhere (and the params are reversed).
Comment #19
lisastreeter CreditAttribution: lisastreeter at Centarro commentedOops! Missed that. Thanks for pointing it out. (And I'm always reversing the params...have to remember to double-check that whenever I write tests.)
Comment #20
lisastreeter CreditAttribution: lisastreeter at Centarro commentedComment #21
s.messaris CreditAttribution: s.messaris commentedThanks to everyone for your work on this! What else is needed to have this commited? Looks good to me.
Comment #23
bojanz CreditAttribution: bojanz at Centarro commentedThanks, everyone!
Comment #25
pietermouton CreditAttribution: pietermouton commentedCan this one be added in a release? I'm working on the latest dev version and I can't apply this patch with composer. (I guess because of other changes in dev).