Regular order notifications are great, but this module should also support separately sent admin-facing order notifications and a separate message type so that they can be customized.

Comments

nvahalik created an issue. See original summary.

nvahalik’s picture

Status: Active » Needs review
StatusFileSize
new3.98 KB
Christopher Riley’s picture

I too would love to see this be part of the official module however when I use your patch and then try to run an update I receive the following:

-> drush updb
No database updates required [success]
Creating default object from empty value entity.module:876 [warning]
WD message_type: EntityMalformedException: Missing bundle property on entity of type message_type. in entity_extract_ids() (line 7844 of [error]
/home/site/public_html/includes/common.inc).
exception 'EntityMalformedException' with message 'Missing bundle property on entity of type message_type.' in [error]
/home/site/public_html/includes/common.inc:7844
Stack trace:
#0 /home/site/public_html/modules/field/field.attach.inc(191): entity_extract_ids('message_type', Object(stdClass))
#1 /home/site/public_html/modules/field/field.attach.inc(914): _field_invoke('presave', 'message_type', Object(stdClass))
#2 /home/site/public_html/sites/all/modules/contrib/entity/includes/entity.controller.inc(912): field_attach_presave('message_type',
Object(stdClass))
#3 /home/site/public_html/sites/all/modules/contrib/entity/includes/entity.controller.inc(443): EntityAPIControllerExportable->invoke('presave',
Object(stdClass))
#4 /home/site/public_html/sites/all/modules/contrib/entity/includes/entity.controller.inc(949): EntityAPIController->save(Object(stdClass), NULL)
#5 /home/site/public_html/sites/all/modules/contrib/entity/entity.module(289): EntityAPIControllerExportable->save(Object(stdClass))
#6 /home/site/public_html/sites/all/modules/contrib/entity/entity.module(942): entity_save('message_type', Object(stdClass))
#7 /home/site/public_html/sites/all/modules/contrib/entity/entity.module(853): _entity_defaults_rebuild('message_type')
#8 /home/site/public_html/sites/all/modules/contrib/entity/entity.module(1080): entity_defaults_rebuild()
#9 [internal function]: entity_flush_caches()
#10 /home/site/public_html/includes/module.inc(895): call_user_func_array('entity_flush_ca...', Array)
#11 /home/site/public_html/includes/common.inc(7600): module_invoke_all('flush_caches')
#12 /usr/local/src/drush/commands/core/drupal/cache.inc(99): drupal_flush_all_caches()
#13 /usr/local/src/drush/includes/drush.inc(718): drush_cache_clear_both()
#14 /usr/local/src/drush/includes/drush.inc(705): drush_call_user_func_array('drush_cache_cle...', Array)
#15 /usr/local/src/drush/commands/core/cache.drush.inc(143): drush_op('drush_cache_cle...')
#16 [internal function]: drush_cache_command_clear('all')
#17 /usr/local/src/drush/includes/command.inc(368): call_user_func_array('drush_cache_com...', Array)
#18 /usr/local/src/drush/includes/command.inc(219): _drush_invoke_hooks(Array, Array)
#19 [internal function]: drush_command('all')
#20 /usr/local/src/drush/includes/command.inc(187): call_user_func_array('drush_command', Array)
#21 /usr/local/src/drush/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
#22 /usr/local/src/drush/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#23 /usr/local/src/drush/drush.php(11): drush_main()
#24 {main}
Finished performing updates. [ok]

I am sure there is just one thing that was overlooked but it isn't jumping out at me right now. Suggestions?

nvahalik’s picture

Status: Needs review » Needs work
nvahalik’s picture

Status: Needs work » Needs review
StatusFileSize
new3.98 KB

Fixed the import!

jimmynash’s picture

Does this new message work with the !order_summary token? I'd love to have this new message in there but I've had troubles in the past with that token in the message. More here https://www.drupal.org/node/2366413

nvahalik’s picture

Yes, it does support !order-summary:

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

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

I know there has been some discussion about opening that token up, but obviously that is out of scope for this ticket. ;)

mglaman’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We have tests now, and we should add that. The tests have an example for ensuring a message is emailed.

+++ b/commerce_message.module
@@ -57,7 +57,7 @@ function commerce_message_module_implements_alter(&$implementations, $hook) {
-  if (!empty($message->mid) || $message->type != 'commerce_order_order_confirmation') {
+  if (!empty($message->mid) || $message->type != 'commerce_order_order_confirmation' && $message->type != 'commerce_order_admin_order_confirmation') {

Also, I'd like to get #2366413: !order-summary token not replaced in message types other than "commerce_order_order_confirmation" resolve so we don't need this logic check

  • mglaman committed 0997677 on 7.x-1.x
    Issue #2572767 by nvahalik, mglaman: Tests for admin order notifications
    
  • mglaman committed 19d2613 on 7.x-1.x authored by nvahalik
    Issue #2572767 by nvahalik: Add admin order notifications
    
mglaman’s picture

Status: Needs work » Fixed

I went and re-rolled nvahalik's patch. I also added tests to confirm the message gets sent.

  • mglaman committed 49bb9d8 on 7.x-1.x
    Issue #2572767 by nvahalik, mglaman: Test admin order notifications...

Status: Fixed » Closed (fixed)

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

wizonesolutions’s picture

FYI, there are some tokens that are serialized bad in the defaults here. Easy enough to fix manually, and I know this isn't the place to post, but.....just...mentioning it.

rob c’s picture

For some reason this message is sent to the user and not the admin on a site i maintain after updating. (without changing the rule ofco). Would be nice to have a heads up for this in the docs, sites might start to mail to users without manual testing / changing the rule / other changes might impact this. From looking at the code i wonder: where does the admin email come in to play? Trying to trace back the why.