Full integration with commerce module

Created on 24 March 2022, over 2 years ago
Updated 22 May 2023, over 1 year ago

Commerce currently works with Symfony Mailer, but the integration is limited. Effectively Commerce is still building the email, and Symfony Mailer is only transporting it. If we add an EmailBuilder for Commerce then we can use all of the features of Symfony Mailer:
Twig templates & variables, Mailer Policy (for addresses, subject, body), rendering, language switching, etc. This would pave the way for removing the corresponding code from Commerce.

The commerce template commerce-order-receipt.html.twig is quite long (150 lines) and is effectively rendered HTML. The natural approach in Symfony Mailer would be to use Drupal mechanisms more:

  • Put the CSS in a CSS file which is part of a library - hence easy to theme
  • Render the order entity using formatters to generate markup for fields
  • Use "Manage Display" settings to control which fields are displayed and their order
  • The template can then be short and simple, with only any wrapping text

Original summary

I have create a new policy for commerce order email. But when I type tokens or twig code does not converted to values of them. Typed as clear text. Is something that I have to enable? The other examples that the module have produce by installation, register email etc (that use tokens as I have see) works ok and transform tokens to values at sending emails.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇷Greece tarasiadis

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom adamps

    The problem with other keys like 'shipment_confirmation' should now be fixed.

  • 🇬🇧United Kingdom adamps
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    4 pass, 2 fail
  • 🇬🇧United Kingdom adamps
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    5 pass
  • 🇬🇧United Kingdom adamps

    Another reroll

  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom adamps
    • AdamPS → committed 9198f976 on 1.x
      Issue #3271421 by AdamPS: Full integration with commerce module (fix...
  • Issue was unassigned.
  • 🇬🇧United Kingdom adamps
  • 🇬🇧United Kingdom adamps

    Sorry this issue was eventually fixed in 3 commits

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    5 pass
  • 🇬🇧United Kingdom adamps

    New patch fixes some missing config defaults

  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom adamps

    Sorry this issue was eventually fixed in 4 commits

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    This is awesome progress! I hope i can soon-ish leverage and test this in a project.

    There are some comments in CommerceOrderEmailBuilder code that Commerce Core may need some adjustments, too.
    Does this mean that this integration conflicts with the existing integration?
    Does this need additional followups for Commerce Core, or are some on the way?

    + * @todo Notes for adopting Symfony Mailer into commerce. It should be possible
    + * to remove the MailHandler service and classes such as OrderReceiptMail. The
    + * commerce_order_receipt template could be retired, switching instead to use
    + * email__commerce_order_type__receipt or by editing Mailer Policy for
    + * commerce_order_type.
    
  • 🇬🇧United Kingdom adamps

    @geek-merlin
    This issue adds integration of Commerce and Symfony Mailer by adding code to Symfony Mailer. It's complete and working (as far as I know😃) without any further changes to Commerce.

    Those comments relate to a theoretical future date when Commerce might decide to adopt Symfony Mailer by changing code in Commerce (after which the code added in this issue could be removed).

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed over 1 year ago
  • 🇨🇦Canada jmee Canada

    Just applied the patch and find the changes for "Commerce order" to work pretty much as expected, awesome! Thanks for this patch!

    I'm having issues trying to use the new "Commerce order" policy type, it seems that the email is using the commerce_order.html.twig template, which is the default entity display for the order entity.

    My use case: I have a functioning template in my theme called commerce-order-receipt.html.twig and I was hoping to use a mailer policy to customize the BCC and Subject depending on the order type, but to continue using the Body from my custom template (ie. not add a body element to the policy).

    In the theme debug:

     THEME HOOK: 'commerce_order' 
     FILE NAME SUGGESTIONS:
       * commerce-order--5--email.html.twig
       * commerce-order--5.html.twig
       * commerce-order--download--email.html.twig
       * commerce-order--download.html.twig
       * commerce-order--email.html.twig
       x commerce-order.html.twig
    

    If I customize any of these templates, I'll be changing how the site displays orders. I also don't have access to the same variables as the commerce-order-receipt template.

    This template is called by email.html.twig:

     THEME HOOK: 'email' 
     FILE NAME SUGGESTIONS:
       * email--commerce-order-type--resend-receipt--download.html.twig
       * email--commerce-order-type--resend-receipt.html.twig
       * email--commerce-order-type.html.twig
       x email.html.twig
    

    Again, not really a feasible option.

    It seems like the intended use case for this patch is new users of Commerce, so existing users of commerce and symfony_mailer may have a hard time taking advantage of the features. In order to use the Commerce order policy type, the body content *must* be added as a policy element and it is not possible to use a twig template -- is that correct ?

    If so, I think there's a good argument to change this behaviour and instead fall back to the default commerce-order-receipt template

  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands

    @jmee if you experiencing any new problems. Please open a new ticket as follow up.

Production build 0.71.5 2024