diff --git a/admin/partials/ssbhesabix-admin-functions.php b/admin/partials/ssbhesabix-admin-functions.php index ad74d95..f313ebe 100644 --- a/admin/partials/ssbhesabix-admin-functions.php +++ b/admin/partials/ssbhesabix-admin-functions.php @@ -796,56 +796,37 @@ class Ssbhesabix_Admin_Functions public function exportCustomers($batch, $totalBatch, $total, $updateCount) { HesabixLogService::writeLogStr("Export Customers"); - $wpFaService = new HesabixWpFaService(); - $result = array(); $result["error"] = false; - $rpp = 500; global $wpdb; - - if ($batch == 1) { - $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`"); - $totalBatch = ceil($total / $rpp); - } - - $offset = ($batch - 1) * $rpp; - $customers = $wpdb->get_results("SELECT ID FROM `" . $wpdb->prefix . "users` ORDER BY ID ASC LIMIT $offset,$rpp"); - - $items = array(); - foreach ($customers as $item) { - $id_customer = $item->ID; - $id_obj = $wpFaService->getWpFaId('customer', $id_customer); - if (!$id_obj) { - $hesabixCustomer = ssbhesabixCustomerService::mapCustomer(null, $id_customer); - array_push($items, $hesabixCustomer); - $updateCount++; - } - } - - if (!empty($items)) { - $hesabix = new Ssbhesabix_Api(); - $response = $hesabix->contactBatchSave($items); - if ($response->Success) { - foreach ($response->Result as $item) { - $json = json_decode($item->Tag); - - $wpdb->insert($wpdb->prefix . 'ssbhesabix', array( - 'id_hesabix' => (int)$item->Code, - 'obj_type' => 'customer', - 'id_ps' => (int)$json->id_customer, - )); - - HesabixLogService::log(array("Contact successfully added. Contact Code: " . $item->Code . ". Customer ID: " . (int)$json->id_customer)); + $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`"); + $customers = $wpdb->get_results("SELECT id,user_nicename,user_email FROM " . $wpdb->prefix . "users"); + $data = array(); + foreach($customers as $customer){ + $temp = array(); + $tempresult = $wpdb->get_results("SELECT meta_key,meta_value FROM `" . $wpdb->prefix . "usermeta` WHERE user_id='". $customer->id . "'"); + foreach($tempresult as $tmr){ + if($tmr->meta_key == 'nickname'){ + $temp['nickname'] = $tmr->meta_value; + } + if($tmr->meta_key == 'first_name'){ + $temp['name'] = $tmr->meta_value; + } + if($tmr->meta_key == 'last_name'){ + $temp['name'] .= $tmr->meta_value; } - } else { - HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode.")); } + $temp['email'] .= $customer->user_email; + array_push($data,$temp); + } + $hesabix = new Ssbhesabix_Api(); + $response = $hesabix->personsImport(['data'=>$data]); + if ($response->Success) { + HesabixLogService::log(array("Contact successfully added.")); + } else { + HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode.")); } - - $result["batch"] = $batch; - $result["totalBatch"] = $totalBatch; $result["total"] = $total; - $result["updateCount"] = $updateCount; return $result; } diff --git a/admin/partials/ssbhesabix-admin-setting.php b/admin/partials/ssbhesabix-admin-setting.php index 9ba3588..f465d0f 100644 --- a/admin/partials/ssbhesabix-admin-setting.php +++ b/admin/partials/ssbhesabix-admin-setting.php @@ -1527,31 +1527,7 @@ class Ssbhesabix_Setting { return $available_cashes; } } -//============================================================================================= - public static function ssbhesabix_get_projects() { - $ssbhesabix_api = new Ssbhesabix_Api(); - $projects = $ssbhesabix_api->settingGetProjects(); - if ( is_object( $projects ) && $projects->Success ) { - $available_projects = array(); - $available_projects[ - 1 ] = __( 'Choose', 'ssbhesabix' ); - foreach ( $projects->Result as $project ) { - if ( $project->Active ) { - $available_projects[ $project->Title ] = $project->Title; - } - } - - return $available_projects; - } else { - update_option( 'ssbhesabix_live_mode', 0 ); - echo '
' . __( 'Cannot get Projects detail.', 'ssbhesabix' ) . '
'; - echo '