Advertisement
MrJoshMiller

Anonymous Checkout Create New User Name as Billing Name

Dec 17th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.71 KB | None | 0 0
  1. { "commerce_checkout_new_account" : {
  2.     "LABEL" : "Create a new account for an anonymous order",
  3.     "PLUGIN" : "reaction rule",
  4.     "WEIGHT" : "2",
  5.     "REQUIRES" : [ "rules", "commerce", "php", "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" : {
  22.               "select" : "commerce-order:mail-username",
  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];" }
  24.             },
  25.             "param_mail" : [ "commerce-order:mail" ]
  26.           },
  27.           "PROVIDE" : { "entity_created" : { "account_created" : "Created account" } }
  28.         }
  29.       },
  30.       { "data_set" : { "data" : [ "account-created:status" ], "value" : 1 } },
  31.       { "entity_save" : { "data" : [ "account-created" ], "immediate" : 1 } },
  32.       { "entity_query" : {
  33.           "USING" : {
  34.             "type" : "user",
  35.             "property" : "mail",
  36.             "value" : [ "commerce-order:mail" ],
  37.             "limit" : 1
  38.           },
  39.           "PROVIDE" : { "entity_fetched" : { "account_fetched" : "Fetched account" } }
  40.         }
  41.       },
  42.       { "LOOP" : {
  43.           "USING" : { "list" : [ "account-fetched" ] },
  44.           "ITEM" : { "list_item" : "Current list item" },
  45.           "DO" : [
  46.             { "send_account_email" : { "account" : [ "list-item" ], "email_type" : "register_admin_created" } },
  47.             { "data_set" : { "data" : [ "commerce-order:uid" ], "value" : [ "list-item:uid" ] } },
  48.             { "data_set" : {
  49.                 "data" : [ "commerce-order:commerce-customer-billing:uid" ],
  50.                 "value" : [ "list-item:uid" ]
  51.               }
  52.             },
  53.             { "data_set" : {
  54.                 "data" : [ "commerce-order:commerce-customer-shipping:uid" ],
  55.                 "value" : [ "list-item:uid" ]
  56.               }
  57.             }
  58.           ]
  59.         }
  60.       }
  61.     ]
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement