Provide a UI to enter / edit order receipt header and footer texts

Created on 27 August 2024, 3 months ago
Updated 12 September 2024, 2 months ago

Problem/Motivation

Currently, for shop owners it needs programming / theming to be able to add textual information for order receipt / confirmation emails configured at order types (e.g. /admin/commerce/config/order-types/default/edit)

If the "Email the customer a receipt when an order is placed" checkbox is enabled, you're able to enter an email address to receive a copy and enter the email subject using tokens. This is already very helpful, but clients typically need to at least add some textual information to the order order receipt / confirmation emails.

Might be a friendly introduction sentence or terms and conditions in the end. As tokens are also available, this already solves many typical use-cases.
For more complex cases, using https://www.drupal.org/project/commerce_email is an option and / or altering the twig template or using hooks.

But for a better out-of-the-box experience (and many cases I know about for smaller shops) it would be good enough to be able to configure a header and footer text in the configuration.

Steps to reproduce

Try to add terms and conditions (manually or by tokens) or a friendly sentence to a commerce order order receipt / confirmation email as shop-owner. It's not possible currently without coding or complex custom modules.

Proposed resolution

If the "Email the customer a receipt when an order is placed" checkbox is enabled, add two text areas below the subject input:

  • E-Mail heading text
  • E-Mail footer text

Move the "Thank you for your order" text (https://git.drupalcode.org/project/commerce/-/blob/8.x-2.x/modules/order...) from the twig template to the footer text area as example.

Provide two new twig variables, e.g.

  • {{ header_text }}
  • {{ footer_text }}

for the commerce-order-receipt.html.twig template and place them in appropriate regions in the template.

Have happy Drupal Commerce users by a better out of the box experience for shop owners.

Feature request
Status

RTBC

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    Would be great to have short maintainer feedback, if they'd like this functionality to be implemented, then we'll prepare it. We have two customers interested.

  • 🇮🇱Israel jsacksick

    Valid feature request IMO, one potential "problem" I can think of would be translability, but config entities are translatables, so it'd be a matter of ensuring the translated header/footer is injected into the receipt.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thank you for the feedback @jsacksick! So we'll start implementing this.

    Yes, this needs to be passed to the template in order language. But I think that should be solvable, hopefully. The other already existing content of the receipt already need the correct language for all contents. As there's already an implementation for the subject, that's either solved already or not yet solved. I hope for the first! :)

    Header + Footer is alright?
    I was thinking about a token / placeholder based "body" field, but I think header and footer is more bulletproof, good enough and what the store owners need around the table of order items etc.

    Furthermore, I think if that's not enough, it's valid to have a developer or themer for more custom stuff.

    Once you give us green light, we'll implement this! :)

  • 🇮🇱Israel jsacksick

    Only thing is... Not sure it is "easy" to understand where the text is going to be output from the admin interface context.

    Also for example, in the footer there is:
    {{ 'Thank you for your order!'|t }}, once we implement this, we should either skip this if the footer is not empty, or we could set this as the footer text the default order type provided.
    Not sure what is the best solution.

  • 🇩🇪Germany Anybody Porta Westfalica

    Yeah, I think we should move it into the footer field, it's a good example and customizable then!
    For existing installations, I'd use an update hook to inform the users about the change and possible requirement to update their theme override.

    I think it would be best to have this in 3.x as it's kind of (little) breaking change due to the new template variables. Fine with the new major release then, but of course we'll do our best to keep the change as minimal as possible.

  • Assigned to lrwebks
  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany lrwebks Porta Westfalica
  • Merge request !323Resolve #3470548 "Provide a ui" → (Open) created by lrwebks
  • Pipeline finished with Failed
    3 months ago
    Total: 342s
    #272396
  • Pipeline finished with Failed
    3 months ago
    Total: 613s
    #272425
  • Pipeline finished with Failed
    3 months ago
    Total: 743s
    #272500
  • Pipeline finished with Failed
    3 months ago
    Total: 919s
    #272527
  • 🇩🇪Germany Anybody Porta Westfalica

    Tests fail with: "Undefined array key "Your order has been placed.""

    Also please make this a non-draft, seem only the creator can do that. :)

  • 🇮🇱Israel jsacksick

    Also please make this a non-draft, seem only the creator can do that. :)

    What difference does it make? Seems the tests are still running? Also because the tests are failing, this is technically not ready.

  • 🇩🇪Germany Anybody Porta Westfalica

    What difference does it make? Seems the tests are still running? Also because the tests are failing, this is technically not ready.

    In the past I think the tests were not executed automatically, when this was a draft?

    The reason mainly was, that this is blocked as "Draft" to the person / creator who set that flag. I think we should focus on the Drupal.org issue status mainly, until it's all GitLab. I didn't say draft is wrong :)

  • 🇩🇪Germany Anybody Porta Westfalica

    I left some comments on the MR, maybe @jsacksick also would like to take a look? (And see if he disagrees somewhere or has a stronger opinion)

  • Pipeline finished with Failed
    3 months ago
    Total: 491s
    #273175
  • Pipeline finished with Failed
    3 months ago
    Total: 622s
    #273280
  • 🇩🇪Germany Anybody Porta Westfalica

    @lrwebks further tasks:

    1. To come closer to the reasons for the failing test, please create a dedicated test with custom header and footer text set in config
    2. Update hook is missing for existing sites.
  • Pipeline finished with Canceled
    3 months ago
    Total: 590s
    #273381
  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany lrwebks Porta Westfalica
  • Pipeline finished with Failed
    3 months ago
    Total: 614s
    #273400
  • Pipeline finished with Failed
    3 months ago
    Total: 466s
    #273404
  • Pipeline finished with Failed
    3 months ago
    Total: 444s
    #273417
  • Pipeline finished with Failed
    3 months ago
    Total: 414s
    #273428
  • Pipeline finished with Failed
    3 months ago
    Total: 467s
    #273435
  • Pipeline finished with Failed
    3 months ago
    Total: 605s
    #273458
  • Issue was unassigned.
  • 🇩🇪Germany Anybody Porta Westfalica

    Okay the last test error is really crazy. It fails now, because the french text for the payment method "Paiement à la livraison" is now line-breaking. But we didn't touch it at all.

  • Assigned to Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    Perhaps it would make sense to use {% apply spaceless %}{% endapply %} (https://symfony.com/blog/better-white-space-control-in-twig-templates) in the mail template to clean up the whitespaces in general for the text-only result?

    Or we would need to remove \n's from the tests?

    I guess this is caused, because the MR fixed the wrong indentation in that file and that's just the one space too much for it.

  • Pipeline finished with Failed
    3 months ago
    Total: 1150s
    #273477
  • 🇩🇪Germany Anybody Porta Westfalica

    anybody changed the visibility of the branch 3.0.x to hidden.

  • Pipeline finished with Success
    3 months ago
    Total: 5368s
    #273531
  • Issue was unassigned.
  • 🇩🇪Germany Anybody Porta Westfalica

    Ok that's it... the spaces messed up the text-only version.

    If @jsacksick is fine with that, we can either fix it here in combination or do the clean-up in a separate issue we merge before.

    Seems to me as if it's generally useful to remove whitespace in twig email templates. I think I remember a similar case from the past in a different module.

  • Status changed to RTBC 2 months ago
  • Works great, RTBC from my side, ready for maintainer review and feedback as of #18!

Production build 0.71.5 2024