diff --git a/application/controllers/Site.php b/application/controllers/Site.php index 6f5adfe..91f09ee 100644 --- a/application/controllers/Site.php +++ b/application/controllers/Site.php @@ -7559,6 +7559,34 @@ public function paystack_payment(){ curl_close($curl); return json_decode($response); } + + + public function complete_update_team($data){ + + $affiliate_url = $this->db->get_where('tbl_settings', array('id' => '1'))->row()->affiliate_url; + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => $affiliate_url.'/Api/complete_order_update_team', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => $data, + CURLOPT_HTTPHEADER => array( + 'Cookie: ci_session=7qd31025hq2n7e3pbmrcecad5fklt5mp' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return json_decode($response); + } @@ -9239,4 +9267,150 @@ public function paystack_payment(){ $this->template->load('site/template2', 'site/pages/terms'); // :blush: } + /* public function run_api(){ + + $sql = $this->db->select('*')->from('tbl_order_details')->where('id' >= '13024')->get()->result(); + + + debug_log($sql) + + foreach($sql as $row){ + $api_data=array('orderid' => $row->id,'order_unique_id' => $row->order_unique_id,'status_desc' => 1,'userid' => $row->user_id, 'waybill_number' => ''); + $response=$this->complete_order_gmlm($api_data)->message; + + echo $response; + echo $row->user_id; + } + + + + + }*/ + + + public function run_api() { + $sql = $this->db->select('*') + ->from('tbl_order_details') + ->where('placed_status', 1) + ->where('check_comm', 0) + ->where('id >=', 13024) + ->get() + ->result(); + + debug_log($sql); + + foreach ($sql as $row) { + $api_data = array( + 'orderid' => $row->id, + 'order_unique_id'=> $row->order_unique_id, + 'status_desc' => 1, + 'userid' => $row->user_id, + 'waybill_number' => '' + ); + + $api_response = $this->complete_order_gmlm($api_data); + + // Handle depending on return type + if (is_object($api_response) && isset($api_response->message)) { + $response = $api_response->message; + } elseif (is_array($api_response) && isset($api_response['message'])) { + $response = $api_response['message']; + } else { + $response = $api_response; // fallback (string or raw response) + } + + echo "Response: {$response}, User: {$row->user_id}
"; + } + } + + + public function update_team_sales() { + $sql = $this->db->select('*') + ->from('tbl_order_details') + ->where('placed_status', 1) + ->where('check_comm', 1) + ->where('id >=', 13024) + ->get() + ->result(); + + debug_log($sql); + + foreach ($sql as $row) { + $api_data = array( + 'orderid' => $row->id, + 'order_unique_id'=> $row->order_unique_id, + 'status_desc' => 1, + 'userid' => $row->user_id, + 'waybill_number' => '' + ); + + $api_response = $this->complete_update_team($api_data); + + // Handle depending on return type + if (is_object($api_response) && isset($api_response->message)) { + $response = $api_response->message; + } elseif (is_array($api_response) && isset($api_response['message'])) { + $response = $api_response['message']; + } else { + $response = $api_response; // fallback (string or raw response) + } + + echo "Response: {$response}, User: {$row->user_id}
"; + } + } + + public function send_orders_to_affiliate() { + // Example timestamp filter (replace with your real condition) + $timestamp = '1756665060'; + + // Fetch orders greater than given order_date + $this->db->where('id >=', 13024); + $this->db->where('order_status >=', 1); + $this->db->where('placed_status', 1); + $orders = $this->db->get('tbl_order_details')->result_array(); + + if(empty($orders)) { + echo "No new orders found."; + return; + } + + // echo count($orders); + + // echo "
"; + + print_r($orders); + + // Affiliate API URL + $affiliate_url = "https://www.affiliate.flatstomachtea.co.za/api/receive_orders"; + + $ch = curl_init(); + + // Set cURL options + curl_setopt($ch, CURLOPT_URL, $affiliate_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($orders)); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + "Accept: application/json", + "Content-Type: application/json", + + ]); + + // Execute cURL request + $response = curl_exec($ch); + + // Check for cURL errors + if (curl_errno($ch)) { + echo 'Error:' . curl_error($ch); + } else { + // Output response + echo 'Response from Brevo: ' . $response; + } + // Close cURL session + curl_close($ch); + + echo "Response from affiliate: " . $response; + } + + } diff --git a/application/helpers/custom_helper.php b/application/helpers/custom_helper.php index 233445d..e2b991b 100644 --- a/application/helpers/custom_helper.php +++ b/application/helpers/custom_helper.php @@ -752,3 +752,32 @@ if ( ! function_exists('h_dateFormat')){ return $new_date; } } + +if (!function_exists('debug_log')) { + function debug_log($data) { + if (config_item('debug_mode')) { + + // Skip logging DB config arrays + if (strpos(print_r($data, true), '[dbdriver] => mysqli') === false) { + $fp = fopen('.debug.log', 'a'); + fwrite($fp, date('Y-m-d H:i:s') . ": " . print_r($data, true) . "\n"); + fclose($fp); + } + + // Check if .debug.log exceeds 50 KB (50 * 1024 bytes) + if (file_exists('.debug.log') && filesize('.debug.log') > 50 * 1024) { + // Append to .debug_repo.log + file_put_contents('.debug_repo.log', file_get_contents('.debug.log'), FILE_APPEND | LOCK_EX); + + // Truncate .debug.log + $fh = fopen('.debug.log', 'w'); + fclose($fh); + + // Check if .debug_repo.log exceeds 50 MB (50 * 1024 * 1024 bytes) + if (file_exists('.debug_repo.log') && filesize('.debug_repo.log') > 50 * 1024 * 1024) { + file_put_contents('.debug_repo.log', ''); + } + } + } + } +} diff --git a/application/models/Shipping_model.php b/application/models/Shipping_model.php index 623fd3f..458131d 100644 --- a/application/models/Shipping_model.php +++ b/application/models/Shipping_model.php @@ -446,18 +446,20 @@ class Shipping_model extends CI_Model{ $total_cart_amt+= round($set_data->selling_price*$set_data->product_qty); } $shipping_amm = 0; - if($total_cart_amt >= 1000) { + /*if($total_cart_amt >= 1000) { $shipping_amm = 0; } else { - if($w<=5){ - $shipping_amm = 85; - } - elseif($w<=10){ - $shipping_amm = 125; - } - elseif($w>10){ - $shipping_amm = 160; - } + + }*/ + + if($w<=5){ + $shipping_amm = 85; + } + elseif($w<=10){ + $shipping_amm = 125; + } + elseif($w>10){ + $shipping_amm = 160; } return $shipping_amm;