Api created by Updated by : ps

This commit is contained in:
VE10-Sanjeev 2023-10-13 19:35:47 +05:30
parent 628d77a6db
commit bc6041b89d
2 changed files with 56 additions and 14 deletions

View File

@ -11,6 +11,24 @@ class ApiIntegration extends ResourceController
{
use ResponseTrait;
private $global_variable_business_id;
private $global_variable_user_id;
private $global_variable_user_name;
private $global_variable_role;
public function __construct()
{
$this->global_variable_business_id = 1;
$this->global_variable_role = "online";
$api_model = new ApiIntegrationModel();
$table = 'users';
$where = ['role'=>$this->global_variable_role,'business_id'=>(int)$this->global_variable_business_id];
$existing_data = $api_model->getData($table, $where);
$this->global_variable_user_id = isset($existing_data[0]->user_id) ? (int)$existing_data[0]->user_id : NULL;
$this->global_variable_user_name = isset($existing_data[0]->user_id) ? $existing_data[0]->first_name." ".$existing_data[0]->last_name : NULL;
$this->logger->info("Api Integration : User = ".$this->global_variable_user_name);
}
public function api_integration($api_request_text) {
$this->logger->info("Api Integration : Request Text = ".$api_request_text);
try {
@ -142,6 +160,7 @@ class ApiIntegration extends ResourceController
$primary_key_id = (int)$existing_data[0][$table_column[0]];
$this->logger->info("Api CallMethods : ".$table." its PrimaryKey ID = ".$primary_key_id);
$inactive_data['isactive'] = 0;
$inactive_data['updated_by'] = $this->global_variable_user_id;
$update_where = ['isactive' => 1, $table_column[0] => $primary_key_id];
$api_model->updateData($table, $inactive_data, $update_where);
$get_existing_child_details = $api_model->getData($table_child, $update_where);
@ -253,9 +272,10 @@ class ApiIntegration extends ResourceController
$book_data['price'] = (isset($records['sale_price']) && $records['sale_price'] != '') ? $records['sale_price'] : ((isset($records['regular_price']) && $records['regular_price'] != '') ? $records['regular_price'] : ((isset($records['price']) && $records['price'] != '') ? $records['price'] : NULL));
$book_data['sku'] = isset($records['sku']) ? $records['sku'] : NULL;
$book_data['isactive'] = (isset($records['status']) && strtolower($records['status']) === "publish") ? 1 : 0;
$book_data['business_id'] = 1;
$book_data['business_id'] = $this->global_variable_business_id;
$images = $records['images'];
if ((int)$countAll == 0) {
$book_data['created_by'] = $this->global_variable_user_id;
$insert_result = $api_model->insertData('books', $book_data);
$last_insert_book_id = $insert_result['info'];
$extensive_correspondence .= $insert_result['info'] ? "Book id : " . $insert_result['info']
@ -265,6 +285,7 @@ class ApiIntegration extends ResourceController
$insert_result['err'] ? $this->logger->error("Api SaveBookDetails : Err = ".$insert_result['err']):"";
} else {
$last_insert_book_id = $book_id;
$book_data['updated_by'] = $this->global_variable_user_id;
/** Draft status means entry must but inactive. publish means active that's why comment here
* $book_where = ['book_id' => $book_id, 'isactive' => 1, 'wp_api_product_id' => $wordpress_book_id];
**/
@ -310,7 +331,8 @@ class ApiIntegration extends ResourceController
$inactive_where = ['isactive' => 1, 'book_id' => (int)$last_insert_book_id];
$inactive_whereIn[0] = 'wp_api_img_id';
$inactive_whereIn[1] = $missingValues;
$api_model->inactiveMissingDetails('book_images', $inactive_where, $inactive_whereIn);
$data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id];
$api_model->inactiveMissingDetails('book_images',$data_to_batch_update, $inactive_where, $inactive_whereIn);
}
}
}
@ -401,7 +423,8 @@ class ApiIntegration extends ResourceController
$where2 = ['isactive' => 1];
$whereIn2[0] = 'category_id';
$whereIn2[1] = $book_categories_to_inactive;
$api_model->inactiveMissingDetails('book_categories', $where2, $whereIn2);
$data_to_batch_update2 = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id];
$api_model->inactiveMissingDetails('book_categories',$data_to_batch_update2, $where2, $whereIn2);
//echo $api_model->getlastQuery();
}
} // loop closed
@ -478,13 +501,14 @@ class ApiIntegration extends ResourceController
$customer_data['email'] = $records['email'];
$customer_data['profile_picture'] = $records['avatar_url'];
$customer_data['wp_api_customer_id'] = $wordpress_customer_id;
$customer_data['mode'] = 'online';
$customer_data['business_id'] = 1;
$customer_data['mode'] = $this->global_variable_role;
$customer_data['business_id'] = $this->global_variable_business_id;
$billing = $records['billing'];
$shipping = $records['shipping'];
if ((int)$countAll == 0) {
$customer_data['created_by'] = $this->global_variable_user_id;
$insert_result = $api_model->insertData('customers', $customer_data);
$last_insert_customer_id = $insert_result['info'];
$extensive_correspondence .= $insert_result['info'] ? "Customer id : " . $insert_result['info']
@ -493,6 +517,7 @@ class ApiIntegration extends ResourceController
$insert_result['info'] ? $this->logger->info("Api SaveCustomerDetails : Customer id = ".$insert_result['info']):"";
$insert_result['err'] ? $this->logger->error("Api SaveCustomerDetails : Err = ".$insert_result['err']):"";
} else {
$customer_data['updated_by'] = $this->global_variable_user_id;
$last_insert_customer_id = $customer_id;
$customer_where = ['customer_id' => $customer_id, 'isactive' => 1, 'wp_api_customer_id' => $wordpress_customer_id];
$update_result = $api_model->updateData('customers', $customer_data, $customer_where);
@ -545,7 +570,8 @@ class ApiIntegration extends ResourceController
$inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id,'address_type'=>1];
$inactive_whereIn[0] = 'address_1';
$inactive_whereIn[1] = $missingBillingValues;
$api_model->inactiveMissingDetails('customer_addresses', $inactive_where, $inactive_whereIn);
$data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id];
$api_model->inactiveMissingDetails('customer_addresses',$data_to_batch_update, $inactive_where, $inactive_whereIn);
}
}
}
@ -626,7 +652,8 @@ class ApiIntegration extends ResourceController
$inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id, 'address_type'=>2];
$inactive_whereIn[0] = 'address_1';
$inactive_whereIn[1] = $missingShippingValues;
$api_model->inactiveMissingDetails('customer_addresses', $inactive_where, $inactive_whereIn);
$data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id];
$api_model->inactiveMissingDetails('customer_addresses',$data_to_batch_update, $inactive_where, $inactive_whereIn);
$this->logger->info("Api SaveCustomerDetails : Missing Shipping " .implode(",",$missingShippingValues)." Are inactived");
}
}
@ -762,7 +789,7 @@ class ApiIntegration extends ResourceController
$invoice_data['order_number']=$records['order_key'];
$invoice_data['payment_method']=$records['payment_method_title'];
$invoice_data['event_id']=NULL;
$invoice_data['business_id']=1;
$invoice_data['business_id']=$this->global_variable_business_id;
$invoice_data['shipping_address']=$shipping_addr;
$invoice_data['shipping_address_id']=NULL;
$invoice_data['billing_address']=$billing_addr;
@ -772,6 +799,7 @@ class ApiIntegration extends ResourceController
$invoice_data['invoice_type'] = 1;
if ((int)$countAll == 0) {
$invoice_data['created_by'] = $this->global_variable_user_id;
$insert_result = $api_model->insertData('invoice', $invoice_data);
$last_insert_invoice_id = $insert_result['info'];
$extensive_correspondence .= $insert_result['info'] ? "Invoice id : " . $insert_result['info']
@ -782,6 +810,7 @@ class ApiIntegration extends ResourceController
} else {
$last_insert_invoice_id = $invoice_id;
$customer_where = ['invoice_id' => $invoice_id, 'isactive' => 1, 'wp_api_order_id' => $wordpress_order_id];
$invoice_data['updated_by'] = $this->global_variable_user_id;
$update_result = $api_model->updateData('invoice', $invoice_data, $customer_where);
$extensive_correspondence .= $update_result['info'] ? "Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"
: " ( Err :" . $update_result['err'] . ")";
@ -829,7 +858,8 @@ class ApiIntegration extends ResourceController
$inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id];
$inactive_whereIn[0] = 'wp_api_line_items_id';
$inactive_whereIn[1] = $missingValues;
$api_model->inactiveMissingDetails('invoiceitems', $inactive_where, $inactive_whereIn);
$data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id];
$api_model->inactiveMissingDetails('invoiceitems',$data_to_batch_update, $inactive_where, $inactive_whereIn);
}
}
}
@ -890,7 +920,7 @@ class ApiIntegration extends ResourceController
$subscription_data[$x]['from_subscription'] = $fromDate;
$subscription_data[$x]['to_subscription'] = $toDate;
$subscription_data[$x]['mode'] = $result_book_category[$x]['category_name'];
$subscription_data[$x]['business_id']=1;
$subscription_data[$x]['business_id']=$this->global_variable_business_id;
$this->logger->info("Api SaveSalesDetails : Subscription Data inx = $x Request data = ".json_encode($subscription_data));
}
}
@ -1089,7 +1119,7 @@ class ApiIntegration extends ResourceController
$book_category_data[$a]['id'] = $masterCategoryId;
$book_category_data[$a]['name'] = $r->name;
$book_category_data[$a]['wp_api_category_id'] = $r->id;
$book_category_data[$a]['business_id'] = 1;
$book_category_data[$a]['business_id'] = $this->global_variable_business_id;
$book_category_data[$a]['parent_wp_api_category_id'] = NULL;
$a++;
$this->logger->info("Api SaveCategoriesMasterDetails : Categories Data = $a Request data to save on master category = " . json_encode($book_category_data));

View File

@ -83,9 +83,21 @@ class ApiIntegrationModel extends Model
return $text;
}
public function inactiveMissingDetails($table_name,$where,$whereIn){
$dataToUpdate = ['isactive' => 0];
$this->db->table($table_name)->where($where)->whereIn($whereIn[0],$whereIn[1])->update($dataToUpdate);
// public function inactiveMissingDetails($table_name,$where,$whereIn){
// $dataToUpdate = ['isactive' => 0];
// $this->db->table($table_name)->where($where)->whereIn($whereIn[0],$whereIn[1])->update($dataToUpdate);
// }
public function inactiveMissingDetails($table_name,$dataToUpdate,$where = null,$whereIn = null)
{
$this->db->table($table_name);
$query = $this->db->table($table_name);
if ($where) {
$query->where($where);
}
if ($whereIn) {
$query->whereIn($whereIn[0], $whereIn[1]);
}
$query->update($dataToUpdate);
}
public function getBookCategories($product_id){