api Shipping Address Detils : ps
This commit is contained in:
parent
bc6041b89d
commit
77d56c076d
@ -26,10 +26,10 @@ class ApiIntegration extends ResourceController
|
|||||||
$existing_data = $api_model->getData($table, $where);
|
$existing_data = $api_model->getData($table, $where);
|
||||||
$this->global_variable_user_id = isset($existing_data[0]->user_id) ? (int)$existing_data[0]->user_id : NULL;
|
$this->global_variable_user_id = isset($existing_data[0]->user_id) ? (int)$existing_data[0]->user_id : NULL;
|
||||||
$this->global_variable_user_name = isset($existing_data[0]->user_id) ? $existing_data[0]->first_name." ".$existing_data[0]->last_name : NULL;
|
$this->global_variable_user_name = isset($existing_data[0]->user_id) ? $existing_data[0]->first_name." ".$existing_data[0]->last_name : NULL;
|
||||||
$this->logger->info("Api Integration : User = ".$this->global_variable_user_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function api_integration($api_request_text) {
|
public function api_integration($api_request_text) {
|
||||||
|
$this->logger->info("Api Integration : UID = ".$this->global_variable_user_id." * ".$this->global_variable_user_name);
|
||||||
$this->logger->info("Api Integration : Request Text = ".$api_request_text);
|
$this->logger->info("Api Integration : Request Text = ".$api_request_text);
|
||||||
try {
|
try {
|
||||||
$request_data = $this->request->getVar();
|
$request_data = $this->request->getVar();
|
||||||
@ -742,20 +742,30 @@ class ApiIntegration extends ResourceController
|
|||||||
|
|
||||||
if(isset($records['billing']) && gettype($records['billing']) === 'object') {$billing_array = [$records['billing']];}
|
if(isset($records['billing']) && gettype($records['billing']) === 'object') {$billing_array = [$records['billing']];}
|
||||||
if(isset($records['shipping']) && gettype($records['shipping']) === 'object') {$shipping_array = [$records['shipping']];}
|
if(isset($records['shipping']) && gettype($records['shipping']) === 'object') {$shipping_array = [$records['shipping']];}
|
||||||
|
$where = ['wp_api_customer_id' => (int)$records['customer_id'], 'isactive' => 1];
|
||||||
|
$local_customer = $api_model->getData('customers', $where);
|
||||||
|
$local_customer_id = !empty($local_customer) ? $local_customer[0]->customer_id : NULL;
|
||||||
|
$this->logger->info((!empty($local_customer)) ? "Api SaveSalesDetails : in wordpress customer ref ID = ".$records['customer_id']." is available on Customer table and its PrimaryKey = ".$local_customer_id."(local customer id)" : "Api SaveSalesDetails : in wordpress customer ref ID = ".$records['customer_id']." Not available on Customer table");
|
||||||
|
|
||||||
if (count($billing_array) > 0) {
|
if (count($billing_array) > 0) {
|
||||||
foreach ($billing_array as $bill) {
|
// foreach ($billing_array as $bill) {
|
||||||
if($bill->first_name != ""){
|
// if($bill->first_name != ""){
|
||||||
$billing_addr = $bill->address_1 . " " . $bill->address_2 . ",\n" . $bill->city . ",\n" . $bill->state . " - " . $bill->postal_code . ",\n" . $bill->country . ".";
|
// $billing_addr = $bill->address_1 . " " . $bill->address_2 . ",\n" . $bill->city . ",\n" . $bill->state . " - " . $bill->postal_code . ",\n" . $bill->country . ".";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
$result_billing_addr = $this->save_invoice_address_in_customer_address($billing_array,1,(int)$local_customer_id);
|
||||||
|
$billing_addr_id = $result_billing_addr['addr_id'];
|
||||||
|
$billing_addr = $result_billing_addr['addr'];
|
||||||
}
|
}
|
||||||
if (count($shipping_array) > 0) {
|
if (count($shipping_array) > 0) {
|
||||||
foreach ($shipping_array as $ship) {
|
// foreach ($shipping_array as $ship) {
|
||||||
if($ship->first_name != ""){
|
// if($ship->first_name != ""){
|
||||||
$shipping_addr = $ship->address_1 . " " . $ship->address_2 . ",\n" . $ship->city . ",\n" . $ship->state . " - " . $ship->postal_code . ",\n" . $ship->country . ".";
|
// $shipping_addr = $ship->address_1 . " " . $ship->address_2 . ",\n" . $ship->city . ",\n" . $ship->state . " - " . $ship->postal_code . ",\n" . $ship->country . ".";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
$result_shipping_addr = $this->save_invoice_address_in_customer_address($shipping_array,2,(int)$local_customer_id);
|
||||||
|
$shipping_addr_id = $result_shipping_addr['addr_id'];
|
||||||
|
$shipping_addr = $result_shipping_addr['addr'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($records['line_items']) > 0) {
|
if (count($records['line_items']) > 0) {
|
||||||
@ -771,9 +781,7 @@ class ApiIntegration extends ResourceController
|
|||||||
$subtotal = $lineitems_subtotal + (float)$records['shipping_total'];
|
$subtotal = $lineitems_subtotal + (float)$records['shipping_total'];
|
||||||
$tax = $lineitems_tax + (float)$records['shipping_tax'];
|
$tax = $lineitems_tax + (float)$records['shipping_tax'];
|
||||||
$total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax'];
|
$total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax'];
|
||||||
$where = ['wp_api_customer_id' => (int)$records['customer_id'], 'isactive' => 1];
|
|
||||||
$local_customer = $api_model->getData('customers', $where);
|
|
||||||
$local_customer_id = !empty($local_customer) ? $local_customer[0]->customer_id : "";
|
|
||||||
|
|
||||||
$invoice_data['invoice_id']=$invoice_id;
|
$invoice_data['invoice_id']=$invoice_id;
|
||||||
$invoice_data['invoice_number']=$records['number'];
|
$invoice_data['invoice_number']=$records['number'];
|
||||||
@ -791,13 +799,12 @@ class ApiIntegration extends ResourceController
|
|||||||
$invoice_data['event_id']=NULL;
|
$invoice_data['event_id']=NULL;
|
||||||
$invoice_data['business_id']=$this->global_variable_business_id;
|
$invoice_data['business_id']=$this->global_variable_business_id;
|
||||||
$invoice_data['shipping_address']=$shipping_addr;
|
$invoice_data['shipping_address']=$shipping_addr;
|
||||||
$invoice_data['shipping_address_id']=NULL;
|
$invoice_data['shipping_address_id']=$shipping_addr_id;
|
||||||
$invoice_data['billing_address']=$billing_addr;
|
$invoice_data['billing_address']=$billing_addr;
|
||||||
$invoice_data['billing_address_id'] =NULL;
|
$invoice_data['billing_address_id'] =$billing_addr_id;
|
||||||
$invoice_data['shipping_charge'] = isset($records['shipping_total'])?$records['shipping_total']:NULL;
|
$invoice_data['shipping_charge'] = isset($records['shipping_total'])?$records['shipping_total']:NULL;
|
||||||
$invoice_data['notes'] = isset($records['customer_note'])?$records['customer_note']:NULL;
|
$invoice_data['notes'] = isset($records['customer_note'])?$records['customer_note']:NULL;
|
||||||
$invoice_data['invoice_type'] = 1;
|
$invoice_data['invoice_type'] = 1;
|
||||||
|
|
||||||
if ((int)$countAll == 0) {
|
if ((int)$countAll == 0) {
|
||||||
$invoice_data['created_by'] = $this->global_variable_user_id;
|
$invoice_data['created_by'] = $this->global_variable_user_id;
|
||||||
$insert_result = $api_model->insertData('invoice', $invoice_data);
|
$insert_result = $api_model->insertData('invoice', $invoice_data);
|
||||||
@ -1131,4 +1138,61 @@ class ApiIntegration extends ResourceController
|
|||||||
$this->logger->error("Api SaveCategoriesMasterDetails : Err = Categories Data Not Found");
|
$this->logger->error("Api SaveCategoriesMasterDetails : Err = Categories Data Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save_invoice_address_in_customer_address($request_addr_array,$flag,$customer_id){
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress = ".json_encode($request_addr_array));
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress Flag = ".$flag." Customer Id = ".$customer_id);
|
||||||
|
$api_model = new ApiIntegrationModel();
|
||||||
|
$where = ['customer_id' =>$customer_id,'address_type'=>$flag,
|
||||||
|
'first_name'=>$request_addr_array[0]->first_name,'last_name'=>$request_addr_array[0]->last_name,
|
||||||
|
'address_1'=>$request_addr_array[0]->address_1,'address_2'=>$request_addr_array[0]->address_2,
|
||||||
|
'city'=>$request_addr_array[0]->city,'state'=>$request_addr_array[0]->state,
|
||||||
|
'postal_code'=>$request_addr_array[0]->postcode];
|
||||||
|
$existing_addr = $api_model->getData('customer_addresses', $where);
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress Count = ".count($existing_addr));
|
||||||
|
$final_array['addr_id'] = NULL;
|
||||||
|
$final_array['addr'] = NULL;
|
||||||
|
|
||||||
|
$addr_data = [];
|
||||||
|
|
||||||
|
if (!empty($existing_addr)) {
|
||||||
|
$final_array['addr_id'] = isset($existing_addr) && !empty($existing_addr) ? $existing_addr[0]->customer_address_id : NULL;
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress Ex Addr id = ".$final_array['addr_id']);
|
||||||
|
if($existing_addr[0]->first_name != ""){
|
||||||
|
$final_array['addr'] = $existing_addr[0]->address_1 . " " . $existing_addr[0]->address_2 . ",\n" . $existing_addr[0]->city . ",\n" . $existing_addr[0]->state . " - " . $existing_addr[0]->postal_code . ",\n" . $existing_addr[0]->country . ".";
|
||||||
|
}
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress Ex Addr = ".$final_array['addr']);
|
||||||
|
}
|
||||||
|
if (empty($existing_addr)) {
|
||||||
|
foreach ($request_addr_array as $addr) {
|
||||||
|
if($addr->first_name != ""){
|
||||||
|
$addr_data['first_name'] = $addr->first_name;
|
||||||
|
$addr_data['last_name'] = $addr->last_name;
|
||||||
|
$addr_data['company'] = $addr->company;
|
||||||
|
$addr_data['address_1'] = $addr->address_1;
|
||||||
|
$addr_data['address_2'] = $addr->address_2;
|
||||||
|
$addr_data['city'] = $addr->city;
|
||||||
|
$addr_data['state'] = $addr->state;
|
||||||
|
$addr_data['country'] = $addr->country;
|
||||||
|
$addr_data['postal_code'] = $addr->postcode;
|
||||||
|
$addr_data['email'] = isset($addr->email)? $addr->email:"";
|
||||||
|
$addr_data['mobile_no'] = isset($addr->phone)?$addr->phone:"";
|
||||||
|
$addr_data['customer_id'] = $customer_id;
|
||||||
|
$addr_data['address_type'] = $flag;
|
||||||
|
$addr_data['customer_address_id'] = NULL;
|
||||||
|
$addr_data['created_by'] = $this->global_variable_user_id;
|
||||||
|
$final_array['addr'] = $addr->address_1 . " " . $addr->address_2 . ",\n" . $addr->city . ",\n" . $addr->state . " - " . $addr->postcode . ",\n" . $addr->country . ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress New Addr = ".$final_array['addr']);
|
||||||
|
if(!empty($addr_data)){
|
||||||
|
|
||||||
|
$insert_result = $api_model->insertData('customer_addresses',$addr_data);
|
||||||
|
$final_array['addr_id'] = $insert_result['info'];
|
||||||
|
$this->logger->info("Api saveInvoiceAddressInCustomerAddress New Addr id = ".$final_array['addr_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return $final_array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user