Add a view mode selection for commerce order confirmation emails (by order type)

Created on 4 November 2024, about 1 month ago

Problem/Motivation

Currently, commerce order confirmation emails always seem to be sent in default order type display mode.
This is not totally the "Drupal way", where you'd expect to be able to create a view mode to render the order in, when sending the email. Of course, only as optional opt-in.

This needs two things:
- Being able to add a custom view mode for order types (already possible)
- A setting to select the view mode to actually render the emails in (connect the new view mode, which should typically be called "mail" for example, but could also be named "herbert" to the email sending.

Steps to reproduce

Try to change the order or display of order fields for the order confirmation email.
See that it's not yet possible.

Proposed resolution

Add a display mode selection in admin/commerce/config/order-types/default/edit for the order confirmation emails.

Render the order and its fields in the selected view mode, when sending the email
Pass the selected view mode to the template as variable

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

3.0

Component

Order

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • 🇮🇱Israel jsacksick

    First of all, there is no such thing as a "Major" feature request.
    Furthermore, we don't even use the "default" view mode there, there is just a set of fields we're printing and additional information that is injected via preprocess hooks.

    I don't think we can make it as easy as simply render the order in a given view mode.
    Or maybe we'd need to create a receipt view mode, but I guess that is a disruptive change at this point.
    That is something you can easily achieve on our own.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks for the quick reply @jsacksick and sorry, priority was a fat-finger 😉

    Just to explain how I came here: The display settings differ between shop display and email display, for example the labels should not be inline in the email and for some fields other formatters should be used.

    Of course, that could all go into the template, but isn't very Drupal-way. Mail styling and template are always some kind of special and I understand that it won't make sense to simply render the full order entity, but even at the field rendering level it might be helpful to define the display mode to use for the email(s).

    So please decide to keep this closed or re-open it as feature request for the future. I was just wring what I would have expected as the Drupal way here. Thanks!

Production build 0.71.5 2024