- Issue created by @uaparac
- Status changed to Fixed
about 1 year ago 9:21pm 6 November 2023 - 🇵🇹Portugal introfini
Hi,
The related Drupal Commerce issue: 📌 Show payment instructions in the order receipt Needs work
You need to create a Twig variable that contains payment instructions. This variable can subsequently be incorporated into your email template.
Below is an example of how you might define this variable within Twig. Please note that the exact implementation may vary depending on the method you utilize to dispatch emails:
function bloom_custom_preprocess_easy_email_commerce_order_payment_method_html(&$variables) { /** @var Drupal\commerce_order\Entity\OrderInterface $order */ $order = $variables["commerce_order"]; if ($order->get('payment_gateway')->isEmpty()) { return; } /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */ $payment_gateway = $order->get('payment_gateway')->entity; /** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\HasPaymentInstructionsInterface $payment_gateway_plugin */ $payment_gateway_plugin = $payment_gateway->getPlugin(); if ($payment_gateway_plugin instanceof HasPaymentInstructionsInterface) { $payment_storage = \Drupal::entityTypeManager() ->getStorage('commerce_payment'); $payments = $payment_storage->loadMultipleByOrder($order); $payments = array_filter($payments, function ($payment) use ($payment_gateway) { return $payment->getPaymentGatewayId() == $payment_gateway->id(); }); $payment = reset($payments); if ($payment) { $variables['payment_instructions'] = $payment_gateway_plugin->buildPaymentInstructions($payment); } } }
Once you have defined the variable, you can include it in your email template using {{ payment_instructions }}
Automatically closed - issue fixed for 2 weeks with no activity.