"https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); $products = array_filter($json, function ($var) use ($category) { return ($var['product_type'] == 'simple' && $var['product_image'] != '' && fnmatch("$category*", $var['product_category'])); }); $products = array_values($products); return $products; } // 02-19-2024 Jun Jihad Same Day Filter Function function sddProducts() { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products"; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/6527b593f79b5deac5ad6cb8', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); $products = array_filter($json, function ($var) { return ($var['promo'][0]['next-day-delivery'] === "Yes" && $var['product_type'] == '' || $var['promo'][0]['next-day-delivery'] === "Yes" && $var['product_type'] == 'simple' || $var['promo'][0]['next-day-delivery'] === "Yes" && $var['product_type'] == 'variable' ); }); $products = array_values($products); return $products; return $json; // Add this line to return the decoded JSON data } // 02-19-2024 Jun Jihad Same Day Filter Function // function searchProducts($query) // { // $query = str_replace(" ", "+", $query); // $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=$query"; // $curl = curl_init(); // curl_setopt($curl, CURLOPT_URL, $url); // curl_setopt_array($curl, array( // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'GET', // CURLOPT_HTTPHEADER => array( // 'X-Api-Key: {{apiKey}}' // ), // )); // $response = curl_exec($curl); // curl_close($curl); // $json = json_decode($response, true); // $products = array_filter($json, function ($var) { // return ($var['product']['product_type'] == 'simple' ); // }); // $products = array_values($products); // return $products; // } function searchProducts($query) { $query = str_replace(" ", "+", $query); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=$query"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $data = json_decode($response, true); if (isset($data['results'])) { // Filter products with product_type equal to 'simple' or 'variable' $filteredProducts = array_filter($data['results'], function ($product) { return isset($product['product']['product_type']) && in_array($product['product']['product_type'], ['simple', 'variable']); }); // Reassign the filtered results to the 'results' key $data['results'] = array_values($filteredProducts); // Check if there are no results if (empty($data['results'])) { // $data['message'] = 'No products available for the given query.'; $data['results'] = []; } } else { // Handle the case where 'results' key is not set // $data['message'] = 'No products available for the given query.'; $data['results'] = []; } return json_encode($data); } // Example usage: $query = 'asus'; $result = searchProducts($query); // function searchProducts($query) // { // $query = str_replace(" ", "+", $query); // $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=$query"; // $curl = curl_init(); // curl_setopt($curl, CURLOPT_URL, $url); // curl_setopt_array($curl, array( // //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'GET', // CURLOPT_HTTPHEADER => array( // 'X-Api-Key: {{apiKey}}' // ), // )); // $response = curl_exec($curl); // curl_close($curl); // return // $response; // } function getProduct($product) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/$product"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function productList() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } function productListVendor($vendorId) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/" . $vendorId; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/6527b593f79b5deac5ad6cb8', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); $products = array_filter($json, function ($var) { return ($var['product_type'] == '' || $var['product_type'] == 'simple' || $var['product_type'] == 'variable' || $var['product_type'] == 'variation' && $var['product_image'] != ''); }); $products = array_values($products); return $products; return $json; // Add this line to return the decoded JSON data } function getProductVariations($parent_id) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); // Filter variations based on parent_id $variations = array_filter($json, function ($product) use ($parent_id) { return $product['product_type'] === 'variation' && $product['parent_id'] === $parent_id; }); return json_encode(array_values($variations)); // Convert the filtered array back to JSON } function register($username, $password) { $curl = curl_init(); $array = array( "username" => $username, "password" => $password ); $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/register", 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_HTTPHEADER => array( 'Content-Type: application/json', 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function login($username, $password) { $curl = curl_init(); $array = array( "username" => $username, "password" => $password ); $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/login", 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_HTTPHEADER => array( 'Content-Type: application/json', 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $token = json_decode($response, true); return $token["token"]; } function forgot_password($email) { if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ $email = $_SESSION["test_email_rcpt"]; } $curl = curl_init(); $array = array( "username" => $email ); $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/forgot-password", 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_HTTPHEADER => array( 'Content-Type: application/json', 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function getCustomerbyLoginId($id) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/login_id/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } function getCustomer($id) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } function getVendorbyLoginId($id) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/login_id/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } function customerExists($email) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/search?q=$email"; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $array = json_decode($response, true); $_SESSION["customerId"] = $array["results"][0]["_id"]; $_SESSION["firstname"] = $array["results"][0]["first_name"]; $_SESSION["lastname"] = $array["results"][0]["last_name"]; $_SESSION["phone"] = $array["results"][0]["phone_number"]; $count = count($array["results"]); return $count; } function vendorExists($email) { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/search?q=$email"; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $array = json_decode($response, true); $_SESSION["vendorId"] = $array["results"][0]["_id"]; $_SESSION["firstname"] = $array["results"][0]["first_name"]; $_SESSION["company"] = $array["results"][0]["first_name"]; $_SESSION["phone"] = $array["results"][0]["phone"]; $_SESSION["vendorId"] = $array["results"][0]["_id"]; $count = count($array["results"]); return $count; } function sendEmail_obanana($fName, $lName, $email, $phone, $message) { if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ $testEmail = $_SESSION["test_email_rcpt"]; } $msgto_obanana = "

Greetings from Obanana!

"; $data = [ "Messages" => [ [ "From" => [ "Email" => "webdev@obanana.com", "Name" => "Obanana B2B" ], "To" => [ [ "Email" => $testEmail, "Name" => "Subscriber" ] ], "Subject" => "Obanana Contact Us Form", "TextPart" => "Greetings from Obanana!", "HTMLPart" => $msgto_obanana ] ] ]; $json = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mailjet.com/v3.1/send", 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_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function sendEmail_customer($fName, $lName, $email) { // if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ // $testEmail = $_SESSION["test_email_rcpt"]; // } $msgto_customer = "

Greetings from Obanana!

"; $data = [ "Messages" => [ [ "From" => [ "Email" => "webdev@obanana.com", "Name" => "Obanana B2B" ], "To" => [ [ "Email" => $email, "Name" => "Subscriber" ] ], "Subject" => "Obanana Contact Us Form", "TextPart" => "Greetings from Obanana!", "HTMLPart" => $msgto_customer ] ] ]; $json = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mailjet.com/v3.1/send", 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_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function contact_Seller($cstm_email, $prd_name, $prd_qnty, $message) { if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ $testEmail = $_SESSION["test_email_rcpt"]; } $msgto_seller = "

Greetings from Obanana!

"; $data = [ "Messages" => [ [ "From" => [ "Email" => "webdev@obanana.com", "Name" => "Obanana B2B" ], "To" => [ [ "Email" => $testEmail, "Name" => "Subscriber" ] ], "Subject" => "Obanana Contact Seller Form", "TextPart" => "Greetings from Obanana!", "HTMLPart" => $msgto_seller ] ] ]; $json = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mailjet.com/v3.1/send", 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_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function contact_Inquirer($cstm_email) { // if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ // $testEmail = $_SESSION["test_email_rcpt"]; // } $msgto_inquirer = "

Greetings from Obanana!

"; $data = [ "Messages" => [ [ "From" => [ "Email" => "webdev@obanana.com", "Name" => "Obanana B2B" ], "To" => [ [ // "Email" => $cstm_email, "Email" => "stacyjoycemapano@gmail.com", "Name" => "Subscriber" ] ], "Subject" => "Obanana Contact Seller Form", "TextPart" => "Greetings from Obanana!", "HTMLPart" => $msgto_inquirer ] ] ]; $json = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mailjet.com/v3.1/send", 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_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function sendOTP($email) { if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ $email = $_SESSION["test_email_rcpt"]; } $curl = curl_init(); $otp = generateOTP(6); $json = '{ "Messages": [ { "From": { "Email": "webdev@obanana.com", "Name": "Obanana B2B" }, "To": [ { "Email": "' . $email . '", "Name": "Subscriber" } ], "Subject": "Obanana OTP", "TextPart": "Greetings from Obanana!", "HTMLPart": "This is your OTP - ' . $otp . '. Do not share this with anyone." } ] }'; curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.mailjet.com/v3.1/send", 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_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=' ), )); $response = curl_exec($curl); curl_close($curl); $array = json_decode($response, true); return $array["Messages"][0]["Status"] . ",$otp"; //return $otp; } function generateOTP($length) { $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } function createCustomer($email, $phone, $firstname, $lastname, $loginId, $token) { $array = array( 'user_email' => $email, 'phone_number' => $phone, 'first_name' => $firstname, 'last_name' => $lastname, 'login_id' => $loginId ); $header = array( 'Accept: application/json', 'Authorization: Bearer ' . $token ); $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/customers", 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', )); $response = curl_exec($curl); curl_close($curl); $array = json_decode($response, true); return $array; } function updateCustomer($customerId, $phone, $firstname, $lastname, $loginId, $token) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/$customerId"; $array = '{ "last_name": "' . $lastname . '", "login_id": "' . $loginId . '", "phone_number": "' . $phone . '", "first_name": "' . $firstname . '" }'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function profile($token) { $header = array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token ); $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/profile", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', )); $response = curl_exec($curl); curl_close($curl); $array = json_decode($response, true); return $array; } // function createVendor($email, $phone, $company, $loginId, $token) // { // $curl = curl_init(); // $array = array( // 'user_email' => $email, // 'first_name' => $company, // 'phone' => $phone, // 'login_id' => $loginId // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( // CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // 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_HTTPHEADER => array( // 'Accept: application/json', // 'X-Api-Key: {{apiKey}}' // ), // )); // $response = curl_exec($curl); // curl_close($curl); // echo $response; // } // function updateVendor($vendorId, $phone, $company, $loginId, $token) // { // $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/$vendorId"; // $array = '{ // "login_id": "' . $loginId . '", // "first_name": "' . $company . '", // "phone": "' . $phone . '" // }'; // $curl = curl_init(); // curl_setopt($curl, CURLOPT_URL, $url); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'PATCH', // CURLOPT_HTTPHEADER => array( // 'Accept: application/json', // 'Content-Type: application/json', // 'Authorization: Bearer ' . $token // ), // )); // $response = curl_exec($curl); // curl_close($curl); // return $response; // } function updateVendor($vendorId, $phone, $userlogin, $firstname, $lastname, $loginId, $token) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/$vendorId"; $array = '{ "login_id": "' . $loginId . '", "user_login": "' . $userlogin . '", "first_name": "' . $firstname . '", "last_name": "' . $lastname . '", "phone": "' . $phone . '" }'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function createVendor($email, $phone, $userlogin, $firstname, $lastname, $loginId, $token) { $curl = curl_init(); $array = array( 'user_login' => $userlogin, 'user_email' => $email, 'first_name' => $firstname, 'last_name' => $lastname, 'phone' => $phone, 'login_id' => $loginId ); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", 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_HTTPHEADER => array( 'Accept: application/json', 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; } // function addVendor( // $companyname, // $email, // $phone, // $firstName, // $lastName, // $vendorDescription, // $building, // $street, // $barangay, // $city, // $province, // $country, // $address, // $fileImagePath, // $attributes, // $tags // ) { // $curl = curl_init(); // // $vendor_address = [ // // 'barangay' => $barangay, // // 'city' => $city // // ]; // //$vendor_address = "{ 'barangay':'barangay', 'city':'city' }"; // // $address = json_encode($vendor_address); // $array = // [ // 'user_login' => $companyname, // 'user_email' => $email, // 'phone' => $phone, // 'first_name' => $firstName, // 'last_name' => $lastName, // 'vendor_description' => $vendorDescription, // 'address_1' => $building, // 'address_2' => $street, // // 'address' => "{ 'barangay':'barangay', 'city':'city' }", // // 'barangay' => $barangay, // // 'city' => $city // // ), // 'file_path_image' => $fileImagePath, // ]; // // file_put_contents('request_data.txt', json_encode($array)); // // error_log("API Request Data: " . json_encode($array)); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( // CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // 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_HTTPHEADER => array( // 'Accept: application/json', // 'Content-Type: application/json', // 'X-Api-Key: {{apiKey}}' // ), // )); // $response = curl_exec($curl); // curl_close($curl); // echo $response; // // file_put_contents('request_data.txt', json_encode($response)); // } function vendorList() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } function simpleVendors() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); $vendors = array_filter($json, function ($var) { return ($var['vendor_image'] != ''); }); $vendors = array_values($vendors); return $vendors; } function productListVendors($vendorIds) { // Convert the array of vendor IDs to a comma-separated string $vendorIdsString = implode(',', $vendorIds); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products?vendor_ids=" . $vendorIdsString, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; } function simpleVendorsWithProducts() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); // Extract vendor IDs from the response $vendorIds = array_map(function ($vendor) { return $vendor['_id']; }, $json); // Fetch products for multiple vendors in a single API call $products = productListVendors($vendorIds); // Combine vendor and product data as needed $vendorsWithProducts = array_map(function ($vendor) use ($products) { // Extract products associated with the current vendor from the $products array $vendorProducts = array_filter($products, function ($product) use ($vendor) { // Filter out products with empty product_image and product_category not equal to "simple" or "variable" return $product['vendor_api_id'] === $vendor['_id'] && !empty($product['product_image']) && in_array($product['product_type'], ['simple', 'variable']); }); // Add products to the vendor array or format as needed $vendor['products'] = array_values($vendorProducts); // Adjust as needed return $vendor; }, $json); // Filter vendors to include only those with more than 4 products $vendorsWithMoreThanFourProducts = array_filter($vendorsWithProducts, function ($vendor) { return count($vendor['products']) > 4; }); return array_values($vendorsWithMoreThanFourProducts); } /* if (isset($_POST['action'])) { $action = $_POST['action']; if ($action === 'addToCart') { $data = $_POST['addToCartData']; $result = addToCart($data); echo json_encode($result); exit; // Stop further execution } } */ function getVendorbyId($id) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/$id"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function searchVendorByLoginId($id) { $id = str_replace(" ", "+", $id); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/search?q=$id"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function getOrder($order) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/orders/$order"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function getAllOrder() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/orders", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); // Filter out orders with status 'cart', 'Cart', or 'CART' $filteredOrders = array_filter($json, function ($order) { $status = isset($order['status']) ? strtoupper($order['status']) : ''; return !in_array($status, ['CART']); }); return $filteredOrders; } function getOrderbyCustomerId($id) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/orders/customer/$id"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function getOrderbyVendorId($id) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/orders/vendor/$id"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $courierName, $token) { $curl = curl_init(); $data = array( 'status' => $status ); if ($currentStatus == "TO SHIP" || $currentStatus == "T Ship") { // $data['tracking_number'] = $trackingNumber; $data['tracking_number'] = $trackingNumber; $data['courier_name'] = $courierName; } $params3 = json_encode($data); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/orders/" . $orderId, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $params3, CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); return $response; } // function addToCart($product_id, $product_name, $user_data){ // $array = array( // 'product' => array( // 'product_id' => $product_id, // 'name' => $product_name, // ), // ); // $curl = curl_init(); // curl_setopt($curl,CURLOPT_POSTFIELDS,$array); // curl_setopt_array($curl, array( // CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/orders', // 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', // )); // $response = curl_exec($curl); // curl_close($curl); // $array = json_decode($response,true); // return $array; // } function deleteOrderbyId($id) { $url = "https://".$_SESSION["data_endpoint"]."/api/v1/orders/$id"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function addProduct( $vendorId, $productName, $stock, $price, $salePrice, $weight, $length, $width, $height, $specifications, $productType, $parentId, $token ) { $curl = curl_init(); $array = array( 'vendor_api_id' => $vendorId, 'product_name' => $productName, 'stock' => $stock, 'regular_price' => $price, 'sale_price' => $salePrice, 'weight' => $weight, 'length' => $length, 'width' => $width, 'height' => $height, 'specifications' => $specifications, 'product_type' => $productType, 'parent_id' => $parentId, ); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", 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_HTTPHEADER => array( 'Accept: application/json', 'X-Api-Key: {{apiKey}}', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function editProduct( $productId, $vendorId, $productName, $stock, $ndd, $sdd, $freeSf, $price, $salePrice, $weight, $length, $width, $height, $description, $specifications, $productType, $productCategory, $productSf, $productStatus, $parentId, $minimumOrder, $color, $material, $size, $token ) { $curl = curl_init(); $data = array( 'vendor_api_id' => $vendorId, 'product_name' => $productName, 'product_description' => $description, 'stock' => $stock, 'regular_price' => $price, 'sale_price' => $salePrice, 'weight' => $weight, 'length' => $length, 'width' => $width, 'height' => $height, 'specifications' => $specifications, 'product_type' => $productType, 'product_category' => $productCategory, 'shipping_fee' => $productSf, 'status' => $productStatus, 'promo' => array( 'next-day-delivery' => $ndd , 'same-day-delivery' => $sdd , 'free-shipping' => $freeSf ), 'parent_id' => $parentId, 'minimum_order' => $minimumOrder, // 'variants' => array( // 'color' => $color, // 'material' => $material, // 'size' => $size // ) ); if ($productType == "variation") { $data['variants'] = array( 'color' => $color, 'material' => $material, 'size' => $size ); } // $params3 = json_encode($data); // $url = 'https://".$_SESSION["data_endpoint"]."/api/v1/products/'.$productId; // curl_setopt($curl,CURLOPT_URL,$url); // curl_setopt($curl, CURLOPT_POSTFIELDS, $params3); // curl_setopt_array($curl, array( // //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/656712969624f6181c49cdd0', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'PATCH', // CURLOPT_HTTPHEADER => array( // 'Accept: application/json', // 'X-Api-Key: {{apiKey}}' // ), // )); $params3 = json_encode($data); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products/" . $productId, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $params3, CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'X-Api-Key: {{apiKey}}', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); return $response; } // Function addVendor( // $companyname, // $firstName, // $lastName, // $vendorDescription, // // $building, // ) { // $curl = curl_init(); // $array = array( // 'user_login' => $companyname, // 'first_name' => $firstName, // 'last_name' => $lastName, // 'vendor_description' => $vendorDescription, // 'address' => array( // array('barangay' => 'barangay', 'city' => 'city') // ), // // 'regular_price' => $price, // // 'vendor_api_id' => $vendorId, // // 'product_type' => $productType, // // 'parent_id' => $parentId, // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( // CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // 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_HTTPHEADER => array( // 'Accept: application/json', // 'X-Api-Key: {{apiKey}}', // ), // )); // $response = curl_exec($curl); // curl_close($curl); // echo $response; // } function addVendor( $companyname, $firstName, $lastName, $vendorDescription, $vendorStatus, $building, $street, $barangay, $city, $province, $country, $email, $phone, $dateRegistered ) { $curl = curl_init(); $data = array( 'user_login' => $companyname, 'first_name' => $firstName, 'last_name' => $lastName, 'vendor_description' => $vendorDescription, 'status' => $vendorStatus, 'address' => array( 'address_1' => $building, 'address_2' => $street, 'barangay' => $barangay, 'city' => $city, 'province' => $province, 'country' => $country, ), 'user_email' => $email, 'phone' => $phone, 'date_registered' => $dateRegistered, ); $params2 = json_encode($data); curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", 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 => $params2, CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; } function getUsers() { $curl = curl_init(); $url = "https://".$_SESSION["data_endpoint"]."/api/v1/users"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}' ), )); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); return $json; // Add this line to return the decoded JSON data } // function editUsers( // $id, // $username, // $userType, // $token // ) { // $curl = curl_init(); // $array = array( // 'username' => $username, // 'user_type' => $userType, // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( // CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/users/' . $id, // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'PATCH', // CURLOPT_HTTPHEADER => array( // 'X-Api-Key: {{apiKey}}', // 'Content-Type: application/json', // 'Authorization: Bearer ' . $token // ), // )); // $response = curl_exec($curl); // curl_close($curl); // $json = json_decode($response, true); // return $json; // Add this line to return the decoded JSON data // } function editUsers($id, $username, $userType, $token) { $curl = curl_init(); $data = array( // 'username' => $username, 'user_type' => $userType, ); $jsonPayload = json_encode($data); // Convert the array to JSON format curl_setopt_array($curl, array( CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/users/" . $id, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $jsonPayload, // Set the JSON payload CURLOPT_HTTPHEADER => array( 'X-Api-Key: {{apiKey}}', 'Content-Type: application/json', 'Authorization: Bearer ' . $token ), )); $response = curl_exec($curl); curl_close($curl); echo $response; return $response; }