I'm trying to figure out how to set a message using code?
The content of my mails are generated by another module but I want to use the Message and Message Notify to store the mails and send the mails, since it all fits in with the existing views/logs/history functionality.
But how can I set the message data properly in code?
I had a good look at the Examples in Message but I still miss some parts.
Case: I want to extend the "commerce_order_created" message type, so I added extra fields.
/**
* Implements custom function().
*/
function MYMODULE_message_insert_status($order, $communication) {
// Load data
$account = user_load($order->uid);
$message = message_create('commerce_order_created', array(), $account);
$message->message_commerce_order[LANGUAGE_NONE][0]['target_id'] = $order->order_id;
// Save reference to the order in the order reference field, and the
$wrapper = entity_metadata_wrapper('message', $message);
$now = time();
$wrapper->field_confirmation_date_created->set($now); // Custom fields to extend the commerce_order_created message type
$wrapper->field_confirmation_date_send->set($now); // Custom fields to extend the commerce_order_created message type
// Save message
$wrapper->save();
}
How can I set the data for?
Notify - Email subject
Notify - Email body
I loaded the message object and there these fields are not present?
Comments
Comment #1
thim CreditAttribution: thim commentedAnybody got some info to get me started?
Comment #2
asak CreditAttribution: asak commentedbump. me too. trying to set a Commerce Message.
1. Implemented the hook_default_message_type:
2. Created a function:
But - i can't seem to get the message attached to the order...
Any clues - highly appreciated ;)
-Asaph
Comment #3
5kot CreditAttribution: 5kot as a volunteer commentedHad the same problem and this is what I got working
Comment #4
bluegeek9 CreditAttribution: bluegeek9 as a volunteer commented