Created
November 11, 2015 17:15
-
-
Save andyg5000/a0feb70f979156102734 to your computer and use it in GitHub Desktop.
Create a simple addressbook profile from the last order for each customer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = db_query("SELECT MAX(order_id) as order_id, uid FROM commerce_order GROUP BY uid"); | |
foreach ($query as $result) { | |
try { | |
$order_wrapper = entity_metadata_wrapper('commerce_order', $result->order_id); | |
$billing = $order_wrapper->commerce_customer_billing->value(); | |
if (empty($billing->data['commerce_simple_addressbook']['cloned'])) { | |
$billing->data['commerce_simple_addressbook']['cloned'] = TRUE; | |
$order_wrapper->commerce_customer_billing->commerce_simple_addressbook_save->set(TRUE); | |
$order_wrapper->commerce_customer_billing->save(); | |
$order_wrapper->commerce_customer_shipping->commerce_simple_addressbook_save->set(TRUE); | |
$order_wrapper->commerce_customer_shipping->save(); | |
commerce_simple_addressbook_commerce_checkout_complete($order_wrapper->value()); | |
} | |
} catch (Exception $ex) {} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment