Purpose of order receipt theme suggestions/overrides

Created on 12 March 2024, about 1 year ago

Problem/Motivation

Just want to report that having the `hook_theme_suggestions_HOOK_alter` and receipt template in this module provided a poor DX for me. It took me a minute to realize this module was overriding the commerce (and my theme) templates because of the suggestion. Also, the template appears to be the exact same, so I'm not sure why this exists.

Proposed resolution

Remove the `hook_theme_suggestions_HOOK_alter` and template, let theme decide when and how to override the template.

You can close as designed or provide a reason for this since I'm not seeing. Just reporting that it caused me some extra time.

Thanks,
Andy

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States andyg5000 North Carolina, USA

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

Merge Requests

Comments & Activities

  • Issue created by @andyg5000
  • πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

    Hi - thanks for the feedback. I wrote that method 7 years ago, when this was a customization for client and not yet contributed, so my best guess is I needed it for that work.

    Perhaps the best DX solution at this point is to remove the template but leave the suggestion, since Commerce adds the order bundle type but not the gateway ID as a suggestion

  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

    A closer look and I have a better answer. There is a small but important difference between the templates.

    The template at commerce/modules/order/templates/commerce-order-receipt.html.twig has this block:

    {% block payment_method %}
      {{ payment_method }}
    {% endblock %}
    

    And the template in this module has:

    {% block payment_method %}
      {{ payment_method }}
      {{ payment_instructions }}
    {% endblock %}
    

    The payment instruction info is preprocessed in commerce_purchase_order_preprocess_commerce_order_receipt. I've changed the template in this module to a clear twig block override. Please would this have saved you time?

  • πŸ‡ΊπŸ‡ΈUnited States andyg5000 North Carolina, USA

    Hey Shawn,

    Thanks for making the update and explaining the preprocess. I think all of this makes sense.

    Thanks,
    Andy

  • πŸ‡ΊπŸ‡ΈUnited States rclemings

    Related: It looks as if the system is using this module's receipt template for all orders, even those that don't use the purchase order gateway.

    Is that correct/intended?

    If so, would it make sense to add the theme suggestions only for purchase orders? Maybe wrap it in something like:

    if ($variables['order_entity']->get('payment_gateway') == "purchase_order")  {
    }

    I'd like to customize the template for other payment methods and this is a complication.

Production build 0.71.5 2024