View difference between Paste ID: 5B3B6Rhz and KNhe8gRS
SHOW: | | - or go back to the newest paste.
1-
{ "commerce_checkout_new_account" : {
1+
{ "rules_create_a_new_account_for_an_anonymous_order_jm" : {
2-
    "LABEL" : "Create a new account for an anonymous order",
2+
    "LABEL" : "Create a new account for an anonymous order (jm)",
3
    "PLUGIN" : "reaction rule",
4
    "WEIGHT" : "2",
5-
    "REQUIRES" : [ "rules", "commerce", "php", "commerce_checkout" ],
5+
    "REQUIRES" : [ "rules", "commerce", "commerce_checkout" ],
6
    "ON" : [ "commerce_checkout_complete" ],
7
    "IF" : [
8
      { "data_is" : { "data" : [ "commerce-order:uid" ], "value" : "0" } },
9
      { "NOT entity_exists" : {
10
          "type" : "user",
11
          "property" : "mail",
12
          "value" : [ "commerce-order:mail" ]
13
        }
14
      },
15
      { "data_is" : { "data" : [ "commerce-order:type" ], "value" : "commerce_order" } }
16
    ],
17
    "DO" : [
18
      { "entity_create" : {
19
          "USING" : {
20
            "type" : "user",
21-
            "param_name" : {
21+
            "param_name" : "[commerce-order:commerce-customer-billing]",
22-
              "select" : "commerce-order:mail-username",
22+
23-
              "php" : { "code" : "global $user;\r\n$order = commerce_order_load(commerce_cart_order_id($user-\u003Euid)); \/\/ current order\r\n$order_wrapper = entity_metadata_wrapper(\u0027commerce_order\u0027, $order);\r\n\r\n\/\/ This is the part that Rules doesn\u0027t get ... \r\n$customer_profile = commerce_customer_profile_load($order_wrapper-\u003Ecommerce_customer_billing-\u003Eraw());\r\nreturn $customer_profile-\u003Ecommerce_customer_address[\u0027und\u0027][0][\u0027name_line\u0027];" }
23+
24
          "PROVIDE" : { "entity_created" : { "account_created" : "Created account" } }
25
        }
26
      },
27
      { "data_set" : { "data" : [ "account-created:status" ], "value" : 1 } },
28
      { "entity_save" : { "data" : [ "account-created" ], "immediate" : 1 } },
29
      { "entity_query" : {
30
          "USING" : {
31
            "type" : "user",
32
            "property" : "mail",
33
            "value" : [ "commerce-order:mail" ],
34
            "limit" : 1
35
          },
36
          "PROVIDE" : { "entity_fetched" : { "account_fetched" : "Fetched account" } }
37
        }
38
      },
39
      { "LOOP" : {
40
          "USING" : { "list" : [ "account-fetched" ] },
41
          "ITEM" : { "list_item" : "Current list item" },
42
          "DO" : [
43
            { "send_account_email" : { "account" : [ "list-item" ], "email_type" : "register_admin_created" } },
44
            { "data_set" : { "data" : [ "commerce-order:uid" ], "value" : [ "list-item:uid" ] } },
45
            { "data_set" : {
46
                "data" : [ "commerce-order:commerce-customer-billing:uid" ],
47
                "value" : [ "list-item:uid" ]
48
              }
49
            },
50
            { "data_set" : {
51
                "data" : [ "commerce-order:commerce-customer-shipping:uid" ],
52
                "value" : [ "list-item:uid" ]
53
              }
54
            }
55
          ]
56
        }
57
      }
58
    ]
59
  }
60
}