I hope you understand my bad english.

I have message type Commerce Order: order processing notify to send a mail for change of status.

The rules settings I have here in a image.

How it all works beautifully. Only I have a big one with the language.

If I admin area language (German) send out a mail to a customer in English or that mail arrives in German, even though the user had set his language in English.
I've tried everything. If I set the admin language to English all get an English email, and the German customer.

I have set in message type translation. German and English.

I do not remember more. I tried the language by rules to check but I do not know how to do it.

Why it sends the e-mail to the admin language, and not by language of the customer?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fugazi’s picture

Issue summary: View changes
FileSize
115.98 KB
261.07 KB
fugazi’s picture

if I change the order status, and the admin page is.
hxxp://mysite.de/en/users/user-0#overlay=en/admin/commerce/orders will be adjusting the message sent in English. Even if the set language of the user is German.

hxxp://mysite.de/de/users/user-0#overlay=en/admin/commerce/orders will be shipped in the German message. Even if the set language of the user is English.

I do not understand why the message is not sent the user in the selected language.

Best Regards

fugazi’s picture

FileSize
20.11 KB

I have now the modules commerce_message for additional message types and matching rules rewritten (I know, that one that does not make). Maybe somebody once pleasurable to test this, to see that the new message type will not be sent in the language of the user.
The Module is now writing two new message types "Order Processing notify" and "Order complete notify". Both will be prompted by a message on Rules Change the status "Processing in progress" and "completed" to send.
Here also, the message from the system will send in the correct language and even sent with status change, unfortunately not.

fugazi’s picture

Version: 7.x-1.0-rc2 » 7.x-1.0-rc3
fugazi’s picture

I only problem I mean? Or it happens in other multi-language pages?

fugazi’s picture

I have now through all and knows exactly that all mails are send via a command sent the admin area in its set language from the admin.

It can not be verified which language the customer is established. And so you can not create a multilingual website without a vendor's language must impose upon the customer.

A way which, although totally stupid when I set the country or the language of the customer know I need to change the prefix of the country and the customer will then receive the emial in his language.

That can not be whole purpose of rules and drupal commerce. Or?

suvsv’s picture

Have you found the solution?

fugazi’s picture

hello,

yes I could solve it with custom php code in the rules.

Value:

$account = user_load($commerce_order->uid);
$languages = language_list();
global $language;
if ($language->language != $account->language) {
  $language = $languages[$account->language];
}
fugazi’s picture

if required here are my rules setting

{ "rules_commerce_order_order_marked_complete" : {
    "LABEL" : "Commerce Order: order marked complete",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Order Complete Notify" ],
    "REQUIRES" : [ "rules", "php", "message_notify", "entity" ],
    "ON" : { "commerce_order_presave" : [] },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "commerce-order" ], "type" : "commerce_order" } },
      { "NOT data_is_empty" : { "data" : [ "commerce-order:owner" ] } },
      { "NOT data_is" : { "data" : [ "commerce-order-unchanged:status" ], "value" : "completed" } },
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "completed" } }
    ],
    "DO" : [
      { "php_eval" : { "code" : "$account = user_load($commerce_order-\u003Euid);\r\n$languages = language_list();\r\nglobal $language;\r\nif ($language-\u003Elanguage != $account-\u003Elanguage) {\r\n  $language = $languages[$account-\u003Elanguage];\r\n}" } },
      { "drupal_message" : { "message" : "Order notification has been sent" } },
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "commerce_order_complete_notify",
            "param_user" : [ "commerce-order:owner" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:message-commerce-order" ],
          "value" : [ "commerce-order" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
      { "message_notify_process" : {
          "message" : [ "entity-created" ],
          "save_on_fail" : 0,
          "save_on_success" : 0,
          "rendered_body_field" : [ "entity-created:message-commerce-order:owner:language" ]
        }
      }
    ]
  }
}
suvsv’s picture

Fantastic! Thank you.

maxplus’s picture

Thanks fugazi,

I have added the same php code to my Rule where I use message notify to send out an email and now my message is send in the correct language.
See also: https://www.drupal.org/node/2177929

jmary’s picture

The token entity-created:message-commerce-order:owner:language is not existing on my install. Is there any specific module to install to get that one ?

fugazi’s picture

I have subsequently not pursued and have avoided between messages. I had to test this time this module used https://www.drupal.org/sandbox/mglaman/2220855

I hope that it will help you further. Oh, I have had still more i18n rules installed, but I know now no longer whether this was necessary.

fugazi’s picture

Sorry double post

bohemier’s picture

Thanks to fugazi for the very useful snippet... I adapted it to my anonymous checkout process by adding a language field to my order entity (since there is no user associated to orders in an anonymous checkout commerce site - well there is but it's always the anonymous user), and saving the current site language during checkout completion. Here are the rules for that:

Saving the language in the order:

{ "commerce_message_set_the_order_language" : {
    "LABEL" : "Set the order language",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-2",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "field_language" } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "commerce-order:field-language" ],
          "value" : "[site:current-page:language]"
        }
      }
    ]
  }
}

Restoring the language when sending a confirmation:

{ "rules_commerce_order_message_status_shipped_notification_email" : {
    "LABEL" : "Commerce order message: status shipped notification email",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "php", "message_notify", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "NOT data_is" : {
          "data" : [ "commerce-order:status" ],
          "value" : [ "commerce-order-unchanged:status" ]
        }
      },
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "completed" } }
    ],
    "DO" : [
      { "php_eval" : { "code" : "global $language;\r\n$languages = language_list();\r\n$lang = $commerce_order-\u003Efield_language[LANGUAGE_NONE][0][\u0027value\u0027];\r\n\r\nforeach($languages as $l) {\r\n  if($l-\u003Enative == $lang) {\r\n    $language = $l;\r\n    break;\r\n  }\r\n}\r\n" } },
      { "drupal_message" : { "message" : "Shipping confirmation message has been sent to [commerce-order:mail]" } },
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "commerce_order_order_status_shipped",
            "param_user" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "message" : "Message" } }
        }
      },
      { "data_set" : { "data" : [ "message:field-order" ], "value" : [ "commerce-order" ] } },
      { "data_set" : {
          "data" : [ "message:arguments:comment" ],
          "value" : "[message:message_commerce_body]"
        }
      },
      { "entity_save" : { "data" : [ "message" ], "immediate" : "1" } },
      { "message_notify_process" : {
          "message" : [ "message" ],
          "save_on_fail" : "0",
          "save_on_success" : "0",
          "mail" : "[commerce-order:mail]"
        }
      }
    ]
  }
}

Don't forget to create a field_language in the order at admin/commerce/config/order/fields - Create a text field with length 50.