API Integration Stage 2 : ps
This commit is contained in:
parent
210ae2ca18
commit
4a2db9b357
@ -96,4 +96,8 @@ define('EVENT_PRIORITY_HIGH', 10);
|
|||||||
/**
|
/**
|
||||||
* Constants For Api Integration.
|
* 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');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,9 @@ $routes->post("insert_scheme/", "Scheme::insert_scheme");
|
|||||||
$routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1");
|
$routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1");
|
||||||
|
|
||||||
# Api integration Routes
|
# Api integration Routes
|
||||||
$routes->get("apiintegration", "Home::apiintegration");
|
$routes->get("book_api_integration", "Book::apiintegration");
|
||||||
|
$routes->get("customer_api_integration", "Customer::apiintegration");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* --------------------------------------------------------------------
|
* --------------------------------------------------------------------
|
||||||
* Additional Routing
|
* Additional Routing
|
||||||
|
|||||||
@ -148,4 +148,78 @@ class Books extends BaseController
|
|||||||
$BooksModel->update($id, $data);
|
$BooksModel->update($id, $data);
|
||||||
return redirect()->route('book_list');
|
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'])." <br/>";
|
||||||
|
echo "Note : This For CrossCheck Purpose 1ly <br/>";
|
||||||
|
echo "Total Book API Reponse Count : " . count($response['response']) . " <br/>";
|
||||||
|
$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)." <br/>";
|
||||||
|
echo "book ID : ".$lastInsertId." have Imgs".count($images)." <br/>";
|
||||||
|
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 <br/>";
|
||||||
|
echo "       Img Batch Inserted Done. ".$i. " <br/>";
|
||||||
|
}//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 "<center><a href=".$go_to_list_page.">go to list page</a></center>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,9 @@ class Customer extends BaseController
|
|||||||
$session_bid = get_business_id();
|
$session_bid = get_business_id();
|
||||||
if (!empty($session_role) && $session_role !== "sadmin") {
|
if (!empty($session_role) && $session_role !== "sadmin") {
|
||||||
$where = ['isactive' => 1, 'business_id' => (int)$session_bid];
|
$where = ['isactive' => 1, 'business_id' => (int)$session_bid];
|
||||||
}else{ $where = ['isactive != '=>NULL];}
|
} else {
|
||||||
|
$where = ['isactive != ' => NULL];
|
||||||
|
}
|
||||||
$CustomerModel = new CustomerModel();
|
$CustomerModel = new CustomerModel();
|
||||||
|
|
||||||
$data['page_name'] = 'Customer Listing';
|
$data['page_name'] = 'Customer Listing';
|
||||||
@ -28,7 +30,6 @@ class Customer extends BaseController
|
|||||||
} else {
|
} else {
|
||||||
return redirect()->to('login');
|
return redirect()->to('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## To Load Customer Form (Add/Update)
|
## 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()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.');
|
||||||
return redirect()->route('customer_list');
|
return redirect()->route('customer_list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## 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'])." <br/>";
|
||||||
|
echo "Note : This For CrossCheck Purpose 1ly <br/>";
|
||||||
|
echo "Total Customer API Reponse Count : " . count($response['response']) . " <br/>";
|
||||||
|
$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)." <br/>";
|
||||||
|
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." <br/>";
|
||||||
|
}else{
|
||||||
|
echo "       Keys are available but Billing address has no value; <br/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(!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." <br/>";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
echo "        Keys are available but Shipping address has no value <br/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(!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 "<center><a href=".$go_to_list_page.">go to list page</a></center>";
|
||||||
|
// return $message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -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'])." <br/>";
|
|
||||||
echo "Reponse Count : ".count($response['response'])." <br/>";
|
|
||||||
$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)." <br/>";
|
|
||||||
echo "book ID : ".$lastInsertId." have Imgs".count($images)." <br/>";
|
|
||||||
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 <br/>";
|
|
||||||
echo "book ID : ".$lastInsertId." Img. Batch Inserted Done <br/>";
|
|
||||||
}//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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,5 +15,15 @@ class CustomerModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->insert($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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -4,7 +4,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<a href="<?= base_url() . "book_page/0"; ?>" class="btn btn-primary waves-effect"> <span> <i class="mdi mdi-book-plus"></i></span> Add New </a>
|
<a href="<?= base_url() . "book_page/0"; ?>" class="btn btn-primary waves-effect"> <span> <i class="mdi mdi-book-plus"></i></span> Add New </a>
|
||||||
<a href="<?= base_url()."apiintegration"; ?>" class="btn btn-success waves-effect"> <span> <i class="mdi mdi-gesture-swipe-down"></i></span> Api integration </a>
|
<a href="<?= base_url()."book_api_integration"; ?>" class="btn btn-success waves-effect"> <span> <i class="mdi mdi-gesture-swipe-down"></i></span> Api integration </a>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
|
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<a href="new_customer/0" class="btn btn-primary"><i class="ri-map-pin-user-fill"></i> Add New </a>
|
<a href="new_customer/0" class="btn btn-primary"><i class="ri-map-pin-user-fill"></i> Add New </a>
|
||||||
|
<a href="<?= base_url()."customer_api_integration"; ?>" class="btn btn-success waves-effect"> <span> <i class="mdi mdi-gesture-swipe-down"></i></span> Api integration </a>
|
||||||
</div><!-- end col-->
|
</div><!-- end col-->
|
||||||
<br>
|
<br>
|
||||||
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
|
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user