diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index 4f636275..d3df0db2 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -96,8 +96,8 @@ define('EVENT_PRIORITY_HIGH', 10);
/**
* Constants For Api Integration.
*/
-define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/');
-define('VB_BOOKS', VB_APIURL.'products');
-define('VB_CUSTOMERS', VB_APIURL.'customers');
+// define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/');
+// define('VB_BOOKS', VB_APIURL.'products');
+// define('VB_CUSTOMERS', VB_APIURL.'customers');
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 709ed250..0864bbc5 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -84,8 +84,10 @@ $routes->post("insert_scheme/", "Scheme::insert_scheme");
$routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1");
# Api integration Routes
-$routes->get("book_api_integration", "Books::apiintegration");
-$routes->get("customer_api_integration", "Customer::apiintegration");
+$routes->group("api", function ($routes) {
+ $routes->post("create_products/", "ApiIntegration::save_book_details");
+ $routes->post("create_customers/", "ApiIntegration::save_customer_details");
+});
/*
* --------------------------------------------------------------------
diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php
new file mode 100644
index 00000000..8afc8314
--- /dev/null
+++ b/app/Controllers/ApiIntegration.php
@@ -0,0 +1,180 @@
+is('post')) {
+ $records = (array)$request->getVar();
+ if (count($records) > 0 && $records['status'] == "publish" && !empty($records['id'])) {
+ $where = ['wp_api_id' => $records['id']];
+ $countAll = $api_model->countAll('books', $where);
+ if ((int)$countAll == 0) {
+ $publisher = '';
+ $language = '';
+ $attributes = $records['attributes'];
+ if (count($attributes) > 0) {
+ foreach ($attributes as $att) {
+ if ($att->name == "Publisher") {
+ $publisher = implode(", ", $att->options);
+ }
+ if ($att->name == "Book Author") {
+ $publisher .= implode(", ", $att->options) . "(Book Author)";
+ }
+ if ($att->name == "Book Language") {
+ $language = implode(", ", $att->options);
+ }
+ }
+ }
+ $insertion_data['wp_api_id'] = $records['id'];
+ $insertion_data['title'] = $records['name'];
+ $insertion_data['publication_date'] = $records['date_created'];
+ $insertion_data['publisher'] = $publisher;
+ $insertion_data['genre'] = $records['description'];
+ $insertion_data['language'] = $language;
+ $insertion_data['description'] = $records['short_description'];
+ $insertion_data['page_count'] = '';
+ $insertion_data['price'] = $records['sale_price'] != '' ? $records['sale_price'] : $records['regular_price'];
+ $insertion_data['created_by'] = 77;
+ $insertion_data['isactive'] = 1;
+ $insertion_data['business_id'] = 1;
+ $images = $records['images'];
+ $i = 0;
+ $lastInsertId = $api_model->insertData('books', $insertion_data);
+ $insertion_img_data = [];
+ $message .= "book ID : " . $lastInsertId . " have Imgs" . count($images) . "
";
+ // echo "book ID : ".$lastInsertId." have Imgs".count($images)."
";
+ if (count($images) > 0) {
+ foreach ($images as $img) {
+ $insertion_img_data[$i]['img_name'] = $img->src;
+ $insertion_img_data[$i]['is_cover'] = 0;
+ $insertion_img_data[$i]['type'] = 2;
+ $insertion_img_data[$i]['book_id'] = $lastInsertId;
+ $insertion_img_data[$i]['created_by'] = 777;
+ $insertion_img_data[$i]['isactive'] = 1;
+ $i++;
+ } // image loop closed
+ $api_model->insertImagesBatch($insertion_img_data);
+ $message .= "book ID : " . $lastInsertId . " Img. Batch Inserted Done
";
+ // echo " Img Batch Inserted Done. ".$i. "
";
+ } //image count closed
+ $response = ['status' => 200, 'message' => $message, 'data' => array()];
+ } else {
+ $response = ['status' => 204, 'message' => 'Data Already Exist', 'data' => array()];
+ }
+ } //if cond. closed
+ } else {
+ $response = ['status' => 204, 'message' => 'Invaild Method', 'data' => array()];
+ }
+ return $this->respond($response);
+ }
+
+ public function save_customer_details()
+ {
+
+ $request = \Config\Services::request();
+ $api_model = new ApiIntegrationModel();
+ $message = "";
+
+ if ($request->is('post')) {
+ $records = (array)$request->getVar();
+ $message = "Reponse Count : ".count($records)."
";
+ $x=0;
+ $records = (array)$request->getVar();
+ if (count($records) > 0 && !empty($records['id'])) {
+ $where = ['wp_api_id' => $records['id']];
+ $countAll = $api_model->countAll('customers', $where);
+ if ((int)$countAll == 0) {
+ $insertion_data['wp_api_id'] = $records['id'];
+ $insertion_data['first_name'] = $records['first_name'];
+ $insertion_data['last_name'] = $records['last_name'];
+ $insertion_data['type'] = $records['role'];
+ $insertion_data['email'] = $records['email'];
+ $insertion_data['mode'] = 'online';
+ $insertion_data['created_by'] = 777;
+ $insertion_data['business_id'] = 7;
+ $billing = $records['billing'];
+ $shipping = $records['shipping'];
+ $lastInsertId = $api_model->insertData('customers', $insertion_data);
+ $insertion_baddress_data = [];$insertion_saddress_data = [];
+ $i = 0; $j = 0;
+
+ if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];}
+ if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];}
+ $message .= "Customer ID : ".$lastInsertId." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)."
";
+ if (count($billing) > 0) {
+ foreach ($billing as $bill) {
+ if ($bill->first_name !== '') {
+ $insertion_baddress_data[$i]['first_name'] = $bill->first_name;
+ $insertion_baddress_data[$i]['last_name'] = $bill->last_name;
+ $insertion_baddress_data[$i]['company'] = $bill->company;
+ $insertion_baddress_data[$i]['address_1'] = $bill->address_1;
+ $insertion_baddress_data[$i]['address_2'] = $bill->address_2;
+ $insertion_baddress_data[$i]['city'] = $bill->city;
+ $insertion_baddress_data[$i]['state'] = $bill->state;
+ $insertion_baddress_data[$i]['country'] = $bill->country;
+ $insertion_baddress_data[$i]['postal_code'] = $bill->postcode;
+ $insertion_baddress_data[$i]['customer_id'] = $lastInsertId;
+ $insertion_baddress_data[$i]['address_type'] = 1;
+ $insertion_baddress_data[$i]['created_by'] = 777;
+ $insertion_baddress_data[$i]['email'] = isset($bill->email) ? $bill->email : '';
+ $insertion_baddress_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : '';
+ $i++;
+ $message .= " Billing address has a value and Inserted ".$i."
";
+ }else{
+ $message .= " Keys are available but Billing address has no value;
";
+ }
+ }
+ (!empty($insertion_baddress_data) ? $api_model->insertAddressBatch($insertion_baddress_data) : "");
+ }
+ if (count($shipping) > 0) {
+ foreach ($shipping as $ship) {
+ if ($ship->first_name !== '') {
+ $insertion_saddress_data[$j]['first_name'] = $ship->first_name;
+ $insertion_saddress_data[$j]['last_name'] = $ship->last_name;
+ $insertion_saddress_data[$j]['company'] = $ship->company;
+ $insertion_saddress_data[$j]['address_1'] = $ship->address_1;
+ $insertion_saddress_data[$j]['address_2'] = $ship->address_2;
+ $insertion_saddress_data[$j]['city'] = $ship->city;
+ $insertion_saddress_data[$j]['state'] = $ship->state;
+ $insertion_saddress_data[$j]['country'] = $ship->country;
+ $insertion_saddress_data[$j]['postal_code'] = $ship->postcode;
+ $insertion_saddress_data[$j]['email'] = isset($ship->email)?$ship->email:"";
+ $insertion_saddress_data[$j]['mobile_no'] = isset($ship->phone)?$ship->phone:"";
+ $insertion_saddress_data[$j]['customer_id'] = $lastInsertId;
+ $insertion_saddress_data[$j]['address_type'] = 2;
+ $insertion_saddress_data[$j]['created_by'] = 777;
+ $j++;
+ $message .= " Shipping address has a value and Inserted ".$j."
";
+ }
+ else{
+ $message .= " Keys are available but Shipping address has no value
";
+ }
+ }
+ (!empty($insertion_saddress_data) ? $api_model->insertAddressBatch($insertion_saddress_data) : "");
+ }
+ $response = ['status' => 200, 'message' => $message, 'data' => array()];
+ } else {
+ $response = ['status' => 204, 'message' => 'Data Already Exist', 'data' => array()];
+ }
+ } //reponse count if closed
+ }else{
+ $response = ['status' => 204, 'message' => 'Invaild Method', 'data' => array()];
+ }
+ return $this->respond($response);
+ }
+}
diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php
index 5eaeaa06..f20be53f 100755
--- a/app/Controllers/Books.php
+++ b/app/Controllers/Books.php
@@ -149,77 +149,4 @@ class Books extends BaseController
return redirect()->route('book_list');
}
- ## ApiIntegration For Book.
- public function apiintegration() {
- helper('apiIntegration');
- helper('session');
- $session_role = get_user_role();
- $session_uid = get_logged_user_id();
- $response = perform_http_request('GET', VB_BOOKS);
- $message = "";
- if(count($response['response'])>0){
- //$message = "Reponse Count : ".count($response['response'])."
";
- echo "Note : This For CrossCheck Purpose 1ly
";
- echo "Total Book API Reponse Count : " . count($response['response']) . "
";
- $BooksModel = new BooksModel();
- foreach($response['response'] as $row){
- if($row->status == "publish"){
- $publisher = '';
- $language = '';
- $attributes = $row->attributes;
- if(count($attributes)>0){
- foreach ($attributes as $att){
- if($att->name == "Publisher"){ $publisher = implode(", ",$att->options); }
- if($att->name == "Book Author"){ $publisher .= implode(", ",$att->options)."(Book Author)"; }
- if($att->name == "Book Language"){ $language = implode(", ",$att->options); }
- }
- }
- // echo $row->permalink ;
- $insertion_data['title'] = $row->name ;
- $insertion_data['publication_date'] = $row->date_created;
- $insertion_data['publisher'] = $publisher;
- $insertion_data['genre'] = $row->description;
- $insertion_data['language'] = $language;
- $insertion_data['description'] = $row->short_description;
- $insertion_data['page_count']='';
- $insertion_data['price'] = $row->sale_price != '' ? $row->sale_price : $row->regular_price;
- $insertion_data['created_by'] = $session_uid;
- $insertion_data['isactive'] = 1;
- $insertion_data['business_id'] = 1;
- $images = $row->images;
- $i = 0;
- $BooksModel->insert($insertion_data);
- $lastInsertId = $BooksModel->insertID();
- $insertion_img_data = [];
- // $message .= "book ID : ".$lastInsertId." have Imgs".count($images)."
";
- echo "book ID : ".$lastInsertId." have Imgs".count($images)."
";
- if(count($images)>0){
- foreach ($images as $img){
- $insertion_img_data[$i]['img_name'] = $img->src;
- $insertion_img_data[$i]['is_cover'] = 0;
- $insertion_img_data[$i]['type'] = 2;
- $insertion_img_data[$i]['book_id'] = $lastInsertId;
- $insertion_img_data[$i]['created_by'] = $session_uid;
- $insertion_img_data[$i]['isactive'] = 1;
- $i++;
- } // image loop closed
- $BooksModel->insertImagesBatch($insertion_img_data);
- //$message .= "book ID : ".$lastInsertId." Img. Batch Inserted Done
";
- echo " Img Batch Inserted Done. ".$i. "
";
- }//image count closed
- }//if cond. closed
- }//reponse foreach closed
- }//reponse count if closed
- if(!empty($response['error'])){
- echo $response['error'];
- echo $response['error_msg'];
- $message .= $response['error'].$response['error_msg'];
- echo $response['error'].$response['error_msg'];
- echo "Error :".$response['error'] . $response['error_msg'];
- }else{
- echo "Done";
- }
- $go_to_list_page = base_url()."book_list";
- echo "