From 8bd8211b3d05ce8478ae31ca54d1fbf91dd31bea Mon Sep 17 00:00:00 2001 From: Jun Barroga Date: Thu, 15 Feb 2024 17:32:28 +0800 Subject: [PATCH 1/3] Vendor Product Add and Edit page Multiple Image --- vendor-uploads.php | 406 +++++++++++++++++++++++++-------------------- 1 file changed, 228 insertions(+), 178 deletions(-) diff --git a/vendor-uploads.php b/vendor-uploads.php index 709251a..026a2e4 100644 --- a/vendor-uploads.php +++ b/vendor-uploads.php @@ -111,6 +111,7 @@ $array = json_decode($result, true);
+
+ +
+
@@ -131,93 +135,109 @@ $array = json_decode($result, true);
- +
- edit - " alt="edit" /> + + ?> edit
+ +
-
-
- - -
-
-
- edit + $image_url) { + $image_url = trim($image_url); + ?> +
+
+ + +
+
+
+ edit + +
+
+
+ +
+
+ + +
+
+
+ edit +
-
-
-
- - -
-
-
- edit -
-
-
-
-
- - -
-
-
- edit -
-
-
-
-
- - -
-
-
- edit -
-
-
-
-
- - -
-
-
- edit -
-
-
-
-
- - -
-
-
- edit -
-
-
+ + + + +
+
@@ -248,7 +268,6 @@ $array = json_decode($result, true);
- - - - - - - - - - -
-
- - -
-
- - -
+ + +
+
+ + +
+
+ + +
@@ -409,104 +428,135 @@ $array = json_decode($result, true); function uploadProductImage() { var productId = ''; var fileInput = document.getElementById('imageUpload'); - var file = fileInput.files[0]; + var files = fileInput.files; - if (file) { - const reader = new FileReader(); - reader.onload = function(e) { - const img = new Image(); - img.onload = function() { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); + if (files.length > 0) { + var promises = []; + var existingImages = []; - // Resize the image - const maxWidth = 1200; // Set your desired maximum width - const maxHeight = 1000; // Set your desired maximum height - const aspectRatio = img.width / img.height; + fetch('https://api.obanana.shop/api/v1/products/' + productId) + .then(response => response.json()) + .then(product => { + existingImages = product.images || []; + existingImages = Array.isArray(existingImages) ? existingImages : [existingImages]; + existingImages = existingImages.filter(image => image); + }) + .catch(error => { + console.error('Error fetching existing images:', error); + }); - let newWidth = img.width; - let newHeight = img.height; + for (let i = 0; i < files.length; i++) { + const file = files[i]; + const reader = new FileReader(); - if (img.width > maxWidth) { - newWidth = maxWidth; - newHeight = newWidth / aspectRatio; - } + const promise = new Promise((resolve, reject) => { + reader.onload = function(e) { + const img = new Image(); + img.onload = function() { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + const maxWidth = 1200; + const maxHeight = 1000; + const aspectRatio = img.width / img.height; + let newWidth = img.width; + let newHeight = img.height; - if (newHeight > maxHeight) { - newHeight = maxHeight; - newWidth = newHeight * aspectRatio; - } + if (img.width > maxWidth) { + newWidth = maxWidth; + newHeight = newWidth / aspectRatio; + } - canvas.width = newWidth; - canvas.height = newHeight; + if (newHeight > maxHeight) { + newHeight = maxHeight; + newWidth = newHeight * aspectRatio; + } - // Draw the image on the canvas - ctx.drawImage(img, 0, 0, newWidth, newHeight); + canvas.width = newWidth; + canvas.height = newHeight; + ctx.drawImage(img, 0, 0, newWidth, newHeight); - // Convert the canvas content to a new image file - canvas.toBlob((blob) => { - const resizedFile = new File([blob], file.name, { - type: 'image/jpeg' - }); - - // Continue with the rest of your upload logic using the resized file - var formData = new FormData(); - formData.append('image_id', productId); - formData.append('category', 'product'); - formData.append('image', resizedFile); - - fetch('https://api.obanana.shop/api/v1/upload_image', { - method: 'POST', - body: formData - }) - .then(response => { - if (response.ok) { - return response.json(); - } else { - console.error('File upload failed'); - throw new Error('File upload failed'); - } - }) - .then(result => { - const filename = result.filename; - - const payload = { - product_image: `https://api.obanana.shop/images/storage/product_uploads/${filename}`, - }; - - console.log('Payload:', payload); - const token = ''; - return fetch('https://api.obanana.shop/api/v1/products/' + productId, { - method: 'PATCH', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + token, - }, - body: JSON.stringify(payload) + canvas.toBlob((blob) => { + const resizedFile = new File([blob], file.name, { + type: 'image/jpeg' }); - }) - .then(secondResponse => { - if (secondResponse.ok) { - console.log('Second request successful'); - location.reload(); - } else { - console.error('Second request failed'); - } - }) - .catch(error => { - console.error('Error during fetch:', error); - }); - }, 'image/jpeg'); - }; - img.src = e.target.result; - }; + var formData = new FormData(); + formData.append('image_id', productId); + formData.append('category', 'product'); + formData.append('image', resizedFile); - reader.readAsDataURL(file); + fetch('https://api.obanana.shop/api/v1/upload_image', { + method: 'POST', + body: formData + }) + .then(response => { + if (response.ok) { + return response.json(); + } else { + console.error('File upload failed'); + reject(new Error('File upload failed')); + } + }) + .then(result => { + const filename = result.filename; + resolve(filename); + }) + .catch(error => { + console.error('Error during fetch:', error); + reject(error); + }); + }, 'image/jpeg'); + }; + + img.src = e.target.result; + }; + + reader.readAsDataURL(file); + }); + + promises.push(promise); + } + + Promise.all(promises) + .then(filenames => { + const updatedImages = existingImages.concat(filenames.map(filename => `https://api.obanana.shop/images/storage/product_uploads/${filename}`)); + + if (!Array.isArray(updatedImages)) { + console.error('Updated images is not an array:', updatedImages); + throw new Error('Updated images is not an array'); + } + const imagesString = updatedImages.join(','); + const payload = { + images: imagesString, + }; + + const token = ''; + return fetch('https://api.obanana.shop/api/v1/products/' + productId, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + token, + }, + body: JSON.stringify(payload) + }); + }) + .then(response => { + if (response.ok) { + console.log('Images uploaded successfully'); + location.reload(); + } else { + console.error('Image upload failed'); + } + }) + .catch(error => { + console.error('Error during image upload:', error); + }); } } + + From 4f8a0c54717b9c95e1b219dd68d4bb756835b2dc Mon Sep 17 00:00:00 2001 From: webdeveloper Date: Thu, 15 Feb 2024 20:42:37 +0800 Subject: [PATCH 2/3] introduced config.php - test mode, test email, data endpoint --- admin/add_vendor_action.php | 2 +- admin/config.php | 5 + admin/index.php | 2 +- admin/login.php | 2 +- admin/logout.php | 2 +- admin/order-history.php | 8 +- admin/product-add-action.bak.php | 2 +- admin/product-add-action.php | 2 +- admin/product-add.bak.php | 2 +- admin/product-delete-action.php | 3 +- admin/product-edit-action.php | 2 +- admin/product-edit.php | 8 +- admin/product-grid.php | 10 +- admin/update-token-session.php | 2 +- admin/upload_monitor.php | 5 +- admin/upload_monitor_user.php | 5 +- admin/user-card-action.php | 2 +- admin/user-card.php | 4 +- admin/vendor-card-2.php | 2 +- admin/vendor-card.php | 14 +-- admin/vendor-delete-action.php | 4 +- admin/vendor-list.php | 2 +- admin/vendor-product-grid.bak.php | 10 +- admin/vendor-product-grid.php | 4 +- admin/vendor-profile.php | 2 +- admin/vendor_list_action.php | 2 +- cart.php | 22 ++--- catalog-single-vendor.php | 2 +- check_session_variables.php | 46 ++------- checkout.php | 10 +- checkouttest.php | 10 +- contact-us-action.php | 2 +- forget_otp.php | 4 +- forget_otp_action.php | 2 +- forgot_password_action.php | 4 +- functions.php | 126 +++++++++++++----------- header.php | 16 +-- index.php | 2 +- info.php | 3 + login.php | 2 +- login_action.php | 2 +- offer.php | 2 +- product-left-sidebar.php | 18 ++-- register.php | 2 +- register_action.php | 2 +- register_customer.php | 2 +- register_customer_action.php | 2 +- register_otp.php | 2 +- register_otp_action.php | 2 +- register_vendor.php | 2 +- register_vendor_action.php | 4 +- same_day_delivery.php | 2 +- search_product_action.php | 4 +- selected_variation.php | 2 +- shop-left-sidebar-col-4.php | 2 +- shop-list-left-sidebar.php | 2 +- shop-list-left-sidebar2.php | 2 +- update-token-session.php | 2 +- user-history.php | 14 +-- user-profile.php | 18 ++-- user-refund-history.php | 2 +- vendor-all-product-list.php | 4 +- vendor-dashboard-orders-edit-action.php | 2 +- vendor-dashboard-orders-edit.php | 2 +- vendor-dashboard.php | 4 +- vendor-list.php | 2 +- vendor-profile.php | 2 +- vendor-refund-history.php | 8 +- vendor-settings.php | 24 ++--- vendor-uploads-add-product-action.php | 2 +- vendor-uploads-edit-product-action.php | 2 +- vendor-uploads.php | 8 +- wishlist.php | 4 +- 73 files changed, 252 insertions(+), 261 deletions(-) create mode 100644 admin/config.php create mode 100644 info.php diff --git a/admin/add_vendor_action.php b/admin/add_vendor_action.php index a54aa0d..d7066b5 100644 --- a/admin/add_vendor_action.php +++ b/admin/add_vendor_action.php @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index 14c69dd..65db273 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/admin/login.php b/admin/login.php index acccbda..a1883c5 100644 --- a/admin/login.php +++ b/admin/login.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -959,7 +959,7 @@ $allorders = json_encode($orders, true); var password = ''; function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -1029,7 +1029,7 @@ $allorders = json_encode($orders, true); // Define your functions here function toReceiveFunction(orderId, reason, image, token) { // const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -1057,7 +1057,7 @@ $allorders = json_encode($orders, true); } function refundCompleteFunction(orderId, reason, image, token) { - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', diff --git a/admin/product-add-action.bak.php b/admin/product-add-action.bak.php index 6b5699e..f2610ff 100644 --- a/admin/product-add-action.bak.php +++ b/admin/product-add-action.bak.php @@ -1,6 +1,6 @@ '; $productName = $_POST['product_name']; diff --git a/admin/product-add.bak.php b/admin/product-add.bak.php index 9294bbc..a726648 100644 --- a/admin/product-add.bak.php +++ b/admin/product-add.bak.php @@ -1,6 +1,6 @@ diff --git a/admin/product-delete-action.php b/admin/product-delete-action.php index c80aec4..f3ede2a 100644 --- a/admin/product-delete-action.php +++ b/admin/product-delete-action.php @@ -1,7 +1,8 @@ 'https://api.obanana.shop/api/v1/products/656717579624f6181c49cdda', diff --git a/admin/product-edit-action.php b/admin/product-edit-action.php index 492717a..7c116e7 100644 --- a/admin/product-edit-action.php +++ b/admin/product-edit-action.php @@ -1,6 +1,6 @@ '; diff --git a/admin/product-edit.php b/admin/product-edit.php index 84f9fec..6968787 100644 --- a/admin/product-edit.php +++ b/admin/product-edit.php @@ -1,6 +1,6 @@ "") { @@ -1046,7 +1046,7 @@ $vendorId = $_SESSION["vendorId"]; formData.append('category', 'product'); formData.append('image', resizedFile); - fetch('https://api.obanana.shop/api/v1/upload_image', { + fetch('https:///api/v1/upload_image', { method: 'POST', body: formData }) @@ -1062,12 +1062,12 @@ $vendorId = $_SESSION["vendorId"]; const filename = result.filename; const payload = { - product_image: `https://api.obanana.shop/images/storage/product_uploads/${filename}`, + product_image: `https:///images/storage/product_uploads/${filename}`, }; console.log('Payload:', payload); const token = ''; - return fetch('https://api.obanana.shop/api/v1/products/' + productId, { + return fetch('https:///api/v1/products/' + productId, { method: 'PATCH', headers: { 'Content-Type': 'application/json', diff --git a/admin/product-grid.php b/admin/product-grid.php index 4c5e8ea..4634636 100644 --- a/admin/product-grid.php +++ b/admin/product-grid.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -928,7 +928,7 @@ if($_SESSION["user_type"]!="admin"){ formData.append('category', 'product'); formData.append('image', file); - fetch('https://api.obanana.shop/api/v1/upload_image', { + fetch('https:///api/v1/upload_image', { method: 'POST', body: formData }) @@ -947,7 +947,7 @@ if($_SESSION["user_type"]!="admin"){ const filename = result.filename; const payload = { - product_image: `https://api.obanana.shop/images/storage/product_uploads/${filename}`, + product_image: `https:///images/storage/product_uploads/${filename}`, vendor_api_id: vendor, product_name: updatedName, stock: updatedStock, @@ -963,7 +963,7 @@ if($_SESSION["user_type"]!="admin"){ console.log('Payload:', payload); // Make another API request using the extracted filename - return fetch('https://api.obanana.shop/api/v1/products/' + productId, { + return fetch('https:///api/v1/products/' + productId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -988,7 +988,7 @@ if($_SESSION["user_type"]!="admin"){ } else { // If no file selected, only update the email - fetch('https://api.obanana.shop/api/v1/products/' + productId, { + fetch('https:///api/v1/products/' + productId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' diff --git a/admin/update-token-session.php b/admin/update-token-session.php index 652ac4d..3423690 100644 --- a/admin/update-token-session.php +++ b/admin/update-token-session.php @@ -1,5 +1,5 @@ @@ -169,7 +170,7 @@ function getAllProducts() $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products/search?q=', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -194,7 +195,7 @@ function getAllUsers() $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/users', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/users", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, diff --git a/admin/upload_monitor_user.php b/admin/upload_monitor_user.php index d2ce03c..891402f 100644 --- a/admin/upload_monitor_user.php +++ b/admin/upload_monitor_user.php @@ -1,4 +1,5 @@ 'https://api.obanana.shop/api/v1/users', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/users", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -108,7 +109,7 @@ function getAllProducts() $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products/search?q=', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, diff --git a/admin/user-card-action.php b/admin/user-card-action.php index c25141d..d7bb536 100644 --- a/admin/user-card-action.php +++ b/admin/user-card-action.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -762,7 +762,7 @@ $users = getUsers(); } function login(username, password, sessionToken, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/admin/vendor-card-2.php b/admin/vendor-card-2.php index 97e976f..f4111d0 100644 --- a/admin/vendor-card-2.php +++ b/admin/vendor-card-2.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/admin/vendor-card.php b/admin/vendor-card.php index add84a8..111c49c 100644 --- a/admin/vendor-card.php +++ b/admin/vendor-card.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -892,7 +892,7 @@ function deleteVendor(vendorId){ formData.append('category', 'vendor'); formData.append('image', file); - fetch('https://api.obanana.shop/api/v1/upload_image', { + fetch('https:///api/v1/upload_image', { method: 'POST', body: formData }) @@ -908,7 +908,7 @@ function deleteVendor(vendorId){ const filename = result.filename; const payload = { - vendor_image: `https://api.obanana.shop/images/storage/vendor_uploads/${filename}`, + vendor_image: `https:///images/storage/vendor_uploads/${filename}`, user_login: updatedUser, first_name: firstName, last_name: lastName, @@ -927,7 +927,7 @@ function deleteVendor(vendorId){ }; // Make another API request using the extracted filename - return fetch('https://api.obanana.shop/api/v1/vendors/' + vendorId, { + return fetch('https:///api/v1/vendors/' + vendorId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -948,7 +948,7 @@ function deleteVendor(vendorId){ }); } else { // If no file selected, only update the email - fetch('https://api.obanana.shop/api/v1/vendors/' + vendorId, { + fetch('https:///api/v1/vendors/' + vendorId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -992,7 +992,7 @@ function deleteVendor(vendorId){ var email = emailInput.value; if (email.trim() !== '') { - return fetch('https://api.obanana.shop/api/v1/vendors/search?q=' + email) + return fetch('https:///api/v1/vendors/search?q=' + email) .then(response => { if (response.ok) { return response.json(); @@ -1301,7 +1301,7 @@ function deleteVendor(vendorId){ if (email.trim() !== '') { var response; $.ajax({ - url: 'https://api.obanana.shop/api/v1/vendors/search?q=' + email, + url: 'https:///api/v1/vendors/search?q=' + email, method: 'GET', success: function(data) { response = data; diff --git a/admin/vendor-delete-action.php b/admin/vendor-delete-action.php index bb8abed..4afde7c 100644 --- a/admin/vendor-delete-action.php +++ b/admin/vendor-delete-action.php @@ -1,10 +1,10 @@ true, diff --git a/admin/vendor-list.php b/admin/vendor-list.php index b426fa7..98b8c67 100644 --- a/admin/vendor-list.php +++ b/admin/vendor-list.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/admin/vendor-product-grid.bak.php b/admin/vendor-product-grid.bak.php index 0126d8e..c528093 100644 --- a/admin/vendor-product-grid.bak.php +++ b/admin/vendor-product-grid.bak.php @@ -1,6 +1,6 @@ @@ -1102,7 +1102,7 @@ $vendorId = $_SESSION["vendorId"]; formData.append('category', 'product'); formData.append('image', file); - fetch('https://api.obanana.shop/api/v1/upload_image', { + fetch('https:///api/v1/upload_image', { method: 'POST', body: formData }) @@ -1121,7 +1121,7 @@ $vendorId = $_SESSION["vendorId"]; const filename = result.filename; const payload = { - product_image: `https://api.obanana.shop/images/storage/product_uploads/${filename}`, + product_image: `https:///images/storage/product_uploads/${filename}`, vendor_api_id: vendor, product_name: updatedName, stock: updatedStock, @@ -1137,7 +1137,7 @@ $vendorId = $_SESSION["vendorId"]; console.log('Payload:', payload); // Make another API request using the extracted filename - return fetch('https://api.obanana.shop/api/v1/products/' + productId, { + return fetch('https:///api/v1/products/' + productId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -1161,7 +1161,7 @@ $vendorId = $_SESSION["vendorId"]; }); } else { // If no file selected, only update the email - fetch('https://api.obanana.shop/api/v1/products/' + productId, { + fetch('https:///api/v1/products/' + productId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' diff --git a/admin/vendor-product-grid.php b/admin/vendor-product-grid.php index 716b86b..f8f24c9 100644 --- a/admin/vendor-product-grid.php +++ b/admin/vendor-product-grid.php @@ -1,6 +1,6 @@ "") { @@ -777,7 +777,7 @@ if($_SESSION["user_type"]!="admin"){ } function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/admin/vendor-profile.php b/admin/vendor-profile.php index 6d87715..2553644 100644 --- a/admin/vendor-profile.php +++ b/admin/vendor-profile.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -255,7 +255,7 @@ if ($_SESSION["userId"] <> "") { function handleQtyInputCart(input, orderId, itemId, prodId) { var newQuantity = parseInt(input.value); // updateQuantityCart(orderId, itemId, newQuantity); - fetch(`https://api.obanana.shop/api/v1/products/${prodId}`, { + fetch(`https:///api/v1/products/${prodId}`, { method: 'GET' }) @@ -301,7 +301,7 @@ if ($_SESSION["userId"] <> "") { } function qtyIncrementCart(orderId, itemId, isFloat, prodId) { - fetch(`https://api.obanana.shop/api/v1/products/${prodId}`, { + fetch(`https:///api/v1/products/${prodId}`, { method: 'GET' }) @@ -352,7 +352,7 @@ if ($_SESSION["userId"] <> "") { function qtyDecrementCart(orderId, itemId, isFloat, prodId) { console.log('decrementing') - fetch(`https://api.obanana.shop/api/v1/products/${prodId}`, { + fetch(`https:///api/v1/products/${prodId}`, { method: 'GET' }) @@ -408,7 +408,7 @@ if ($_SESSION["userId"] <> "") { function updateQuantityCart(orderId, itemId, newQuantity, isFloat) { console.log(isFloat) const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}/items/${itemId}`, { + fetch(`https:///api/v1/orders/${orderId}/items/${itemId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -441,7 +441,7 @@ if ($_SESSION["userId"] <> "") { function updateFloatTotalAmountCart(orderId) { // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`) + fetch(`https:///api/v1/orders/${orderId}`) .then(response => response.json()) .then(orderData => { console.log("This is the OrderData: " + JSON.stringify(orderData, null, 2)); @@ -457,7 +457,7 @@ if ($_SESSION["userId"] <> "") { // Perform the PATCH request to update the total amount in the API const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -487,7 +487,7 @@ if ($_SESSION["userId"] <> "") { function updateTotalAmountCart(orderId) { // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`) + fetch(`https:///api/v1/orders/${orderId}`) .then(response => response.json()) .then(orderData => { if (orderData && orderData !== "") { @@ -504,7 +504,7 @@ if ($_SESSION["userId"] <> "") { // Perform the PATCH request to update the total amount in the API const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -534,7 +534,7 @@ if ($_SESSION["userId"] <> "") { function getLatestOrdersCart() { var customerId = '' // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/customer/${customerId}`) + fetch(`https:///api/v1/orders/customer/${customerId}`) .then(response => response.json()) .then(orderData => { if (orderData && orderData !== "") { @@ -563,7 +563,7 @@ if ($_SESSION["userId"] <> "") { function deleteOrderCart(orderId) { console.log('delete') - fetch('https://api.obanana.shop/api/v1/orders/' + orderId, { + fetch('https:///api/v1/orders/' + orderId, { method: 'DELETE' }) .then(response => response.json()) diff --git a/catalog-single-vendor.php b/catalog-single-vendor.php index a66b9a2..bc7a985 100644 --- a/catalog-single-vendor.php +++ b/catalog-single-vendor.php @@ -3,7 +3,7 @@ use Symfony\Component\VarDumper\VarDumper; include "functions.php"; -session_start(); + $_SESSION["url"] = $_SERVER['REQUEST_URI']; if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = true; diff --git a/check_session_variables.php b/check_session_variables.php index bdbebe3..04f3d39 100644 --- a/check_session_variables.php +++ b/check_session_variables.php @@ -1,37 +1,9 @@ -"; - echo "email : ".$_SESSION["email"]."
"; - echo "password : ".$_SESSION["password"]."
"; - echo "firstname : ".$_SESSION["firstname"]."
"; - echo "lastname : ".$_SESSION["lastname"]."
"; - echo "company : ".$_SESSION["company"]."
"; - echo "phone : ".$_SESSION["phone"]."
"; - if($_SESSION["isCustomer"]){ - echo "isCustomer : true
"; - } else { - echo "isCustomer : false
"; - } - echo "customerId : ".$_SESSION["customerId"]."
"; - if($_SESSION["isVendor"]){ - echo "isVendor : true
"; - } else { - echo "isVendor : false
"; - } - echo "vendorId : ".$_SESSION["vendorId"]."
"; - echo "otp : ".$_SESSION["otp"]."
"; - echo "token : ".$_SESSION["token"]."
"; - echo "userId : ".$_SESSION["userId"]."
"; - if($_SESSION["isLoggedIn"]){ - echo "isLoggedIn : true
"; - } else { - echo "isLoggedIn : false
"; - } - echo "url : ".$_SESSION["url"]."
"; - echo "cartitems : ".count($_SESSION["cart_items"])."
"; - echo "productId : ".$_SESSION["productId"]."
"; - if (isset($_SESSION["LoggedInVendorId"])) { - echo "LoggedInVendorId: " . $_SESSION["LoggedInVendorId"] . "
"; - } - -?> \ No newline at end of file +'; + var_dump($_SESSION); + echo ''; +}else{ + echo "

Alert! This only works in test mode.

"; +} diff --git a/checkout.php b/checkout.php index 305f227..a0d9dd4 100644 --- a/checkout.php +++ b/checkout.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -489,7 +489,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] $('#submitBtn').on('click', function() { // Retrieve existing addresses from the API // fetch('https://api.obanana.shop/api/v1/customers/65482e8d209ff8d348bd30fd') - fetch('https://api.obanana.shop/api/v1/customers/' + customerId) + fetch('https:///api/v1/customers/' + customerId) .then(response => response.json()) .then(data => { // Get the existing addresses array @@ -524,7 +524,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] existingAddresses.push(newAddress); // Make a PATCH request to update the addresses array - return fetch('https://api.obanana.shop/api/v1/customers/' + customerId, { + return fetch('https:///api/v1/customers/' + customerId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -892,7 +892,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] ordersToUpdate.forEach(async (orderId) => { // console.log(orderId) - const patchResponse = await fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + const patchResponse = await fetch(`https:///api/v1/orders/${orderId}`, { method: "PATCH", body: JSON.stringify({ // shipping_address:{ @@ -947,7 +947,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] ordersToUpdate.forEach(async (orderId) => { // console.log(orderId) - const patchResponse = await fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + const patchResponse = await fetch(`https:///api/v1/orders/${orderId}`, { method: "PATCH", body: JSON.stringify({ shipping_address: { diff --git a/checkouttest.php b/checkouttest.php index 5411e25..154742a 100644 --- a/checkouttest.php +++ b/checkouttest.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -490,7 +490,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] $('#submitBtn').on('click', function() { // Retrieve existing addresses from the API // fetch('https://api.obanana.shop/api/v1/customers/65482e8d209ff8d348bd30fd') - fetch('https://api.obanana.shop/api/v1/customers/' + customerId) + fetch('https:///api/v1/customers/' + customerId) .then(response => response.json()) .then(data => { // Get the existing addresses array @@ -525,7 +525,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] existingAddresses.push(newAddress); // Make a PATCH request to update the addresses array - return fetch('https://api.obanana.shop/api/v1/customers/' + customerId, { + return fetch('https:///api/v1/customers/' + customerId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -937,7 +937,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] console.log(orderId) const token = ''; const shippingfee = parseFloat(orderId.shipping_fee) - const patchResponse = await fetch(`https://api.obanana.shop/api/v1/orders/${orderId._id}`, { + const patchResponse = await fetch(`https:///api/v1/orders/${orderId._id}`, { method: "PATCH", body: JSON.stringify({ shipping_address: { @@ -1020,7 +1020,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] console.log(orderId) const token = ''; const shippingfee = parseFloat(orderId.shipping_fee) - const patchResponse = await fetch(`https://api.obanana.shop/api/v1/orders/${orderId._id}`, { + const patchResponse = await fetch(`https:///api/v1/orders/${orderId._id}`, { method: "PATCH", body: JSON.stringify({ shipping_address: { diff --git a/contact-us-action.php b/contact-us-action.php index f6a1164..3625a62 100644 --- a/contact-us-action.php +++ b/contact-us-action.php @@ -1,6 +1,6 @@ @@ -181,7 +181,7 @@ var pass2I = document.getElementById(`passInput2`); var email = '' if (otp && pass && pass2) { if (pass === pass2) { - fetch(`https://api.obanana.shop/api/v1/change-password`, { + fetch(`https:///api/v1/change-password`, { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/forget_otp_action.php b/forget_otp_action.php index 3fc8e4e..83ba3e1 100644 --- a/forget_otp_action.php +++ b/forget_otp_action.php @@ -1,6 +1,6 @@ 'https://api.obanana.shop/api/v1/products', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -30,7 +31,7 @@ function simpleProducts($category) // function searchProducts($query) // { // $query = str_replace(" ", "+", $query); -// $url = "https://api.obanana.shop/api/v1/products/search?q=$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( @@ -57,7 +58,7 @@ function simpleProducts($category) function searchProducts($query) { $query = str_replace(" ", "+", $query); - $url = "https://api.obanana.shop/api/v1/products/search?q=$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( @@ -108,11 +109,11 @@ $result = searchProducts($query); // function searchProducts($query) // { // $query = str_replace(" ", "+", $query); -// $url = "https://api.obanana.shop/api/v1/products/search?q=$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://api.obanana.shop/api/v1/products/search?q=phone', +// //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -133,7 +134,7 @@ $result = searchProducts($query); function getProduct($product) { - $url = "https://api.obanana.shop/api/v1/products/$product"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/$product"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( @@ -157,7 +158,7 @@ function productList() { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -179,10 +180,10 @@ function productList() function productListVendor($vendorId) { $curl = curl_init(); - $url = 'https://api.obanana.shop/api/v1/products/vendor/' . $vendorId; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/" . $vendorId; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( - //CURLOPT_URL => 'https://api.obanana.shop/api/v1/products/vendor/6527b593f79b5deac5ad6cb8', + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/6527b593f79b5deac5ad6cb8', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -209,7 +210,7 @@ function getProductVariations($parent_id) { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -245,7 +246,7 @@ function register($username, $password) $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/register', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/register", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -273,7 +274,7 @@ function login($username, $password) $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/login', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/login", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -293,6 +294,9 @@ function login($username, $password) } 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 @@ -300,7 +304,7 @@ function forgot_password($email) $json = json_encode($array); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/forgot-password', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/forgot-password", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -320,7 +324,7 @@ function forgot_password($email) function getCustomerbyLoginId($id) { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/customers/login_id/$id"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/login_id/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, @@ -344,7 +348,7 @@ function getCustomerbyLoginId($id) function getCustomer($id) { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/customers/$id"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, @@ -368,7 +372,7 @@ function getCustomer($id) function getVendorbyLoginId($id) { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/vendors/login_id/$id"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/login_id/$id"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, @@ -392,7 +396,7 @@ function getVendorbyLoginId($id) function customerExists($email) { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/customers/search?q=$email"; + $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, @@ -420,7 +424,7 @@ function customerExists($email) function vendorExists($email) { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/vendors/search?q=$email"; + $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, @@ -449,7 +453,9 @@ function vendorExists($email) function sendEmail($fName, $lName, $email, $phone, $message) { - $email2 = "stacyjoycemapano@gmail.com"; + if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ + $email = $_SESSION["test_email_rcpt"]; + } $message2 = "

Greetings from Obanana!

    @@ -468,7 +474,7 @@ function sendEmail($fName, $lName, $email, $phone, $message) ], "To" => [ [ - "Email" => $email2, + "Email" => $email, "Name" => "Subscriber" ] ], @@ -484,7 +490,7 @@ function sendEmail($fName, $lName, $email, $phone, $message) $curl = curl_init(); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.mailjet.com/v3.1/send', + CURLOPT_URL => "https://api.mailjet.com/v3.1/send", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -507,7 +513,9 @@ function sendEmail($fName, $lName, $email, $phone, $message) function sendOTP($email) { - $email2 = "junjihadbarroga@gmail.com"; + if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){ + $email = $_SESSION["test_email_rcpt"]; + } $curl = curl_init(); $otp = generateOTP(6); $json = '{ @@ -519,7 +527,7 @@ function sendOTP($email) }, "To": [ { - "Email": "' . $email2 . '", + "Email": "' . $email . '", "Name": "Subscriber" } ], @@ -531,7 +539,7 @@ function sendOTP($email) }'; curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.mailjet.com/v3.1/send', + CURLOPT_URL => "https://api.mailjet.com/v3.1/send", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -581,7 +589,7 @@ function createCustomer($email, $phone, $firstname, $lastname, $loginId, $token) curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/customers', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/customers", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -600,7 +608,7 @@ function createCustomer($email, $phone, $firstname, $lastname, $loginId, $token) function updateCustomer($customerId, $phone, $firstname, $lastname, $loginId, $token) { - $url = "https://api.obanana.shop/api/v1/customers/$customerId"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/customers/$customerId"; $array = '{ "last_name": "' . $lastname . '", "login_id": "' . $loginId . '", @@ -637,7 +645,7 @@ function profile($token) $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/profile', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/profile", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -663,7 +671,7 @@ function profile($token) // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( -// CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', +// CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -683,7 +691,7 @@ function profile($token) // function updateVendor($vendorId, $phone, $company, $loginId, $token) // { -// $url = "https://api.obanana.shop/api/v1/vendors/$vendorId"; +// $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/$vendorId"; // $array = '{ // "login_id": "' . $loginId . '", // "first_name": "' . $company . '", @@ -712,7 +720,7 @@ function profile($token) // } function updateVendor($vendorId, $phone, $userlogin, $firstname, $lastname, $loginId, $token) { - $url = "https://api.obanana.shop/api/v1/vendors/$vendorId"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/vendors/$vendorId"; $array = '{ "login_id": "' . $loginId . '", "user_login": "' . $userlogin . '", @@ -755,7 +763,7 @@ function createVendor($email, $phone, $userlogin, $firstname, $lastname, $loginI ); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -824,7 +832,7 @@ function createVendor($email, $phone, $userlogin, $firstname, $lastname, $loginI // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( -// CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', +// CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -850,7 +858,7 @@ function vendorList() { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -873,7 +881,7 @@ function simpleVendors() { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -902,7 +910,7 @@ function productListVendors($vendorIds) $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products?vendor_ids=' . $vendorIdsString, + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products?vendor_ids=" . $vendorIdsString, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -925,7 +933,7 @@ function simpleVendorsWithProducts() { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -988,11 +996,11 @@ function simpleVendorsWithProducts() function getVendorbyId($id) { - $url = "https://api.obanana.shop/api/v1/vendors/$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://api.obanana.shop/api/v1/products/search?q=phone', + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1012,7 +1020,7 @@ function getVendorbyId($id) function searchVendorByLoginId($id) { $id = str_replace(" ", "+", $id); - $url = "https://api.obanana.shop/api/v1/vendors/search?q=$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( @@ -1034,7 +1042,7 @@ function searchVendorByLoginId($id) function getOrder($order) { - $url = "https://api.obanana.shop/api/v1/orders/$order"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/orders/$order"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt_array($curl, array( @@ -1058,7 +1066,7 @@ function getAllOrder() { $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/orders', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/orders", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1086,11 +1094,11 @@ function getAllOrder() function getOrderbyCustomerId($id) { - $url = "https://api.obanana.shop/api/v1/orders/customer/$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://api.obanana.shop/api/v1/products/search?q=phone', + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1108,11 +1116,11 @@ function getOrderbyCustomerId($id) } function getOrderbyVendorId($id) { - $url = "https://api.obanana.shop/api/v1/orders/vendor/$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://api.obanana.shop/api/v1/products/search?q=phone', + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1142,7 +1150,7 @@ function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $co } $params3 = json_encode($data); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/orders/' . $orderId, + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/orders/" . $orderId, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1174,7 +1182,7 @@ function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $co // $curl = curl_init(); // curl_setopt($curl,CURLOPT_POSTFIELDS,$array); // curl_setopt_array($curl, array( -// CURLOPT_URL => 'https://api.obanana.shop/api/v1/orders', +// CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/orders', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -1193,11 +1201,11 @@ function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $co function deleteOrderbyId($id) { - $url = "https://api.obanana.shop/api/v1/orders/$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://api.obanana.shop/api/v1/products/search?q=phone', + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/search?q=phone', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1247,7 +1255,7 @@ function addProduct( ); curl_setopt($curl, CURLOPT_POSTFIELDS, $array); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1325,11 +1333,11 @@ function editProduct( } // $params3 = json_encode($data); - // $url = 'https://api.obanana.shop/api/v1/products/'.$productId; + // $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://api.obanana.shop/api/v1/products/656712969624f6181c49cdd0', + // //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/656712969624f6181c49cdd0', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -1345,7 +1353,7 @@ function editProduct( $params3 = json_encode($data); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/products/' . $productId, + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/products/" . $productId, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1390,7 +1398,7 @@ function editProduct( // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( -// CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', +// CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/vendors', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -1448,7 +1456,7 @@ function addVendor( $params2 = json_encode($data); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/vendors', + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/vendors", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1473,7 +1481,7 @@ function addVendor( function getUsers() { $curl = curl_init(); - $url = "https://api.obanana.shop/api/v1/users"; + $url = "https://".$_SESSION["data_endpoint"]."/api/v1/users"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, @@ -1508,7 +1516,7 @@ function getUsers() // ); // curl_setopt($curl, CURLOPT_POSTFIELDS, $array); // curl_setopt_array($curl, array( -// CURLOPT_URL => 'https://api.obanana.shop/api/v1/users/' . $id, +// CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/users/' . $id, // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, @@ -1540,7 +1548,7 @@ function editUsers($id, $username, $userType, $token) $jsonPayload = json_encode($data); // Convert the array to JSON format curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.obanana.shop/api/v1/users/' . $id, + CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/users/" . $id, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, @@ -1561,4 +1569,4 @@ function editUsers($id, $username, $userType, $token) echo $response; return $response; -} +} \ No newline at end of file diff --git a/header.php b/header.php index 03c1da5..85fdd4e 100644 --- a/header.php +++ b/header.php @@ -411,7 +411,7 @@ var password = ''; function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -488,7 +488,7 @@ function updateQuantity(orderId, itemId, newQuantity, isFloat, token) { console.log(isFloat) // const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}/items/${itemId}`, { + fetch(`https:///api/v1/orders/${orderId}/items/${itemId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -521,7 +521,7 @@ function updateFloatTotalAmount(orderId, token) { // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`) + fetch(`https:///api/v1/orders/${orderId}`) .then(response => response.json()) .then(orderData => { console.log("This is the OrderData: " + JSON.stringify(orderData, null, 2)); @@ -537,7 +537,7 @@ // Perform the PATCH request to update the total amount in the API // const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -568,7 +568,7 @@ function updateTotalAmount(orderId, token) { // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`) + fetch(`https:///api/v1/orders/${orderId}`) .then(response => response.json()) .then(orderData => { if (orderData && orderData !== "") { @@ -583,7 +583,7 @@ // Perform the PATCH request to update the total amount in the API // const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -614,7 +614,7 @@ function getLatestOrders() { var customerId = '' // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/customer/${customerId}`) + fetch(`https:///api/v1/orders/customer/${customerId}`) .then(response => response.json()) .then(orderData => { if (orderData && orderData !== "") { @@ -635,7 +635,7 @@ } function deleteOrder(orderId) { - fetch('https://api.obanana.shop/api/v1/orders/' + orderId, { + fetch('https:///api/v1/orders/' + orderId, { method: 'DELETE' }) .then(response => response.json()) diff --git a/index.php b/index.php index e6ef7d0..29f23ad 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ use Symfony\Component\VarDumper\VarDumper; include "functions.php"; -session_start(); + $_SESSION["url"] = $_SERVER['REQUEST_URI']; if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = true; diff --git a/info.php b/info.php new file mode 100644 index 0000000..640e4f2 --- /dev/null +++ b/info.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/login.php b/login.php index 083bb6f..f490659 100644 --- a/login.php +++ b/login.php @@ -1,5 +1,5 @@ diff --git a/login_action.php b/login_action.php index 5fbb4db..f3358ef 100644 --- a/login_action.php +++ b/login_action.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/product-left-sidebar.php b/product-left-sidebar.php index 9202a4f..e05ab00 100644 --- a/product-left-sidebar.php +++ b/product-left-sidebar.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -579,7 +579,7 @@ foreach ($variation_details as $index => $variation) { var wishCustomerId = ''; var wishProductId = ''; - fetch('https://api.obanana.shop/api/v1/customers/' + wishCustomerId) + fetch('https:///api/v1/customers/' + wishCustomerId) .then(response => response.json()) .then(data => { const existingWishlist = data.favorites ?? { @@ -599,7 +599,7 @@ foreach ($variation_details as $index => $variation) { existingWishlist.products.push(newFavorites.products[0]); - return fetch('https://api.obanana.shop/api/v1/customers/' + wishCustomerId, { + return fetch('https:///api/v1/customers/' + wishCustomerId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -639,7 +639,7 @@ foreach ($variation_details as $index => $variation) { var password = ''; function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -722,7 +722,7 @@ foreach ($variation_details as $index => $variation) { // Check if the product is already in the order API var existingOrder; var orderCheckXhr = new XMLHttpRequest(); - orderCheckXhr.open("GET", "https://api.obanana.shop/api/v1/orders/customer/" + customerData.customer_id, true); + orderCheckXhr.open("GET", "https:///api/v1/orders/customer/" + customerData.customer_id, true); orderCheckXhr.onreadystatechange = function() { if (orderCheckXhr.readyState === 4) { if (orderCheckXhr.status === 200) { @@ -768,7 +768,7 @@ foreach ($variation_details as $index => $variation) { console.log("Request data:", requestData); // Debugging statement // const token = ''; - xhr.open("POST", "https://api.obanana.shop/api/v1/orders", true); + xhr.open("POST", "https:///api/v1/orders", true); xhr.setRequestHeader("Content-Type", "application/json", ); xhr.setRequestHeader("Authorization", "Bearer " + token); xhr.onreadystatechange = function() { @@ -823,7 +823,7 @@ foreach ($variation_details as $index => $variation) { function getLatestOrders() { var customerId = '' // Fetch the order data - fetch(`https://api.obanana.shop/api/v1/orders/customer/${customerId}`) + fetch(`https:///api/v1/orders/customer/${customerId}`) .then(response => response.json()) .then(orderData => { if (orderData && orderData !== "") { @@ -846,7 +846,7 @@ foreach ($variation_details as $index => $variation) { function updateOrder(orderId, existingItemId) { var updateOrderXhr = new XMLHttpRequest(); // const token = ''; - updateOrderXhr.open("PUT", `https://api.obanana.shop/api/v1/orders/${orderId}/items/${existingItemId}`, true); + updateOrderXhr.open("PUT", `https:///api/v1/orders/${orderId}/items/${existingItemId}`, true); updateOrderXhr.setRequestHeader("Content-Type", "application/json"); updateOrderXhr.setRequestHeader("Authorization", "Bearer " + token); updateOrderXhr.onreadystatechange = function() { @@ -909,7 +909,7 @@ foreach ($variation_details as $index => $variation) { updateOrderXhr.send(JSON.stringify(updateData)); var patchTotalAmountXhr = new XMLHttpRequest(); - patchTotalAmountXhr.open("PATCH", `https://api.obanana.shop/api/v1/orders/${orderId}`, true); + patchTotalAmountXhr.open("PATCH", `https:///api/v1/orders/${orderId}`, true); patchTotalAmountXhr.setRequestHeader("Content-Type", "application/json"); patchTotalAmountXhr.setRequestHeader("Authorization", "Bearer " + token); diff --git a/register.php b/register.php index 4e2a4a5..01b1811 100644 --- a/register.php +++ b/register.php @@ -1,5 +1,5 @@ diff --git a/register_action.php b/register_action.php index e780c35..fc638cb 100644 --- a/register_action.php +++ b/register_action.php @@ -1,6 +1,6 @@ diff --git a/register_customer_action.php b/register_customer_action.php index 73d156d..2645795 100644 --- a/register_customer_action.php +++ b/register_customer_action.php @@ -1,6 +1,6 @@ diff --git a/register_otp_action.php b/register_otp_action.php index dafe29e..a8a956f 100644 --- a/register_otp_action.php +++ b/register_otp_action.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/search_product_action.php b/search_product_action.php index 5436aa0..a6b0ba8 100644 --- a/search_product_action.php +++ b/search_product_action.php @@ -1,6 +1,6 @@ "" ) { $_SESSION["isLoggedIn"] = true; diff --git a/shop-list-left-sidebar.php b/shop-list-left-sidebar.php index 19dce21..cc2f1c5 100644 --- a/shop-list-left-sidebar.php +++ b/shop-list-left-sidebar.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/shop-list-left-sidebar2.php b/shop-list-left-sidebar2.php index 137174e..ad26827 100644 --- a/shop-list-left-sidebar2.php +++ b/shop-list-left-sidebar2.php @@ -1,6 +1,6 @@ "") { $_SESSION["isLoggedIn"] = true; diff --git a/update-token-session.php b/update-token-session.php index 652ac4d..3423690 100644 --- a/update-token-session.php +++ b/update-token-session.php @@ -1,5 +1,5 @@ "") { $_SESSION["isLoggedIn"] = true; @@ -408,7 +408,7 @@ if ($_SESSION["userId"] <> "") { var password = ''; function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -498,7 +498,7 @@ if ($_SESSION["userId"] <> "") { console.log('FormData:', formData); - fetch('https://api.obanana.shop/api/v1/upload_image', { + fetch('https:///api/v1/upload_image', { method: 'POST', body: formData }) @@ -528,12 +528,12 @@ if ($_SESSION["userId"] <> "") { const payload = { return_order: { reason: reason, - image: `https://api.obanana.shop/images/storage/order_uploads/${filename}`, + image: `https:///images/storage/order_uploads/${filename}`, status: 'To Approve', } } // const token = ''; - fetch('https://api.obanana.shop/api/v1/orders/' + orderId, { + fetch('https:///api/v1/orders/' + orderId, { method: 'PATCH', headers: { 'Content-Type': 'application/json', @@ -583,7 +583,7 @@ if ($_SESSION["userId"] <> "") { var password = ''; function login(username, password, callback) { - fetch("https://api.obanana.shop/api/v1/login", { + fetch("https:///api/v1/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -660,7 +660,7 @@ if ($_SESSION["userId"] <> "") { function updateCompletedStatus(orderId) { login(email, password, function(token) { // const token = ''; - fetch(`https://api.obanana.shop/api/v1/orders/${orderId}`, { + fetch(`https:///api/v1/orders/${orderId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', diff --git a/user-profile.php b/user-profile.php index 34030cd..8179aa6 100644 --- a/user-profile.php +++ b/user-profile.php @@ -2,7 +2,7 @@ include "functions.php"; -session_start(); + $_SESSION["url"] = $_SERVER['REQUEST_URI']; if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = true; @@ -351,7 +351,7 @@ if ($_SESSION["userId"] <> "") { const phone = document.getElementById('phone-').value; // If no file selected, only update the email - fetch(`https://api.obanana.shop/api/v1/customers/${customerId}`, { + fetch(`https:///api/v1/customers/${customerId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -508,7 +508,7 @@ if ($_SESSION["userId"] <> "") { $('#submitBtn').on('click', function() { // Retrieve existing addresses from the API // fetch('https://api.obanana.shop/api/v1/customers/65482e8d209ff8d348bd30fd') - fetch('https://api.obanana.shop/api/v1/customers/' + customerId) + fetch('https:///api/v1/customers/' + customerId) .then(response => response.json()) .then(data => { // Get the existing addresses array @@ -543,7 +543,7 @@ if ($_SESSION["userId"] <> "") { existingAddresses.push(newAddress); // Make a PATCH request to update the addresses array - return fetch('https://api.obanana.shop/api/v1/customers/' + customerId, { + return fetch('https:///api/v1/customers/' + customerId, { method: 'PATCH', headers: { 'Content-Type': 'application/json' @@ -577,7 +577,7 @@ if ($_SESSION["userId"] <> "") {