Notification , API : ps
This commit is contained in:
parent
50736198ee
commit
7f5bd919db
@ -97,7 +97,23 @@ define('EVENT_PRIORITY_HIGH', 10);
|
|||||||
* Constants For Api Integration.
|
* Constants For Api Integration.
|
||||||
*/
|
*/
|
||||||
// define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/');
|
// define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/');
|
||||||
// define('VB_BOOKS', VB_APIURL.'products');
|
define('product','books');
|
||||||
// define('VB_CUSTOMERS', VB_APIURL.'customers');
|
define('product_column', ["book_id","wp_api_product_id"]);
|
||||||
|
|
||||||
|
define('product_child','book_images');
|
||||||
|
define('product_child_column', ["book_id","wp_api_img_id","book_img_id"]);
|
||||||
|
|
||||||
|
define('customer','customers');
|
||||||
|
define('customer_column', ["customer_id","wp_api_customer_id"]);
|
||||||
|
|
||||||
|
define('customer_child','customer_addresses');
|
||||||
|
define('customer_child_column', ["customer_id","","customer_address_id"]);
|
||||||
|
|
||||||
|
define('order','invoice');
|
||||||
|
define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]);
|
||||||
|
|
||||||
|
define('order_child','invoiceitems');
|
||||||
|
define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -28,24 +28,22 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* SMTP Server Address
|
* SMTP Server Address
|
||||||
*/
|
*/
|
||||||
public string $SMTPHost = 'bh-in-11.webhostbox.net';
|
public string $SMTPHost = 'smtp.sendgrid.net';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Username
|
* SMTP Username
|
||||||
*/
|
*/
|
||||||
public string $SMTPUser = 'devbook@mprkv.co.in';
|
public string $SMTPUser = 'apikey';
|
||||||
//public string $SMTPUser = 'venbalap08@gmail.com';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Password
|
* SMTP Password
|
||||||
*/
|
*/
|
||||||
public string $SMTPPass = 'DevBook@2023';
|
public string $SMTPPass = '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';
|
||||||
//public string $SMTPPass = 'sganobynfyouaxgs';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Port
|
* SMTP Port
|
||||||
*/
|
*/
|
||||||
public int $SMTPPort = 465;
|
public int $SMTPPort = 587;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Timeout (in seconds)
|
* SMTP Timeout (in seconds)
|
||||||
@ -60,7 +58,7 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* SMTP Encryption. Either tls or ssl
|
* SMTP Encryption. Either tls or ssl
|
||||||
*/
|
*/
|
||||||
public string $SMTPCrypto = 'ssl';
|
public string $SMTPCrypto = 'tls';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable word-wrap
|
* Enable word-wrap
|
||||||
|
|||||||
@ -101,17 +101,17 @@ $routes->post("load_details2/", "Invoice::load_details2/");
|
|||||||
$routes->post("save_invoice/", "Invoice::save_invoice/");
|
$routes->post("save_invoice/", "Invoice::save_invoice/");
|
||||||
$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1");
|
$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1");
|
||||||
|
|
||||||
|
$routes->get('whatsapp/send/(:any)/(:any)', 'Notifications::index/$1/$2');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Api integration Routes
|
# Api integration Routes
|
||||||
$routes->group("api", function ($routes) {
|
$routes->post('api/(:any)', 'ApiIntegration::api_integration/$1');
|
||||||
// $routes->post("create_products/", "ApiIntegration::save_book_details");
|
|
||||||
$routes->match(['put', 'post', 'get', 'delete'], 'products', 'ApiIntegration::book_api_integration');
|
// $routes->group("api", function ($routes) {
|
||||||
$routes->match(['put', 'post', 'get', 'delete'], 'customers', 'ApiIntegration::customer_api_integration');
|
// // $routes->post("create_products/", "ApiIntegration::save_book_details");
|
||||||
$routes->match(['put', 'post', 'get', 'delete'], 'orders', 'ApiIntegration::sales_api_integration');
|
// // $routes->match(['put', 'post', 'get', 'delete'], 'products', 'ApiIntegration::book_api_integration');
|
||||||
});
|
// // $routes->match(['put', 'post', 'get', 'delete'], 'customers', 'ApiIntegration::customer_api_integration');
|
||||||
|
// // $routes->match(['put', 'post', 'get', 'delete'], 'orders', 'ApiIntegration::sales_api_integration');
|
||||||
|
// });
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* --------------------------------------------------------------------
|
* --------------------------------------------------------------------
|
||||||
|
|||||||
@ -11,94 +11,155 @@ class ApiIntegration extends ResourceController
|
|||||||
{
|
{
|
||||||
use ResponseTrait;
|
use ResponseTrait;
|
||||||
|
|
||||||
public function book_api_integration()
|
public function api_integration($api_request_text) {
|
||||||
|
$this->logger->info("Api Integration : Request Text = ".$api_request_text);
|
||||||
|
try {
|
||||||
|
$request_data = $this->request->getVar();
|
||||||
|
$this->logger->info("Api Integration : Request data type = ".gettype($request_data));
|
||||||
|
if(isset($request_data) && gettype($request_data) === 'object') {$request_data = [$request_data]; $this->logger->info("Api Integration : Request data type = ".gettype($request_data));}
|
||||||
|
|
||||||
|
if(count($request_data)>0){
|
||||||
|
$this->logger->info("Api Integration : Request data count = ".count($request_data));
|
||||||
|
$i = 0;
|
||||||
|
$final_response = [];
|
||||||
|
foreach($request_data as $row_data)
|
||||||
{
|
{
|
||||||
$request = \Config\Services::request();
|
$get_response[$i] = $this->call_methods((array)$row_data, $api_request_text);
|
||||||
$message = "";
|
$final_response[$i] = $get_response[$i]['message'];
|
||||||
try {
|
$i++;
|
||||||
switch ($this->request) {
|
|
||||||
case $this->request->is('put'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/products?id=795;
|
|
||||||
$records = (array)$this->request->getVar();
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
if ($records['id'] == $id) {
|
|
||||||
$response = $this->save_book_details($records, $id);
|
|
||||||
} else {
|
|
||||||
$response = ['status' => 404, 'message' => "ID Mismatched"];
|
|
||||||
}
|
}
|
||||||
|
// return $this->respond(['status' => 200, 'message' => $final_response,'references'=>$get_response]);
|
||||||
|
return $this->respond(['status' => 200, 'message' => $final_response]);
|
||||||
|
}else{
|
||||||
|
$this->logger->error('Api Integration : Err = Request data Not Found.');
|
||||||
|
throw new \Exception('Api Request data Not Found.');
|
||||||
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
$this->logger->error("Api Integration : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
return $this->fail('request failed, An error occurred on line ' . $e->getline() . ' : ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case $this->request->is('post'):
|
}
|
||||||
|
|
||||||
|
public function call_methods($row_data, $api_request_text)
|
||||||
|
{
|
||||||
|
|
||||||
|
$parts = explode('_', $api_request_text);
|
||||||
|
$method = $parts[0];
|
||||||
|
$table = constant($parts[1]);
|
||||||
|
$table_column = constant($parts[1].'_column');
|
||||||
|
$table_child = constant($parts[1].'_child');
|
||||||
|
// $table_child_column = constant($table.'_child_column');
|
||||||
|
$this->logger->info("Api CallMethods : method name = ".$method.", table = ".$table.", table child = ".$table_child);
|
||||||
|
$this->logger->info("Api CallMethods : table = ".$table ." and its column => " .implode(",",$table_column));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// $url = http://localhost/vb_book/api/products;
|
switch ($method) {
|
||||||
$records = (array)$this->request->getVar();
|
case "create":
|
||||||
|
case "update":
|
||||||
|
try {
|
||||||
|
switch ($table) {
|
||||||
|
case "books":
|
||||||
|
try {
|
||||||
|
$records = (array)$row_data;
|
||||||
$wordpress_book_id = $records['id'];
|
$wordpress_book_id = $records['id'];
|
||||||
|
$this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Product Ref ID = ".$wordpress_book_id);
|
||||||
$response = $this->save_book_details($records, $wordpress_book_id);
|
$response = $this->save_book_details($records, $wordpress_book_id);
|
||||||
|
$this->logger->info("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." response = ".$response['status']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case $request->is('get'):
|
case "customers":
|
||||||
try {
|
try {
|
||||||
// $url = http://localhost/vb_book/api/products?id=795;
|
$records = (array)$row_data;
|
||||||
// $url = http://localhost/vb_book/api/products;
|
$wordpress_customer_id = $records['id'];
|
||||||
$id = $this->request->getVar('id');
|
$this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Customer Ref ID = ".$wordpress_customer_id);
|
||||||
if ($id) {
|
$response = $this->save_customer_details($records, $wordpress_customer_id);
|
||||||
$where = ['wp_api_product_id' => (int)$id, 'isactive' => 1];
|
$this->logger->info("Api CallMethods : response = ".$response['status']);
|
||||||
} else {
|
|
||||||
$where = ['isactive' => 1];
|
|
||||||
}
|
|
||||||
$api_model = new ApiIntegrationModel();
|
|
||||||
$book_details = $api_model->setTable('books')->where($where);
|
|
||||||
$response = ['status' => 200, 'message' => "Book Details", "data" => $book_details];
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case $request->is('delete'):
|
case "invoice":
|
||||||
try {
|
try {
|
||||||
// $url = http://localhost/vb_book/api/products?id=795;
|
$records = (array)$row_data;
|
||||||
$id = $this->request->getVar('id');
|
$wordpress_order_id = $records['id'];
|
||||||
$api_model = new ApiIntegrationModel();
|
$this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Order Ref ID = ".$wordpress_order_id);
|
||||||
$where = ['isactive' => 1, 'wp_api_product_id' => (int)$id];
|
$response = $this->save_sales_details($records, $wordpress_order_id);
|
||||||
$existing_book_data = $api_model->getData('books', $where);
|
$this->logger->info("Api CallMethods : response = ".$response['status']);
|
||||||
if ((int)count($existing_book_data) > 0) {
|
|
||||||
$book_id = (int)$existing_book_data[0]->book_id;
|
|
||||||
$inactive_data['isactive'] = 0;
|
|
||||||
$update_where = ['isactive' => 1, 'book_id' => $book_id];
|
|
||||||
$api_model->updateData('books', $inactive_data, $update_where);
|
|
||||||
$getExistingBookImageDetails = $api_model->getData('book_images', $update_where);
|
|
||||||
if ($getExistingBookImageDetails) {
|
|
||||||
// $update_where = ['book_id' => $book_id];
|
|
||||||
$api_model->updateData('book_images', $inactive_data, $update_where);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = ['status' => 200, 'message' => "Book Details and Book Images Details Are Inactived"];
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Handle DELETE-specific exception
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$this->logger->error('Api CallMethods : Err = Invaild Api Route.');
|
||||||
|
throw new \Exception('Api Route Not Available');
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage();
|
||||||
|
return $this->fail(ucwords($method).' request failed, An error occurred ' .$exception_ends_with);
|
||||||
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
try {
|
||||||
|
$basic_message = "";
|
||||||
|
$records = (array)$row_data;
|
||||||
|
$wordpress_refer_id = $records['id'];
|
||||||
|
$api_model = new ApiIntegrationModel();
|
||||||
|
$where = ['isactive' => 1, $table_column[1] => (int)$wordpress_refer_id];
|
||||||
|
$existing_data = $api_model->getData($table, $where);
|
||||||
|
$this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", ".$table_column[1]." Ref ID = ".$wordpress_refer_id);
|
||||||
|
if ((int)count($existing_data) > 0) {
|
||||||
|
if(isset($existing_data[0]) && gettype($existing_data[0]) === 'object') {$existing_data[0] = (array)$existing_data[0]; $this->logger->info("Api Integration : delete ".$table." array data type = ".gettype($existing_data[0]));}
|
||||||
|
$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;
|
||||||
|
$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);
|
||||||
|
$this->logger->info("Api CallMethods : ".$table." Child Details Count = ".count($get_existing_child_details));
|
||||||
|
if ($get_existing_child_details) {
|
||||||
|
$api_model->updateData($table_child, $inactive_data, $update_where);
|
||||||
|
}
|
||||||
|
$basic_message = ucwords($table)." Details (ID = ".$primary_key_id.") and ".ucwords($table)." Child Details Are Deleted";
|
||||||
|
}else{
|
||||||
|
$basic_message = ucwords($table)." has No Details";
|
||||||
|
}
|
||||||
|
$this->logger->info("Api CallMethods : ".$basic_message);
|
||||||
|
$response = ['status' => 200, 'message' => $basic_message];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage();
|
||||||
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
return $this->fail('DELETE request failed, An error occurred' . $exception_ends_with);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \Exception('Unsupported HTTP method');
|
throw new \Exception('Unsupported HTTP method');
|
||||||
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Unsupported HTTP method");
|
||||||
// return $this->fail('Unsupported HTTP method');
|
// return $this->fail('Unsupported HTTP method');
|
||||||
}
|
}
|
||||||
return $this->respond($response);
|
return $response;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Handle the exception, you can log it or return an error response
|
// Handle the exception, you can log it or return an error response
|
||||||
return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
$exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage();
|
||||||
// return $this->fail($e->getMessage());
|
$this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]);
|
||||||
|
return $this->fail('An error occurred ' . $exception_ends_with);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_book_details($records, $wordpress_book_id)
|
public function save_book_details($records, $wordpress_book_id)
|
||||||
{
|
{
|
||||||
|
$this->logger->info("Api SaveBookDetails : records count = ".count($records).", wordpress Product Ref ID = ".$wordpress_book_id);
|
||||||
$api_model = new ApiIntegrationModel();
|
$api_model = new ApiIntegrationModel();
|
||||||
$message = "";
|
$extensive_correspondence = "";
|
||||||
|
$basic_message = "";
|
||||||
$book_id = "";
|
$book_id = "";
|
||||||
if (count($records) > 0 && !empty($wordpress_book_id)) {
|
if (count($records) > 0 && !empty($wordpress_book_id)) {
|
||||||
$where = ['wp_api_product_id' => $wordpress_book_id, 'isactive' => 1];
|
$where = ['wp_api_product_id' => $wordpress_book_id, 'isactive' => 1];
|
||||||
@ -108,11 +169,12 @@ class ApiIntegration extends ResourceController
|
|||||||
$where['book_id'] = $book_details['book_id'];
|
$where['book_id'] = $book_details['book_id'];
|
||||||
} // update means bookid where condition added : else no where condition added.
|
} // update means bookid where condition added : else no where condition added.
|
||||||
|
|
||||||
|
|
||||||
$countAll = $api_model->countAll('books', $where);
|
$countAll = $api_model->countAll('books', $where);
|
||||||
|
$this->logger->info(($countAll) ? "Api SaveBookDetails : in wordpress product ref ID = ".$wordpress_book_id." is available on Book table and its PrimaryKey = ".$book_id : "Api SaveBookDetails : in wordpress product ref ID = ".$wordpress_book_id." Not available on Book table");
|
||||||
$publisher = '';
|
$publisher = '';
|
||||||
$language = '';
|
$language = '';
|
||||||
$attributes = $records['attributes'];
|
$attributes = $records['attributes'];
|
||||||
|
|
||||||
if (count($attributes) > 0) {
|
if (count($attributes) > 0) {
|
||||||
foreach ($attributes as $att) {
|
foreach ($attributes as $att) {
|
||||||
if (isset($att->name) && $att->name == "Publisher") {
|
if (isset($att->name) && $att->name == "Publisher") {
|
||||||
@ -139,24 +201,31 @@ class ApiIntegration extends ResourceController
|
|||||||
$book_data['business_id'] = 1;
|
$book_data['business_id'] = 1;
|
||||||
$images = $records['images'];
|
$images = $records['images'];
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
if ((int)$countAll == 0) {
|
if ((int)$countAll == 0) {
|
||||||
$insert_result = $api_model->insertData('books', $book_data);
|
$insert_result = $api_model->insertData('books', $book_data);
|
||||||
$last_insert_book_id = $insert_result['info'];
|
$last_insert_book_id = $insert_result['info'];
|
||||||
$message .= $insert_result['info'] ? "Book id : " . $insert_result['info']
|
$extensive_correspondence .= $insert_result['info'] ? "Book id : " . $insert_result['info']
|
||||||
: "Err :" . $insert_result['err'];
|
: "Err :" . $insert_result['err'];
|
||||||
|
$basic_message .= $insert_result['info'] ? " Book id : " . $insert_result['info'] : "Book details Not Inserted";
|
||||||
|
$insert_result['info'] ? $this->logger->info("Api SaveBookDetails : Book id = ".$insert_result['info']):"";
|
||||||
|
$insert_result['err'] ? $this->logger->error("Api SaveBookDetails : Err = ".$insert_result['err']):"";
|
||||||
} else {
|
} else {
|
||||||
$last_insert_book_id = $book_id;
|
$last_insert_book_id = $book_id;
|
||||||
$book_where = ['book_id' => $book_id, 'isactive' => 1, 'wp_api_product_id' => $wordpress_book_id];
|
$book_where = ['book_id' => $book_id, 'isactive' => 1, 'wp_api_product_id' => $wordpress_book_id];
|
||||||
$update_result = $api_model->updateData('books', $book_data, $book_where);
|
$update_result = $api_model->updateData('books', $book_data, $book_where);
|
||||||
$message .= $update_result['info'] ? "Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")"
|
$extensive_correspondence .= $update_result['info'] ? "Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")"
|
||||||
: " ( Err :" . $update_result['err'] . ")";
|
: " ( Err :" . $update_result['err'] . ")";
|
||||||
|
$basic_message .= "Book id : " . $last_insert_book_id;
|
||||||
|
$update_result['info'] ? $this->logger->info("Api SaveBookDetails : Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")"):"";
|
||||||
|
$update_result['err'] ? $this->logger->error("Api SaveBookDetails : Err = ".$update_result['err']):"";
|
||||||
}
|
}
|
||||||
|
|
||||||
$book_image_data = [];
|
$this->logger->info("Api SaveBookDetails : Book images count : " .count($images));
|
||||||
|
|
||||||
if (count($images) > 0 && $last_insert_book_id != "") {
|
if (count($images) > 0 && $last_insert_book_id != "") {
|
||||||
$message .= " Its have " . count($images) . " Images ,";
|
$extensive_correspondence .= " Its have " . count($images) . " Images ,";
|
||||||
|
$basic_message .= " Its have " . count($images) . " Images";
|
||||||
|
$this->logger->info("Api SaveBookDetails : ".$extensive_correspondence);
|
||||||
$where = ['book_id' => (int)$last_insert_book_id, 'isactive' => 1];
|
$where = ['book_id' => (int)$last_insert_book_id, 'isactive' => 1];
|
||||||
$existing_images = $api_model->getData('book_images', $where);
|
$existing_images = $api_model->getData('book_images', $where);
|
||||||
$request_images = (array)$images;
|
$request_images = (array)$images;
|
||||||
@ -174,11 +243,14 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filteringExistingImagesWpApiId)) {
|
if (!empty($filteringExistingImagesWpApiId)) {
|
||||||
|
$this->logger->info("Api SaveBookDetails : Incoming Images Wp Id " .implode(",",$filteringRequestedImagesWpApiId));
|
||||||
|
$this->logger->info("Api SaveBookDetails : Existing Images Wp Id " .implode(",",$filteringExistingImagesWpApiId));
|
||||||
$A = $filteringExistingImagesWpApiId;
|
$A = $filteringExistingImagesWpApiId;
|
||||||
$B = $filteringRequestedImagesWpApiId;
|
$B = $filteringRequestedImagesWpApiId;
|
||||||
$missingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
$missingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
||||||
$commonElements = array_intersect($A, $B);
|
$commonElements = array_intersect($A, $B);
|
||||||
if (!empty($missingValues)) {
|
if (!empty($missingValues)) {
|
||||||
|
$this->logger->info("Api SaveBookDetails : Missing Images Wp Id " .implode(",",$missingValues)." Are inactived");
|
||||||
$inactive_where = ['isactive' => 1, 'book_id' => (int)$last_insert_book_id];
|
$inactive_where = ['isactive' => 1, 'book_id' => (int)$last_insert_book_id];
|
||||||
$inactive_whereIn[0] = 'wp_api_img_id';
|
$inactive_whereIn[0] = 'wp_api_img_id';
|
||||||
$inactive_whereIn[1] = $missingValues;
|
$inactive_whereIn[1] = $missingValues;
|
||||||
@ -195,7 +267,9 @@ class ApiIntegration extends ResourceController
|
|||||||
$whereIn = null;
|
$whereIn = null;
|
||||||
}
|
}
|
||||||
$lastestActiveBookImageData = $api_model->getData('book_images', $where, $whereIn);
|
$lastestActiveBookImageData = $api_model->getData('book_images', $where, $whereIn);
|
||||||
|
$this->logger->info("Api SaveBookDetails : lastest Active Book Image Data Count " .count($lastestActiveBookImageData));
|
||||||
|
$book_image_data = [];
|
||||||
|
$i = 0;
|
||||||
foreach ($images as $img) {
|
foreach ($images as $img) {
|
||||||
$bookImgId = null;
|
$bookImgId = null;
|
||||||
// Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id'
|
// Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id'
|
||||||
@ -214,106 +288,30 @@ class ApiIntegration extends ResourceController
|
|||||||
$book_image_data[$i]['isactive'] = 1;
|
$book_image_data[$i]['isactive'] = 1;
|
||||||
$book_image_data[$i]['wp_api_img_id'] = $img->id;
|
$book_image_data[$i]['wp_api_img_id'] = $img->id;
|
||||||
$book_image_data[$i]['book_img_id'] = $bookImgId;
|
$book_image_data[$i]['book_img_id'] = $bookImgId;
|
||||||
|
$this->logger->info("Api SaveBookDetails : Image Data = $i ");
|
||||||
$i++;
|
$i++;
|
||||||
} // image loop closed
|
} // image loop closed
|
||||||
$message .= (!empty($book_image_data) ? $api_model->insertAndUpdateChildDetails($book_image_data, 'book_images', 'book_img_id') : []);
|
$extensive_correspondence .= (!empty($book_image_data) ? $api_model->insertAndUpdateChildDetails($book_image_data, 'book_images', 'book_img_id') : []);
|
||||||
|
$this->logger->info("Api SaveBookDetails : ".$extensive_correspondence);
|
||||||
} //image count closed
|
} //image count closed
|
||||||
$response = ['status' => 200, 'message' => $message];
|
else{
|
||||||
|
$this->logger->error("Api SaveBookDetails : Err = Image Data Not Found");
|
||||||
|
}
|
||||||
|
$response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence];
|
||||||
} //if cond. closed
|
} //if cond. closed
|
||||||
else {
|
else {
|
||||||
$response = ['status' => 204, 'message' => 'Data No Found'];
|
$this->logger->error("Api SaveBookDetails : Err = Data Not Found");
|
||||||
|
$response = ['status' => 204, 'message' => 'Data Not Found'];
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function customer_api_integration()
|
|
||||||
{
|
|
||||||
$request = \Config\Services::request();
|
|
||||||
$message = "";
|
|
||||||
try {
|
|
||||||
switch ($this->request) {
|
|
||||||
case $this->request->is('put'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/customers?id=795;
|
|
||||||
$records = (array)$this->request->getVar();
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
if ($records['id'] == $id) {
|
|
||||||
$response = $this->save_customer_details($records, $id);
|
|
||||||
} else {
|
|
||||||
$response = ['status' => 404, 'message' => "ID Mismatched"];
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $this->request->is('post'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/customers;
|
|
||||||
$records = (array)$this->request->getVar();
|
|
||||||
$wordpress_customer_id = $records['id'];
|
|
||||||
$response = $this->save_customer_details($records, $wordpress_customer_id);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $request->is('get'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/customers?id=795;
|
|
||||||
// $url = http://localhost/vb_book/api/customers;
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
if ($id) {
|
|
||||||
$where = ['wp_api_customer_id' => (int)$id, 'isactive' => 1];
|
|
||||||
} else {
|
|
||||||
$where = ['isactive' => 1];
|
|
||||||
}
|
|
||||||
$api_model = new ApiIntegrationModel();
|
|
||||||
$customer_details = $api_model->setTable('customers')->where($where);
|
|
||||||
$response = ['status' => 200, 'message' => "Customer Details", "data" => $customer_details];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $request->is('delete'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/customers?id=795;
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
$api_model = new ApiIntegrationModel();
|
|
||||||
$where = ['isactive' => 1, 'wp_api_customer_id' => (int)$id];
|
|
||||||
$existing_customer_data = $api_model->getData('customers', $where);
|
|
||||||
if ((int)count($existing_customer_data) > 0) {
|
|
||||||
$customer_id = (int)$existing_customer_data[0]->customer_id;
|
|
||||||
$inactive_data['isactive'] = 0;
|
|
||||||
$update_where = ['isactive' => 1, 'customer_id' => $customer_id];
|
|
||||||
$api_model->updateData('customers', $inactive_data, $update_where);
|
|
||||||
$getExistingCustomerImageDetails = $api_model->getData('customer_addresses', $update_where);
|
|
||||||
if ($getExistingCustomerImageDetails) {
|
|
||||||
|
|
||||||
$api_model->updateData('customer_addresses', $inactive_data, $update_where);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = ['status' => 200, 'message' => "customer Details and Customer Addresses Details Are Inactived"];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// Handle DELETE-specific exception
|
|
||||||
return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new \Exception('Unsupported HTTP method');
|
|
||||||
// return $this->fail('Unsupported HTTP method');
|
|
||||||
}
|
|
||||||
return $this->respond($response);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// Handle the exception, you can log it or return an error response
|
|
||||||
return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
// return $this->fail($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save_customer_details($records, $wordpress_customer_id)
|
public function save_customer_details($records, $wordpress_customer_id)
|
||||||
{
|
{
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : records count = ".count($records).", wordpress Customer Ref ID = ".$wordpress_customer_id);
|
||||||
$api_model = new ApiIntegrationModel();
|
$api_model = new ApiIntegrationModel();
|
||||||
$message = "";
|
$extensive_correspondence = "";
|
||||||
|
$basic_message = "";
|
||||||
$customer_id = "";
|
$customer_id = "";
|
||||||
if (count($records) > 0 && !empty($wordpress_customer_id)) {
|
if (count($records) > 0 && !empty($wordpress_customer_id)) {
|
||||||
$where = ['wp_api_customer_id' => $wordpress_customer_id, 'isactive' => 1];
|
$where = ['wp_api_customer_id' => $wordpress_customer_id, 'isactive' => 1];
|
||||||
@ -322,7 +320,9 @@ class ApiIntegration extends ResourceController
|
|||||||
$customer_id = $customer_details['customer_id'];
|
$customer_id = $customer_details['customer_id'];
|
||||||
$where['customer_id'] = $customer_details['customer_id'];
|
$where['customer_id'] = $customer_details['customer_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$countAll = $api_model->countAll('customers', $where);
|
$countAll = $api_model->countAll('customers', $where);
|
||||||
|
$this->logger->info(($countAll) ? "Api SaveCustomerDetails : in wordpress customer ref ID = ".$wordpress_customer_id." is available on customer table and its PrimaryKey = ".$customer_id : "Api SaveBookDetails : in wordpress Customer ref ID = ".$wordpress_customer_id." Not available on Customer table");
|
||||||
|
|
||||||
$customer_data['first_name'] = $records['first_name'];
|
$customer_data['first_name'] = $records['first_name'];
|
||||||
$customer_data['last_name'] = $records['last_name'];
|
$customer_data['last_name'] = $records['last_name'];
|
||||||
@ -339,14 +339,20 @@ class ApiIntegration extends ResourceController
|
|||||||
if ((int)$countAll == 0) {
|
if ((int)$countAll == 0) {
|
||||||
$insert_result = $api_model->insertData('customers', $customer_data);
|
$insert_result = $api_model->insertData('customers', $customer_data);
|
||||||
$last_insert_customer_id = $insert_result['info'];
|
$last_insert_customer_id = $insert_result['info'];
|
||||||
$message .= $insert_result['info'] ? "Customer id : " . $insert_result['info']
|
$extensive_correspondence .= $insert_result['info'] ? "Customer id : " . $insert_result['info']
|
||||||
: "Err :" . $insert_result['err'];
|
: "Err :" . $insert_result['err'];
|
||||||
|
$basic_message .= $insert_result['info'] ? " Customer id : " . $insert_result['info'] : "Customer details Not Inserted";
|
||||||
|
$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 {
|
} else {
|
||||||
$last_insert_customer_id = $customer_id;
|
$last_insert_customer_id = $customer_id;
|
||||||
$customer_where = ['customer_id' => $customer_id, 'isactive' => 1, 'wp_api_customer_id' => $wordpress_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);
|
$update_result = $api_model->updateData('customers', $customer_data, $customer_where);
|
||||||
$message .= $update_result['info'] ? "Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")"
|
$extensive_correspondence .= $update_result['info'] ? "Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")"
|
||||||
: " ( Err :" . $update_result['err'] . ")";
|
: " ( Err :" . $update_result['err'] . ")";
|
||||||
|
$basic_message .= "Customer id : " . $last_insert_customer_id;
|
||||||
|
$update_result['info'] ? $this->logger->info("Api SaveCustomerDetails : Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")"):"";
|
||||||
|
$update_result['err'] ? $this->logger->error("Api SaveCustomerDetails : Err = ".$update_result['err']):"";
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0; $customer_billing_address_data = [];
|
$i = 0; $customer_billing_address_data = [];
|
||||||
@ -354,12 +360,15 @@ class ApiIntegration extends ResourceController
|
|||||||
|
|
||||||
if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];}
|
if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];}
|
||||||
if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];}
|
if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];}
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : billing count : " .count($billing));
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : shipping count : " .count($shipping));
|
||||||
// echo "Customer ID : ".$last_insert_customer_id." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)." <br/>";
|
// echo "Customer ID : ".$last_insert_customer_id." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)." <br/>";
|
||||||
|
|
||||||
if (count($billing) > 0 && $last_insert_customer_id != "") {
|
if (count($billing) > 0 && $last_insert_customer_id != "") {
|
||||||
|
|
||||||
$message .= " Its have " . count($billing) . " Billing address ,";
|
$extensive_correspondence .= " Its have " . count($billing) . " Billing address ,";
|
||||||
|
$basic_message .= " Its have " . count($billing) . " Billing address ,";
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence);
|
||||||
$where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>1];
|
$where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>1];
|
||||||
$existing_billing = $api_model->getData('customer_addresses', $where);
|
$existing_billing = $api_model->getData('customer_addresses', $where);
|
||||||
$request_billing = (array)$billing;
|
$request_billing = (array)$billing;
|
||||||
@ -377,11 +386,14 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filteringExistingBillingAddress)) {
|
if (!empty($filteringExistingBillingAddress)) {
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Incoming billing " .implode(",",$filteringExistingBillingAddress));
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Existing billing " .implode(",",$filteringRequestedBillingAddress));
|
||||||
$A = $filteringExistingBillingAddress;
|
$A = $filteringExistingBillingAddress;
|
||||||
$B = $filteringRequestedBillingAddress;
|
$B = $filteringRequestedBillingAddress;
|
||||||
$missingBillingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
$missingBillingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
||||||
$commonBillingElements = array_intersect($A, $B);
|
$commonBillingElements = array_intersect($A, $B);
|
||||||
if (!empty($missingBillingValues)) {
|
if (!empty($missingBillingValues)) {
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Missing billing " .implode(",",$missingBillingValues)." Are inactived");
|
||||||
$inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id,'address_type'=>1];
|
$inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id,'address_type'=>1];
|
||||||
$inactive_whereIn[0] = 'address_1';
|
$inactive_whereIn[0] = 'address_1';
|
||||||
$inactive_whereIn[1] = $missingBillingValues;
|
$inactive_whereIn[1] = $missingBillingValues;
|
||||||
@ -398,7 +410,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$whereIn = null;
|
$whereIn = null;
|
||||||
}
|
}
|
||||||
$lastestActiveBillingAdressData = $api_model->getData('customer_addresses', $where, $whereIn);
|
$lastestActiveBillingAdressData = $api_model->getData('customer_addresses', $where, $whereIn);
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : lastest Active billing Data Count " .count($lastestActiveBillingAdressData));
|
||||||
foreach ($billing as $bill) {
|
foreach ($billing as $bill) {
|
||||||
$billingAddressId = null;
|
$billingAddressId = null;
|
||||||
if ($bill->first_name != '') {
|
if ($bill->first_name != '') {
|
||||||
@ -424,17 +436,21 @@ class ApiIntegration extends ResourceController
|
|||||||
$customer_billing_address_data[$i]['email'] = isset($bill->email) ? $bill->email : '';
|
$customer_billing_address_data[$i]['email'] = isset($bill->email) ? $bill->email : '';
|
||||||
$customer_billing_address_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : '';
|
$customer_billing_address_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : '';
|
||||||
$customer_billing_address_data[$i]['customer_address_id'] = $billingAddressId;
|
$customer_billing_address_data[$i]['customer_address_id'] = $billingAddressId;
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Billing address has a value and Inserted ");
|
||||||
$i++;
|
$i++;
|
||||||
// echo "       Billing address has a value and Inserted ".$i." <br/>";
|
// echo "       Billing address has a value and Inserted ".$i." <br/>";
|
||||||
}else{
|
}else{
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Billing address has no value ");
|
||||||
// echo "       Keys are available but Billing address has no value; <br/>";
|
// echo "       Keys are available but Billing address has no value; <br/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$message .= (!empty($customer_billing_address_data) ? $api_model->insertAndUpdateChildDetails($customer_billing_address_data, 'customer_addresses', 'customer_address_id') : []);
|
$extensive_correspondence .= (!empty($customer_billing_address_data) ? $api_model->insertAndUpdateChildDetails($customer_billing_address_data, 'customer_addresses', 'customer_address_id') : []);
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (count($shipping) > 0 && $last_insert_customer_id != "") {
|
if (count($shipping) > 0 && $last_insert_customer_id != "") {
|
||||||
$message .= " Its have " . count($shipping) . " Shipping address ,";
|
$extensive_correspondence .= " Its have " . count($shipping) . " Shipping address ,";
|
||||||
|
$basic_message .= " Its have " . count($shipping) . " Shipping address .";
|
||||||
$where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>2];
|
$where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>2];
|
||||||
$existing_shipping = $api_model->getData('customer_addresses', $where);
|
$existing_shipping = $api_model->getData('customer_addresses', $where);
|
||||||
$request_shipping = (array)$shipping;
|
$request_shipping = (array)$shipping;
|
||||||
@ -452,6 +468,8 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filteringExistingShippingAddress)) {
|
if (!empty($filteringExistingShippingAddress)) {
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Incoming shipping " .implode(",",$filteringExistingShippingAddress));
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Existing shipping " .implode(",",$filteringExistingShippingAddress));
|
||||||
$A = $filteringExistingShippingAddress;
|
$A = $filteringExistingShippingAddress;
|
||||||
$B = $filteringRequestedShippingAddress;
|
$B = $filteringRequestedShippingAddress;
|
||||||
$missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
$missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
||||||
@ -461,6 +479,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$inactive_whereIn[0] = 'address_1';
|
$inactive_whereIn[0] = 'address_1';
|
||||||
$inactive_whereIn[1] = $missingShippingValues;
|
$inactive_whereIn[1] = $missingShippingValues;
|
||||||
$api_model->inactiveMissingDetails('customer_addresses', $inactive_where, $inactive_whereIn);
|
$api_model->inactiveMissingDetails('customer_addresses', $inactive_where, $inactive_whereIn);
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Missing Shipping " .implode(",",$missingShippingValues)." Are inactived");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,6 +492,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$whereIn = null;
|
$whereIn = null;
|
||||||
}
|
}
|
||||||
$lastestActiveShippingAdressData = $api_model->getData('customer_addresses', $where, $whereIn);
|
$lastestActiveShippingAdressData = $api_model->getData('customer_addresses', $where, $whereIn);
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : lastest Active Shipping Data Count " .count($lastestActiveShippingAdressData));
|
||||||
|
|
||||||
foreach ($shipping as $ship) {
|
foreach ($shipping as $ship) {
|
||||||
$shippingAddressId = null;
|
$shippingAddressId = null;
|
||||||
@ -499,108 +519,34 @@ class ApiIntegration extends ResourceController
|
|||||||
$customer_shipping_address_data[$j]['customer_id'] = $last_insert_customer_id;
|
$customer_shipping_address_data[$j]['customer_id'] = $last_insert_customer_id;
|
||||||
$customer_shipping_address_data[$j]['address_type'] = 2;
|
$customer_shipping_address_data[$j]['address_type'] = 2;
|
||||||
$customer_shipping_address_data[$j]['customer_address_id'] = $shippingAddressId;
|
$customer_shipping_address_data[$j]['customer_address_id'] = $shippingAddressId;
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Shipping address has a value and Inserted ");
|
||||||
$j++;
|
$j++;
|
||||||
// echo "        Shipping address has a value and Inserted ".$j." <br/>";
|
// echo "        Shipping address has a value and Inserted ".$j." <br/>";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : Shipping address has no value ");
|
||||||
// echo "        Keys are available but Shipping address has no value <br/>";
|
// echo "        Keys are available but Shipping address has no value <br/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$message .= (!empty($customer_shipping_address_data) ? $api_model->insertAndUpdateChildDetails($customer_shipping_address_data, 'customer_addresses', 'customer_address_id') : []);
|
$extensive_correspondence .= (!empty($customer_shipping_address_data) ? $api_model->insertAndUpdateChildDetails($customer_shipping_address_data, 'customer_addresses', 'customer_address_id') : []);
|
||||||
|
$this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence);
|
||||||
|
}else{
|
||||||
|
$this->logger->error("Api SaveCustomerDetails : Err = Address Data Not Found");
|
||||||
}
|
}
|
||||||
$response = ['status' => 200, 'message' => $message];
|
$response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence];
|
||||||
} //if cond. closed
|
} //if cond. closed
|
||||||
else {
|
else {
|
||||||
|
$this->logger->error("Api SaveCustomerDetails : Err = Data Not Found");
|
||||||
$response = ['status' => 204, 'message' => 'Data No Found'];
|
$response = ['status' => 204, 'message' => 'Data No Found'];
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sales_api_integration()
|
|
||||||
{
|
|
||||||
$request = \Config\Services::request();
|
|
||||||
$message = "";
|
|
||||||
try {
|
|
||||||
switch ($this->request) {
|
|
||||||
case $this->request->is('put'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/orders?id=795;
|
|
||||||
$records = (array)$this->request->getVar();
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
if ($records['id'] == $id) {
|
|
||||||
$response = $this->save_sales_details($records, $id);
|
|
||||||
} else {
|
|
||||||
$response = ['status' => 404, 'message' => "ID Mismatched"];
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $this->request->is('post'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/orders;
|
|
||||||
$records = (array)$this->request->getVar();
|
|
||||||
$wordpress_order_id = $records['id'];
|
|
||||||
$response = $this->save_sales_details($records, $wordpress_order_id);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $request->is('get'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/orders?id=795;
|
|
||||||
// $url = http://localhost/vb_book/api/orders;
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
if ($id) {
|
|
||||||
$where = ['wp_api_order_id' => (int)$id, 'isactive' => 1];
|
|
||||||
} else {
|
|
||||||
$where = ['isactive' => 1];
|
|
||||||
}
|
|
||||||
$api_model = new ApiIntegrationModel();
|
|
||||||
$invoice_details = $api_model->setTable('invoice')->where($where);
|
|
||||||
$response = ['status' => 200, 'message' => "Invoice Details", "data" => $invoice_details];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case $request->is('delete'):
|
|
||||||
try {
|
|
||||||
// $url = http://localhost/vb_book/api/orders?id=795;
|
|
||||||
$id = $this->request->getVar('id');
|
|
||||||
$api_model = new ApiIntegrationModel();
|
|
||||||
$where = ['isactive' => 1, 'wp_api_order_id' => (int)$id];
|
|
||||||
$existing_invoice_data = $api_model->getData('invoice', $where);
|
|
||||||
if ((int)count($existing_invoice_data) > 0) {
|
|
||||||
$invoice_id = (int)$existing_invoice_data[0]->invoice_id;
|
|
||||||
$inactive_data['isactive'] = 0;
|
|
||||||
$update_where = ['isactive' => 1, 'invoice_id' => $invoice_id];
|
|
||||||
$api_model->updateData('invoice', $inactive_data, $update_where);
|
|
||||||
$getExistingInvoiceItemsDetails = $api_model->getData('invoiceitems', $update_where);
|
|
||||||
if ($getExistingInvoiceItemsDetails) {
|
|
||||||
$api_model->updateData('invoiceitems', $inactive_data, $update_where);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = ['status' => 200, 'message' => "Invoice Details and Invoice Items Details Are Inactived"];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// Handle DELETE-specific exception
|
|
||||||
return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new \Exception('Unsupported HTTP method');
|
|
||||||
// return $this->fail('Unsupported HTTP method');
|
|
||||||
}
|
|
||||||
return $this->respond($response);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// Handle the exception, you can log it or return an error response
|
|
||||||
return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
|
|
||||||
// return $this->fail($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save_sales_details($records, $wordpress_order_id){
|
public function save_sales_details($records, $wordpress_order_id){
|
||||||
|
$this->logger->info("Api SaveSalesDetails : records count = ".count($records).", wordpress Order Ref ID = ".$wordpress_order_id);
|
||||||
|
$basic_message="";
|
||||||
$api_model = new ApiIntegrationModel();
|
$api_model = new ApiIntegrationModel();
|
||||||
$message = "";
|
$extensive_correspondence = "";
|
||||||
$invoice_id = "";
|
$invoice_id = "";
|
||||||
if (count($records) > 0 && !empty($wordpress_order_id)) {
|
if (count($records) > 0 && !empty($wordpress_order_id)) {
|
||||||
$where = ['wp_api_order_id' => $wordpress_order_id, 'isactive' => 1];
|
$where = ['wp_api_order_id' => $wordpress_order_id, 'isactive' => 1];
|
||||||
@ -610,6 +556,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$where['invoice_id'] = (int)$invoice_id;
|
$where['invoice_id'] = (int)$invoice_id;
|
||||||
}
|
}
|
||||||
$countAll = $api_model->countAll('invoice', $where);
|
$countAll = $api_model->countAll('invoice', $where);
|
||||||
|
$this->logger->info(($countAll) ? "Api SaveSalesDetails : in wordpress product ref ID = ".$wordpress_order_id." is available on Invoice table and its PrimaryKey = ".$invoice_id : "Api SaveSalesDetails : in wordpress order ref ID = ".$wordpress_order_id." Not available on Invoice table");
|
||||||
$billing_addr = "";$shipping_addr = "";
|
$billing_addr = "";$shipping_addr = "";
|
||||||
$lineitems_array = [];
|
$lineitems_array = [];
|
||||||
$billing_array = []; $shipping_array = [];
|
$billing_array = []; $shipping_array = [];
|
||||||
@ -669,22 +616,31 @@ class ApiIntegration extends ResourceController
|
|||||||
if ((int)$countAll == 0) {
|
if ((int)$countAll == 0) {
|
||||||
$insert_result = $api_model->insertData('invoice', $invoice_data);
|
$insert_result = $api_model->insertData('invoice', $invoice_data);
|
||||||
$last_insert_invoice_id = $insert_result['info'];
|
$last_insert_invoice_id = $insert_result['info'];
|
||||||
$message .= $insert_result['info'] ? "Invoice id : " . $insert_result['info']
|
$extensive_correspondence .= $insert_result['info'] ? "Invoice id : " . $insert_result['info']
|
||||||
: "Err :" . $insert_result['err'];
|
: "Err :" . $insert_result['err'];
|
||||||
|
$basic_message .= $insert_result['info'] ? " Invoice id : " . $insert_result['info'] : "Invoice details Not Inserted";
|
||||||
|
$insert_result['info'] ? $this->logger->info("Api SaveSalesDetails : Invoice id = ".$insert_result['info']):"";
|
||||||
|
$insert_result['err'] ? $this->logger->error("Api SaveSalesDetails : Err = ".$insert_result['err']):"";
|
||||||
} else {
|
} else {
|
||||||
$last_insert_invoice_id = $invoice_id;
|
$last_insert_invoice_id = $invoice_id;
|
||||||
$customer_where = ['invoice_id' => $invoice_id, 'isactive' => 1, 'wp_api_order_id' => $wordpress_order_id];
|
$customer_where = ['invoice_id' => $invoice_id, 'isactive' => 1, 'wp_api_order_id' => $wordpress_order_id];
|
||||||
$update_result = $api_model->updateData('invoice', $invoice_data, $customer_where);
|
$update_result = $api_model->updateData('invoice', $invoice_data, $customer_where);
|
||||||
$message .= $update_result['info'] ? "Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"
|
$extensive_correspondence .= $update_result['info'] ? "Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"
|
||||||
: " ( Err :" . $update_result['err'] . ")";
|
: " ( Err :" . $update_result['err'] . ")";
|
||||||
|
$basic_message .= "Invoice id : " . $last_insert_invoice_id;
|
||||||
|
$update_result['info'] ? $this->logger->info("Api SaveSalesDetails : Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"):"";
|
||||||
|
$update_result['err'] ? $this->logger->error("Api SaveSalesDetails : Err = ".$update_result['err']):"";
|
||||||
}
|
}
|
||||||
|
|
||||||
$line_item_data = [];
|
$line_item_data = [];
|
||||||
$shipping_line_item_data = [];
|
$shipping_line_item_data = [];
|
||||||
$i = 0;$j=0;
|
$i = 0;$j=0;
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Invoice items count : " .count($lineitems_array));
|
||||||
if (count($lineitems_array) > 0 && $last_insert_invoice_id != "") {
|
if (count($lineitems_array) > 0 && $last_insert_invoice_id != "") {
|
||||||
$message .= " Its have " . count($lineitems_array) . " LineItems ,";
|
$extensive_correspondence .= " Its have " . count($lineitems_array) . " LineItems ,";
|
||||||
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
|
$basic_message .= " Its have " . count($lineitems_array) . " LineItems";
|
||||||
|
$this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence);
|
||||||
|
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1, 'quantity != '=>0];
|
||||||
$existing_invoiceitem = $api_model->getData('invoiceitems', $where);
|
$existing_invoiceitem = $api_model->getData('invoiceitems', $where);
|
||||||
$request_invoiceitem = (array)$lineitems_array;
|
$request_invoiceitem = (array)$lineitems_array;
|
||||||
|
|
||||||
@ -701,11 +657,14 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filteringExistingInvoiceItemWpApiId)) {
|
if (!empty($filteringExistingInvoiceItemWpApiId)) {
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Incoming InvoiceItem Wp Id " .implode(",",$filteringRequestedInvoiceItemWpApiId));
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Existing InvoiceItem Wp Id " .implode(",",$filteringExistingInvoiceItemWpApiId));
|
||||||
$A = $filteringExistingInvoiceItemWpApiId;
|
$A = $filteringExistingInvoiceItemWpApiId;
|
||||||
$B = $filteringRequestedInvoiceItemWpApiId;
|
$B = $filteringRequestedInvoiceItemWpApiId;
|
||||||
$missingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
$missingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
||||||
$commonElements = array_intersect($A, $B);
|
$commonElements = array_intersect($A, $B);
|
||||||
if (!empty($missingValues)) {
|
if (!empty($missingValues)) {
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Missing InvoiceItem Wp Id " .implode(",",$missingValues)." Are inactived");
|
||||||
$inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id];
|
$inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id];
|
||||||
$inactive_whereIn[0] = 'wp_api_line_items_id';
|
$inactive_whereIn[0] = 'wp_api_line_items_id';
|
||||||
$inactive_whereIn[1] = $missingValues;
|
$inactive_whereIn[1] = $missingValues;
|
||||||
@ -714,7 +673,7 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
|
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1, 'quantity != '=>0];
|
||||||
if (!empty($commonElements)) {
|
if (!empty($commonElements)) {
|
||||||
$whereIn[0] = 'wp_api_line_items_id';
|
$whereIn[0] = 'wp_api_line_items_id';
|
||||||
$whereIn[1] = $commonElements;
|
$whereIn[1] = $commonElements;
|
||||||
@ -722,6 +681,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$whereIn = null;
|
$whereIn = null;
|
||||||
}
|
}
|
||||||
$lastestActiveInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn);
|
$lastestActiveInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn);
|
||||||
|
$this->logger->info("Api SaveSalesDetails : lastest Active Invoice Items Data Count " .count($lastestActiveInvoiceitemsData));
|
||||||
|
|
||||||
foreach ($lineitems_array as $ii) {
|
foreach ($lineitems_array as $ii) {
|
||||||
$invoiceItemsId = null;
|
$invoiceItemsId = null;
|
||||||
@ -747,17 +707,24 @@ class ApiIntegration extends ResourceController
|
|||||||
$line_item_data[$i]['invoice_child_id'] = $invoiceItemsId;
|
$line_item_data[$i]['invoice_child_id'] = $invoiceItemsId;
|
||||||
$line_item_data[$i]['wp_api_line_items_id'] = $ii->id;
|
$line_item_data[$i]['wp_api_line_items_id'] = $ii->id;
|
||||||
$line_item_data[$i]['invoice_id'] = $last_insert_invoice_id;
|
$line_item_data[$i]['invoice_id'] = $last_insert_invoice_id;
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Invoiceitem Data inx = $i ");
|
||||||
$i++;
|
$i++;
|
||||||
} // line item loop closed
|
} // line item loop closed
|
||||||
$message .= (!empty($line_item_data) ? $api_model->insertAndUpdateChildDetails($line_item_data, 'invoiceitems', 'invoice_child_id') : []);
|
$extensive_correspondence .= (!empty($line_item_data) ? $api_model->insertAndUpdateChildDetails($line_item_data, 'invoiceitems', 'invoice_child_id') : []);
|
||||||
|
$this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
$this->logger->error("Api SaveSalesDetails : Err = Invoice items Data Not Found");
|
||||||
|
}
|
||||||
$shipping_lineitems_array = $records['shipping_lines'];
|
$shipping_lineitems_array = $records['shipping_lines'];
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Shipping Invoice items count : " .count($shipping_lineitems_array));
|
||||||
if (count($shipping_lineitems_array) > 0 && $last_insert_invoice_id != "") {
|
if (count($shipping_lineitems_array) > 0 && $last_insert_invoice_id != "") {
|
||||||
$message .= " Its have " . count($shipping_lineitems_array) . " shipping details ,";
|
$extensive_correspondence .= " Its have " . count($shipping_lineitems_array) . " shipping details ,";
|
||||||
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
|
$basic_message .= " and Its have " . count($shipping_lineitems_array) . " shipping details";
|
||||||
$existing_shipping_invoiceitem = $api_model->getData('invoiceitems', $where);
|
$this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence);
|
||||||
|
$shipping_where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1,'quantity'=>0];
|
||||||
|
$existing_shipping_invoiceitem = $api_model->getData('invoiceitems', $shipping_where);
|
||||||
$request_shipping_invoiceitem = (array)$shipping_lineitems_array;
|
$request_shipping_invoiceitem = (array)$shipping_lineitems_array;
|
||||||
|
|
||||||
$filteringExistingShippingInvoiceItemWpApiId = [];
|
$filteringExistingShippingInvoiceItemWpApiId = [];
|
||||||
@ -773,11 +740,15 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($filteringExistingShippingInvoiceItemWpApiId)) {
|
if (!empty($filteringExistingShippingInvoiceItemWpApiId)) {
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Incoming InvoiceItem (Shipping) Wp Id " .implode(",",$filteringRequestedShippingInvoiceItemWpApiId));
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Existing InvoiceItem (Shipping) Wp Id " .implode(",",$filteringExistingShippingInvoiceItemWpApiId));
|
||||||
$A = $filteringExistingShippingInvoiceItemWpApiId;
|
$A = $filteringExistingShippingInvoiceItemWpApiId;
|
||||||
$B = $filteringRequestedShippingInvoiceItemWpApiId;
|
$B = $filteringRequestedShippingInvoiceItemWpApiId;
|
||||||
|
|
||||||
$missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
$missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only
|
||||||
$commonShippingElements = array_intersect($A, $B);
|
$commonShippingElements = array_intersect($A, $B);
|
||||||
if (!empty($missingShippingValues)) {
|
if (!empty($missingShippingValues)) {
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Missing InvoiceItem (shipping) Wp Id " .implode(",",$missingShippingValues)." Are inactived");
|
||||||
$inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id];
|
$inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id];
|
||||||
$inactive_whereIn[0] = 'wp_api_line_items_id';
|
$inactive_whereIn[0] = 'wp_api_line_items_id';
|
||||||
$inactive_whereIn[1] = $missingShippingValues;
|
$inactive_whereIn[1] = $missingShippingValues;
|
||||||
@ -786,7 +757,7 @@ class ApiIntegration extends ResourceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
|
$where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1,'quantity'=>0];
|
||||||
if (!empty($commonShippingElements)) {
|
if (!empty($commonShippingElements)) {
|
||||||
$whereIn[0] = 'wp_api_line_items_id';
|
$whereIn[0] = 'wp_api_line_items_id';
|
||||||
$whereIn[1] = $commonShippingElements;
|
$whereIn[1] = $commonShippingElements;
|
||||||
@ -794,6 +765,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$whereIn = null;
|
$whereIn = null;
|
||||||
}
|
}
|
||||||
$lastestActiveShippingInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn);
|
$lastestActiveShippingInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn);
|
||||||
|
$this->logger->info("Api SaveSalesDetails : lastest Active Invoice Item (shipping) Data Count " .count($lastestActiveShippingInvoiceitemsData));
|
||||||
|
|
||||||
foreach ($shipping_lineitems_array as $sii) {
|
foreach ($shipping_lineitems_array as $sii) {
|
||||||
$shippingInvoiceItemsId = null;
|
$shippingInvoiceItemsId = null;
|
||||||
@ -819,13 +791,19 @@ class ApiIntegration extends ResourceController
|
|||||||
$shipping_line_item_data[$j]['invoice_child_id'] = $shippingInvoiceItemsId;
|
$shipping_line_item_data[$j]['invoice_child_id'] = $shippingInvoiceItemsId;
|
||||||
$shipping_line_item_data[$j]['wp_api_line_items_id'] = $sii->id;
|
$shipping_line_item_data[$j]['wp_api_line_items_id'] = $sii->id;
|
||||||
$shipping_line_item_data[$j]['invoice_id'] = $last_insert_invoice_id;
|
$shipping_line_item_data[$j]['invoice_id'] = $last_insert_invoice_id;
|
||||||
|
$this->logger->info("Api SaveSalesDetails : Invoiceitem Data For Shipping inx = $j ");
|
||||||
$j++;
|
$j++;
|
||||||
} // line item loop closed
|
} // line item loop closed
|
||||||
$message .= (!empty($shipping_line_item_data) ? $api_model->insertAndUpdateChildDetails($shipping_line_item_data, 'invoiceitems', 'invoice_child_id') : []);
|
$extensive_correspondence .= (!empty($shipping_line_item_data) ? $api_model->insertAndUpdateChildDetails($shipping_line_item_data, 'invoiceitems', 'invoice_child_id') : []);
|
||||||
|
$this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence);
|
||||||
}
|
}
|
||||||
$response = ['status' => 200, 'message' => $message];
|
else{
|
||||||
|
$this->logger->error("Api SaveSalesDetails : Err = Invoice items (Shipping) Data Not Found");
|
||||||
|
}
|
||||||
|
$response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$this->logger->error("Api SaveSalesDetails : Err = Data Not Found");
|
||||||
$response = ['status' => 204, 'message' => 'Data No Found'];
|
$response = ['status' => 204, 'message' => 'Data No Found'];
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class Authentication extends BaseController
|
|||||||
public function auth_confirm_mail()
|
public function auth_confirm_mail()
|
||||||
{
|
{
|
||||||
// Get the email address from the request
|
// Get the email address from the request
|
||||||
$email = $this->request->getGet('email');
|
$mail_id = $this->request->getGet('email');
|
||||||
$url_domain = base_url();
|
$url_domain = base_url();
|
||||||
|
|
||||||
// Validate the email address
|
// Validate the email address
|
||||||
@ -99,43 +99,32 @@ class Authentication extends BaseController
|
|||||||
|
|
||||||
// Check if the email exists in the database
|
// Check if the email exists in the database
|
||||||
$auth_model = new AuthenticationModel();
|
$auth_model = new AuthenticationModel();
|
||||||
// $user = $auth_model->where('email', $email)->first();
|
// $user = $auth_model->where('email', $mail_id)->first();
|
||||||
$where = ['email' => $email, 'isactive' => 1];
|
$where = ['email' => $mail_id, 'isactive' => 1];
|
||||||
$user = $auth_model->where($where)->first();
|
$user = $auth_model->where($where)->first();
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$this->logger->error('There is no user enteries against given mail');
|
$this->logger->error('There is no user enteries against given mail');
|
||||||
return redirect()->back()->withInput()->with('error', 'There is no user enteries against given mail');
|
return redirect()->back()->withInput()->with('error', 'There is no user enteries against given mail');
|
||||||
} else {
|
} else {
|
||||||
$data['email'] = $email;
|
$data['mail_id'] = $mail_id;
|
||||||
// Generate a unique token for password reset
|
// Generate a unique token for password reset
|
||||||
$token = bin2hex(random_bytes(32));
|
$token = bin2hex(random_bytes(32));
|
||||||
$content = "Click the link below to reset your password : " . $url_domain . "reset_password?email=" . $email . "&token=" . $token;
|
$content = "Click the link below to reset your password : " . $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token;
|
||||||
// $email = \Config\Services::email();
|
$email = \Config\Services::email();
|
||||||
// $email->setTo('sanjeev.p@venbainfotech.com');
|
// $recipient = 'venbalap08@gmail.com';
|
||||||
// $email->setFrom('venbalap08@gmail.com', 'BB-VBP');
|
$recipient = $mail_id;
|
||||||
// $email->setSubject('BB-VBP Password Reset');
|
|
||||||
// $email->setMessage($content);
|
|
||||||
|
|
||||||
|
// Compose the email
|
||||||
|
$email->setTo($recipient);
|
||||||
// $email->setTo('venbalap08@gmail.com');
|
$email->setFrom('no-reply@tripapprovaltool.com', 'BB-VBP');
|
||||||
// $email->setFrom('venbalap08@gmail.com');
|
$email->setSubject('Email Notification');
|
||||||
// $email->setSubject('Password Reset Testing');
|
// $email->setMessage('This is a notification email from CodeIgniter.');
|
||||||
// $email->setMessage('ZXER');
|
$email->setMessage($content);
|
||||||
|
|
||||||
|
|
||||||
// if ($email->send()) {
|
|
||||||
// // Email sent successfully
|
|
||||||
// return view('auth_confirm_mail', $data);
|
|
||||||
// } else {
|
|
||||||
// $this->logger->error('Email Not Sended,Try Again');
|
|
||||||
// return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again');
|
|
||||||
// }
|
|
||||||
|
|
||||||
$update_token['reset_link'] = $token;
|
$update_token['reset_link'] = $token;
|
||||||
$auth_model->update($user['user_id'], $update_token);
|
$auth_model->update($user['user_id'], $update_token);
|
||||||
$data['link'] = $url_domain . "auth_reset_password?email=" . $email . "&token=" . $token;
|
$data['link'] = $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token;
|
||||||
// Retrieve flashed session data
|
// Retrieve flashed session data
|
||||||
$successMessage = session()->getFlashdata('success');
|
$successMessage = session()->getFlashdata('success');
|
||||||
$validationErrors = session()->getFlashdata('error');
|
$validationErrors = session()->getFlashdata('error');
|
||||||
@ -144,7 +133,14 @@ class Authentication extends BaseController
|
|||||||
// Here, we'll use the default View class for demonstration purposes
|
// Here, we'll use the default View class for demonstration purposes
|
||||||
$data['successMessage'] = $successMessage;
|
$data['successMessage'] = $successMessage;
|
||||||
$data['validationErrors'] = $validationErrors;
|
$data['validationErrors'] = $validationErrors;
|
||||||
|
// return view('auth_confirm_mail', $data);
|
||||||
|
if ($email->send()) {
|
||||||
|
// Email sent successfully
|
||||||
return view('auth_confirm_mail', $data);
|
return view('auth_confirm_mail', $data);
|
||||||
|
} else {
|
||||||
|
$this->logger->error('Email Not Sended,Try Again');
|
||||||
|
return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
app/Controllers/Notifications.php
Executable file
21
app/Controllers/Notifications.php
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
class Notifications extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index($phoneNumber,$message)
|
||||||
|
{
|
||||||
|
// Sanitize phone number to remove special characters and spaces
|
||||||
|
$phoneNumber = preg_replace('/[^0-9]/', '', $phoneNumber);
|
||||||
|
|
||||||
|
// Construct the WhatsApp link
|
||||||
|
$whatsappLink = "https://wa.me/{$phoneNumber}?text=" . urlencode($message);
|
||||||
|
|
||||||
|
// Redirect to the WhatsApp link
|
||||||
|
return redirect()->to($whatsappLink);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
function perform_http_request($method, $url, $data = false) {
|
function perform_http_request_old($method, $url, $data = false) {
|
||||||
$username = "ck_935889d13267b63c2341168e42ffafe3c1ee831a";
|
$username = "ck_935889d13267b63c2341168e42ffafe3c1ee831a";
|
||||||
$password = "cs_6ce1321c3f08049dfb3c8098ea21137796446bc4";
|
$password = "cs_6ce1321c3f08049dfb3c8098ea21137796446bc4";
|
||||||
$encodekey = base64_encode($username.':'.$password);
|
$encodekey = base64_encode($username.':'.$password);
|
||||||
|
|||||||
22
app/Models/NotificationModel.php
Normal file
22
app/Models/NotificationModel.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
class NotificationModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'users';
|
||||||
|
protected $primaryKey = 'user_id';
|
||||||
|
protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id'];
|
||||||
|
|
||||||
|
public function saveData($data, $id = null)
|
||||||
|
{
|
||||||
|
if ($id === null) {
|
||||||
|
// Insert new record
|
||||||
|
return $this->insert($data);
|
||||||
|
} else {
|
||||||
|
// Update existing record
|
||||||
|
return $this->update($id, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -103,12 +103,12 @@
|
|||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<h3>Success !</h3>
|
<h3>Success !</h3>
|
||||||
<!-- <p class="text-muted mt-2"> A email has been send to <span class="font-weight-medium"><?= $email; ?></span>.
|
<p class="text-muted mt-2"> A email has been send to <span class="font-weight-medium"><?= $mail_id; ?></span>.
|
||||||
Please check for an email from company and click on the included link to
|
Please check for an email from company and click on the included link to
|
||||||
reset your password. </p>
|
reset your password. </p>
|
||||||
|
|
||||||
<a href="<?= base_url(); ?>" class="btn btn-block btn-primary waves-effect waves-light mt-3">Back to Home</a> -->
|
<a href="<?= base_url(); ?>" class="btn btn-block btn-primary waves-effect waves-light mt-3">Back to Home</a>
|
||||||
<a href="<?= $link; ?>" class="btn btn-block btn-primary waves-effect waves-light mt-3" target="_blank">Alternative So Click here</a>
|
<!-- <a href="<?= $link; ?>" class="btn btn-block btn-primary waves-effect waves-light mt-3" target="_blank">Alternative So Click here</a> -->
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- end card-body -->
|
</div> <!-- end card-body -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user