Created
October 23, 2015 20:12
-
-
Save vimes1984/ac3e5ae8a0ca4aa83320 to your computer and use it in GitHub Desktop.
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 | |
| /** | |
| * | |
| * | |
| * | |
| * | |
| **/ | |
| public function runimport(){ | |
| global $woocommerce; | |
| $cmscsvpath = realpath(dirname(__FILE__)).'/imports/cms.csv'; | |
| $itemscsvpath = realpath(dirname(__FILE__)).'/imports/Items.csv'; | |
| $custcsvpath = realpath(dirname(__FILE__)).'/imports/cust1.csv'; | |
| $cmscsvarray = $this->parse_file_cms($cmscsvpath); | |
| $itemscsvarray = $this->parse_file_items($itemscsvpath); | |
| $custcsvarray = $this->parse_file_cust($custcsvpath); | |
| /*echo "<h1>ITEMS ARRAY</h1>"; | |
| echo "<pre>"; | |
| var_dump($itemscsvarray); | |
| echo "</pre>"; | |
| echo "<h1>CMS ARRAY</h1>"; | |
| echo "<pre>"; | |
| var_dump($cmscsvarray); | |
| echo "</pre>"; | |
| echo "<h1>CUST ARRAY</h1>"; | |
| echo "<pre>"; | |
| var_dump($custcsvarray); | |
| echo "</pre>"; | |
| */ | |
| foreach($cmscsvarray as $cmskey => $cmsvalue){ | |
| /** | |
| *User import | |
| **/ | |
| $custkey = array_search($cmsvalue['custnum'], array_column($custcsvarray, 'custnum')); | |
| //check if the user allready exists | |
| $usercheck = get_users(array('meta_key' => 'old_user_ID', 'meta_value' => $cmsvalue['custnum'])); | |
| if(count($usercheck) === 0){ | |
| //use doesn't exist | |
| //Import user with $custcsvarray[$custkey] | |
| $login_name = strtolower($custcsvarray[$custkey]['firstname'] . '.' .$custcsvarray[$custkey]['lastname']); | |
| $userdata = array( | |
| 'user_login' => $login_name, | |
| 'first_name' => $custcsvarray[$custkey]['firstname'], | |
| 'last_name' => $custcsvarray[$custkey]['lastname'], | |
| 'user_pass' => 'qpX9h5J2',//All users have this opassword | |
| ); | |
| $userID = wp_insert_user($userdata); | |
| //check empty emails | |
| if($custcsvarray[$custkey]['email'] === ''){ | |
| $email = strtolower($custcsvarray[$custkey]['firstname']) .'-' . $userID. '@islandseawreath.com'; | |
| }else{ | |
| $email = $custcsvarray[$custkey]['email']; | |
| } | |
| wp_update_user(array( 'ID' => $userID, 'user_email' => $email ) ); | |
| //update all the user meta | |
| update_user_meta($userID, 'old_user_ID', $cmsvalue['custnum'] ); | |
| update_user_meta($userID, 'billing_first_name', $custcsvarray[$custkey]['firstname'] ); | |
| update_user_meta($userID, 'billing_last_name', $custcsvarray[$custkey]['lastname'] ); | |
| update_user_meta($userID, 'billing_company', $custcsvarray[$custkey]['company'] ); | |
| update_user_meta($userID, 'billing_address_1', $custcsvarray[$custkey]['addr'] ); | |
| update_user_meta($userID, 'billing_address_2', $custcsvarray[$custkey]['addr2'] ); | |
| update_user_meta($userID, 'billing_city', $custcsvarray[$custkey]['city'] ); | |
| update_user_meta($userID, 'billing_postcode', $custcsvarray[$custkey]['zipcode'] ); | |
| update_user_meta($userID, 'billing_country', $custcsvarray[$custkey]['country'] ); | |
| update_user_meta($userID, 'billing_state', $custcsvarray[$custkey]['state'] ); | |
| update_user_meta($userID, 'billing_phone', $custcsvarray[$custkey]['phone'] ); | |
| update_user_meta($userID, 'billing_email', $custcsvarray[$custkey]['email'] ); | |
| update_user_meta($userID, 'shipping_first_name', $custcsvarray[$custkey]['firstname'] ); | |
| update_user_meta($userID, 'shipping_last_name', $custcsvarray[$custkey]['lastname'] ); | |
| update_user_meta($userID, 'shipping_company', $custcsvarray[$custkey]['company'] ); | |
| update_user_meta($userID, 'shipping_address_1', $custcsvarray[$custkey]['addr'] ); | |
| update_user_meta($userID, 'shipping_address_2', $custcsvarray[$custkey]['addr2'] ); | |
| update_user_meta($userID, 'shipping_city', $custcsvarray[$custkey]['city'] ); | |
| update_user_meta($userID, 'shipping_postcode', $custcsvarray[$custkey]['zipcode'] ); | |
| update_user_meta($userID, 'shipping_country', $custcsvarray[$custkey]['country'] ); | |
| update_user_meta($userID, 'shipping_state', $custcsvarray[$custkey]['state'] ); | |
| }else{ | |
| //Suer allready exists just get there user ID | |
| $userID = $usercheck[0]->ID; | |
| } | |
| /** | |
| *End User import | |
| **/ | |
| /** | |
| *Begin order import | |
| **/ | |
| //filter our orders for this client only... | |
| $orders = array_filter($itemscsvarray, function($item) use ($cmsvalue){ | |
| return $item['orderno'] == $cmsvalue['orderno']; | |
| }); | |
| $order = wc_create_order(array('customer_id' => $userID)); | |
| foreach($orders as $keyorder => $valueorder){ | |
| } | |
| echo "<pre>"; | |
| var_dump($orders); | |
| echo "</pre>"; | |
| /* | |
| $prod = get_product(wc_get_product_id_by_sku( $valueorder['item'] )); | |
| $order->add_product( $prod, intval($valueorder['quants']) ); | |
| */ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment