Four years ago we built the checkout system in #2689549: Implement the initial checkout structure. At that time moving everything into templates was seen as a usability improvement and gave greater flexibility for controlling output. So we did not make the checkout completion message customizable – end-users could put the template into their theme and control the output as needed. This bypassed the lack of Token availability as well.
We should add the ability to make the message customizable through the interface and embedded in the pane template.
We can roughly add it this way.
$pane_form['message'] = [
'#theme' => 'commerce_checkout_completion_message',
'#order_entity' => $this->order,
'#message' => $this->configuration['message'],
];
<div class="checkout-complete">
{{ message }}
{% if payment_instructions %}
<div class="checkout-complete__payment-instructions">
<h2>{{ 'Payment instructions'|t }}</h2>
{{ payment_instructions }}
</div>
{% endif %}
</div>
We'll need to update the default configuration to maintain the following:
{{ 'Your order number is @number.'|t({'@number': order_entity.getOrderNumber}) }} <br>
{{ 'You can view your order on your account page when logged in.'|t }} <br>
That means we'll need to figure out token support upfront. We should also support text filters.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | order_complete_result.JPG | 21 KB | canardesign |
| #21 | complete_message-edit_form.JPG | 61.22 KB | canardesign |
| #14 | 3155132-13.patch | 9.95 KB | mglaman |
| #11 | Completation message.png | 156.03 KB | sumi |
| #9 | 3155132-9.patch | 8.56 KB | mglaman |
Issue fork commerce-3155132
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mglamanThere's a problem with this. We don't allow translating checkout flow configuration, so making this a configuration form value prevents it from being translatable.
Comment #3
mglamanOkay, I forgot that all configuration is translatable. However, this means sites which did not extend the template might lose translations if we moved it from Twig to the configurable message. So this backward compatibility problem needs to be reviewed.
Comment #4
mglamanWhen translating checkout flows you can only translate the label, none of the pane configurations.
We'll probably have to copy what bojanz did for product attributes:
Where
\Drupal\commerce_product\ConfigTranslation\ProductAttributeMapperprovides the overridden config edit forms.Digging into it more, the schema gets built into a form by
\Drupal\config_translation\FormElement\ListElement::getTranslationBuild.We could also get the following schema to return an instance of
\Drupal\Core\TypedData\TraversableTypedDataInterfaceand expose all translatable config in a details element.EDIT: I'm wrong, I think it will show up. We just need to define the config schema.
Comment #5
mglaman🥳 translation works, posting a patch for regression testing.
Comment #6
mglamanI began to write this but realize there is no way to alter the message to link to the order for the customer.
This feature is cool, but kind of useless without #3156489: Provide an `admin-url` token for orders.
Comment #7
mglamanHere is at least a test. It is going to at least fail as it assumes
[commerce_order:url]is the customer URL.Comment #9
mglaman🤦♂️ It's definitely failing and was definitely passing earlier because I forgot to patch the template change.
Comment #10
mglamanFixed the phpcs error: https://git.drupalcode.org/issue/commerce-3155132/-/commit/e9b8a359ac738...
Comment #11
sumi commentedTested and on backend it works as expected. All available text formats on the site are available on the field, text entered into the field is translatable through configuration translation.
When using any text format that supports html, html tags are printed as text on the frontend. In my example I just put part of the text into H2 and rest of it was in p tag.
Comment #12
mglamanGood find, @Sumi! We should test that the filter format is respected and HTML is allowed.
Comment #14
mglamanThe problem was that I passed the message value directly to Twig, which autoescaped the value 🤦♂️. Fixed: https://git.drupalcode.org/issue/commerce-3155132/-/commit/18c329b4c653e...
Using the
processed_textelement in a a render array has fixed the HTML rendering. I updated the test to reflect it as well.Comment #15
sumi commentedTested and it is working as expected.
Comment #16
mglamanThanks @Sumi for testing!
Comment #17
mglamanCommitted, 🥳
Comment #20
canardesign commentedHi ! sorry to reopen, but it is not working for me.
I edited the completion message through UI
But on /checkout/[order_id]/complete page I get the default message, even after clearing caches.
What am I missing ?
Comment #21
canardesign commentedComment #22
4kant commentedsame as #21 here.
commerce 8.x-2.30 (no dev)
Comment #23
sakonn commentedI am also facing the issue to translate it through admin interface.
When I copy the configuration manually into yml files and import it the complete message is translated.
Comment #24
sketman commentedThe same problem here. I alter the checkout completion message in UI but nothing gets changed on the site.Am I missing something? Some guidance would be highly appreciated...
My apologies, the issue is solved by copying the template file into my theme´s folder