diff --git a/app/Config/Constants.php b/app/Config/Constants.php index b9cb843e..4f636275 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -96,4 +96,8 @@ define('EVENT_PRIORITY_HIGH', 10); /** * Constants For Api Integration. */ -define('VPB_BOOK', 'https://vbp.venbait.in/wp-json/wc/v3/products'); +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 29aed9aa..f193f0a3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -79,7 +79,9 @@ $routes->post("insert_scheme/", "Scheme::insert_scheme"); $routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1"); # Api integration Routes -$routes->get("apiintegration", "Home::apiintegration"); +$routes->get("book_api_integration", "Book::apiintegration"); +$routes->get("customer_api_integration", "Customer::apiintegration"); + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 00b1fd99..5eaeaa06 100755 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -148,4 +148,78 @@ class Books extends BaseController $BooksModel->update($id, $data); 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 "
go to list page
"; + } } diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index f2ab8d4c..8728cb8d 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -11,12 +11,14 @@ class Customer extends BaseController public function index() { helper('session'); - if (is_session_active()) { + if (is_session_active()) { $session_role = get_user_role(); $session_bid = get_business_id(); if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['isactive'=>1,'business_id'=>(int)$session_bid]; - }else{ $where = ['isactive != '=>NULL];} + $where = ['isactive' => 1, 'business_id' => (int)$session_bid]; + } else { + $where = ['isactive != ' => NULL]; + } $CustomerModel = new CustomerModel(); $data['page_name'] = 'Customer Listing'; @@ -25,10 +27,9 @@ class Customer extends BaseController // print_r($data); die(); $this->render_page('customer_list', $data); - }else{ + } else { return redirect()->to('login'); } - } ## To Load Customer Form (Add/Update) @@ -119,4 +120,104 @@ class Customer extends BaseController // return redirect()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.'); return redirect()->route('customer_list'); } -} \ No newline at end of file + + ## ApiIntegration For Customer. + public function apiintegration() + { + helper('apiIntegration'); + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $response = perform_http_request('GET', VB_CUSTOMERS); + $message = ""; + if (count($response['response']) > 0) { + //$message = "Reponse Count : ".count($response['response'])."
"; + echo "Note : This For CrossCheck Purpose 1ly
"; + echo "Total Customer API Reponse Count : " . count($response['response']) . "
"; + $CustomerModel = new CustomerModel(); + $x=0; + foreach ($response['response'] as $row) { + $insertion_data['first_name'] = $row->first_name; + $insertion_data['last_name'] = $row->last_name; + $insertion_data['type'] = $row->role; + $insertion_data['email'] = $row->email; + // $insertion_data['profile_picture'] = $row->avatar_url; + $insertion_data['mode'] = 'online'; + $insertion_data['created_by'] = $session_uid; + $insertion_data['business_id'] = $session_bid; + $billing = $row->billing; + $shipping = $row->shipping; + $CustomerModel->insert($insertion_data); + $lastInsertId = $CustomerModel->insertID(); + $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];} + echo "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'] = $session_uid; + $insertion_baddress_data[$i]['email'] = isset($bill->email) ? $bill->email : ''; + $insertion_baddress_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : ''; + $i++; + echo "       Billing address has a value and Inserted ".$i."
"; + }else{ + echo "       Keys are available but Billing address has no value;
"; + } + } + (!empty($insertion_baddress_data) ? $CustomerModel->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'] = $session_uid; + $j++; + echo "        Shipping address has a value and Inserted ".$j."
"; + } + else{ + echo "        Keys are available but Shipping address has no value
"; + } + } + (!empty($insertion_saddress_data) ? $CustomerModel->insertAddressBatch($insertion_saddress_data) : ""); + } + } //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 "Error :".$response['error'] . $response['error_msg']; + }else{ + echo "Done"; + } + $go_to_list_page = base_url()."customer_list"; + echo "
go to list page
"; + // return $message; + } +} diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 69c4838b..218308e7 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -14,73 +14,4 @@ class Home extends BaseController } - ## ApiIntegration. - public function apiintegration() { - helper('apiIntegration'); - helper('session'); - $session_role = get_user_role(); - $session_uid = get_logged_user_id(); - $response = perform_http_request('GET', VPB_BOOK); - $message = ""; - if(count($response['response'])>0){ - //$message = "Reponse Count : ".count($response['response'])."
"; - echo "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 "book ID : ".$lastInsertId." Img. Batch Inserted Done
"; - }//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']; - } - //return $message; - echo "Done"; - } } diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 15e23421..71b07cc2 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -14,6 +14,16 @@ class CustomerModel extends Model public function insertCustomer($data) { return $this->insert($data); - } + } + + public function insertAddress($addressData) { + $this->db->table('customer_addresses')->insert($addressData); + return $this->db->insertID(); // Return the last inserted ID + } + + public function insertAddressBatch($addressesDataArray) { + $this->db->table('customer_addresses')->insertBatch($addressesDataArray); + return $this->db->insertID(); // Note: insertID() might not be applicable for batch inserts + } } ?> \ No newline at end of file diff --git a/app/Views/book_list.php b/app/Views/book_list.php index 30fc023a..8b9276db 100644 --- a/app/Views/book_list.php +++ b/app/Views/book_list.php @@ -4,7 +4,7 @@
" class="btn btn-primary waves-effect"> Add New - " class="btn btn-success waves-effect"> Api integration + " class="btn btn-success waves-effect"> Api integration

diff --git a/app/Views/customer_list.php b/app/Views/customer_list.php index f3c14b6a..70a37e4b 100644 --- a/app/Views/customer_list.php +++ b/app/Views/customer_list.php @@ -4,6 +4,7 @@