Hi,
i am running a kickstart 2.12 and have some trouble with !order-summary.
The original message is working for me, even after altering the message.
But if I clone the message type and change the related rule to use the new message type the !order-summary field fails. All other tokens are working. In all languages and with different rules too.
There are only manual payment methods (cash on delivery, pay in person, bank transfer).

Comments

balintbrews’s picture

Category: Bug report » Support request
Status: Active » Fixed

!order-summary is not a token, it's injected as an argument of the Message entity. Commerce Message implements hook_message_presave() to do that.

As you can see it checks the message type, which is different for you, since you cloned the original one. So all you have to do is to implement the same hook and do the same job, but check against your own message type.

Status: Fixed » Closed (fixed)

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

khumbu’s picture

This is what I did, to use !order-summary in my cloned Message

In commerc_message.module you can find following code, the bold italic is my change to use !order-summary in another message

function commerce_message_message_presave($message) {
if (!empty($message->mid) || ($message->type != 'commerce_order_order_confirmation' && $message->type != 'commerce_order_order_confirmation_cloned_' )) {
return;
}

$message->arguments['!order-summary'] = array(
'callback' => 'commerce_message_order_summary',
'pass message' => TRUE,
);
}

peter caritas’s picture

Just to clarify, you wouldn't want to edit the commerce_message.module file because upgrades to that module would write over your changes. The way to accomplish this is through implementing hook_message_presave() in a custom module:

/**
* implement hook_message_presave 
* add !order-summary to custom message type
*/
function mymodule_message_presave($message) {
	
	if($message->type == 'mycustom_order_confirmation') 
	{
	    $message->arguments['!order-summary'] = array(
    	        'callback' => 'commerce_message_order_summary',
    	        'pass message' => TRUE,
  	    );
  	}
}
millionleaves’s picture

#4 solved this problem I was having with a cloned order email - thanks. Nice easy solution.

millionleaves’s picture

On further reflection, this could easily be modified to create additional "variables" for insertion into your message types.

In my case, I needed to include some custom fields in the admin order notification. I made a second version of the Cart Summary view and used the module below to create !order_summary_admin. This module code limits the use of !order_admin_summary to just the Admin notification message type. But you could also create a more generic version of the code below that allowed you to use the output of any view in any message type.

<?php

function commerce_message_order_summary_override_message_presave($message) {
    if ($message->type == 'commerce_order_admin_order_notification') {

	    $message->arguments['!order-summary-admin'] = array(
	        'callback' => 'commerce_message_order_summary_override_order_summary',
	        'pass message' => TRUE,
	    );		
    }

}

/**
 * Message callback; Show order summary.
 *
 * @param $message
 *   The Message entity.
 */
function commerce_message_order_summary_override_order_summary(Message $message) {
    $wrapper = entity_metadata_wrapper('message', $message);
    $view = views_get_view('commerce_cart_summary_cp');
    $view->set_arguments(array($wrapper->message_commerce_order->getIdentifier()));
    $view->hide_admin_links = TRUE;
    return $view->preview();
}