Hello All, I have been working on a Drupal offsite payment module. I want to display additional information related to order (like transaction id, merchant reference number etc that we get in response from gateway side)in the order completion message section. I have attached screenshot for reference. 

Click here

What I did: 

-> Created 'templates' folder inside root directory of my module & Override the "commerce-order-receipt.html.twig". The path is modules/commerce_latpay/templates/commerce-order-receipt.html.twig. Then cleared cache.

But the changes are not reflecting, not sure why? Can anyone guide me, what wrong am I doing and what is the correct way of achieving this? 

what I know:

Click here

-> Please note I already know that the order completion message can be customised by editing the default checkout pane in "admin/commerce/config/checkout-flows/manage/"  but I need to do this programmatically as this module is going to be published publicly for free in future. 

I would greatly appreciate any help. Thanks in advance.

Comments

wombatbuddy’s picture

You may try to implement the hook_theme() in YOUR_MODULE.module file.

pgdev’s picture

Hi, Thanks for the response. However I have already tried hook theme() , it doesn't make any change. The order messages is still same. Look at my .module file code; 
 

/**
 * Implements hook_theme().
 */
function commerce_latpay_theme($existing, $type, $theme, $path) {
  return [
    'commerce_order_receipt' => [
      'variables' => [
        'order' => NULL,
        'transaction_id' => NULL,
        'merchant_ref_number' => NULL,
      ],
      'template' => 'commerce-order-receipt',
    ],
  ];
}
wombatbuddy’s picture

I hope that you rebuild the caches.
It's seems the 'template' => 'commerce-order-receipt', is redundant. Also, you may try to create the unique template by implementing the hook_theme_suggestions_HOOK().

pgdev’s picture

yeah, I clear cache every single I time modify the file. I also implemented the hook_theme_suggestions_HOOK(). Created unique templates too but nothing changes. I really don't understand what am I doing wrong. Here's my .module file code:
 

/**
 * Implements hook_theme_suggestions_HOOK() for commerce_order_receipt.
 */
function commerce_latpay_theme_suggestions_commerce_order_receipt(array $variables) {
  $suggestions = [];
  
  // Get the order object from the variables.
  $order = $variables['order'];
  
  // Add a suggestion based on the order status.
  $status = $order->getState()->getId();
  $suggestions[] = 'commerce_order_receipt__' . $status;

  return $suggestions;
}


/**
 * Page callback to display order receipt for successful payments.
 */
function commerce_latpay_success_orders_page() {
  // Load orders with status code "00" (success).
  $query = \Drupal::entityQuery('commerce_order')
    ->condition('state', 'completed')
    ->condition('field_status_code', '00');
  $order_ids = $query->execute();

  // Load the orders.
  $orders = \Drupal\commerce_order\Entity\Order::loadMultiple($order_ids);

  // Render the template with the orders.
  return [
    '#theme' => 'commerce_order_receipt_success',
    '#orders' => $orders,
  ];
}

click here