Discussions

Using rules to send different emails for Bank transfer and Cash on Delivery Payment

Hallo,
I have setup eshop (Commerce Kickstart) with two type of payments: Bank Transfer and Cash on Delivery.
I need to send different emails for selected payment method (Bank Transfer or Cash on Delivery).

I have decide to use rules for it.
For Cash on Delivery payment I have used default message "Commerce Order: order confirmation" - commerce_order_confirmation from Commerce Kickstart.

For Bank of Transfer payment (in admin/structure/messages) I have created cloned message of "Commerce Order: order confirmation" message - commerce_order_order_confirmation_bank_transfer)

Next I start to define new rule for Bank Transfer by cloning default rule for sending "Commerce order message: order notification e-mail - rules_commerce_order_message_order_notification" to rules_commerce_order_message_order_notification_e_mail_bank_tran.

In cloned rule I have changed only element "Create enitity" from commerce_order_confirmation message type to commerce_order_order_confirmation_bank_transfer message type.

But It makes error in "Set data value" element:
"Data selector entity-created:message-commerce-order for parameter data is invalid."
What is wrong? Thank you.
Here is cloned rule which make an error - rules_commerce_order_message_order_notification_bank_tran:

{ "rules_commerce_order_message_order_notification_e_mail_bank_tran" : {
    "LABEL" : "Commerce order message: order notification e-mail (Bank Transfer)",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "4",
    "REQUIRES" : [ "rules", "message_notify", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "commerce_order_order_confirmation_bank_transfer",
            "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
        }
      }
    ]
  }
}

Here is rule used for cloning - rules_commerce_order_message_order_notification:

{ "rules_commerce_order_message_order_notification" : {
    "LABEL" : "Commerce order message: order notification e-mail",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "3",
    "REQUIRES" : [ "rules", "message_notify", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "commerce_order_order_confirmation",
            "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
        }
      }
    ]
  }
}
AttachmentSize
Image icon rules.png14.86 KB
Posted: Feb 21, 2013

Comments