diff --git a/admin/product-edit-action.php b/admin/product-edit-action.php
index 7c116e7..62baaaf 100644
--- a/admin/product-edit-action.php
+++ b/admin/product-edit-action.php
@@ -7,6 +7,11 @@ $vendorId = $_SESSION['vendorId'];
$productName = $_POST['product_name'];
//echo '$productName: '.$productName.' ';
$stock = $_POST['stock'];
+// 02-19-2024 Jun Jihad Promo Field Product Upload Vendor Page Action
+$ndd = isset($_POST['promo']['next-day-delivery']) ? $_POST['promo']['next-day-delivery'] : 'No';
+$sdd = isset($_POST['promo']['same-day-delivery']) ? $_POST['promo']['same-day-delivery'] : 'No';
+$freeSf = isset($_POST['promo']['free-shipping']) ? $_POST['promo']['free-shipping'] : 'No';
+// 02-19-2024 Jun Jihad Promo Field Product Upload Vendor Page Action
$minimumOrder = $_POST['minimum_order'];
//echo '$stock: '.$stock.' ';
$price = $_POST['regular_price'];
@@ -40,6 +45,9 @@ $response = editProduct(
$vendorId,
$productName,
$stock,
+ $ndd,
+ $sdd,
+ $freeSf,
$price,
$salePrice,
$weight,
@@ -57,8 +65,7 @@ $response = editProduct(
$color,
$material,
$size,
- $token
-);
+ $token);
$array = json_decode($response, true);
$_SESSION['prodictId'] = $array['_id'];
header("location: vendor-product-grid.php");
diff --git a/admin/product-edit.php b/admin/product-edit.php
index 6968787..4ec941c 100644
--- a/admin/product-edit.php
+++ b/admin/product-edit.php
@@ -672,86 +672,103 @@ $vendorId = $_SESSION["vendorId"];
@@ -890,6 +907,31 @@ $vendorId = $_SESSION["vendorId"];
)
+
+
Stock
@@ -997,105 +1039,134 @@ $vendorId = $_SESSION["vendorId"];
}
}
- function uploadImage() {
+ 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/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'
- });
+ 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);
+ var formData = new FormData();
+ formData.append('image_id', productId);
+ formData.append('category', 'product');
+ formData.append('image', resizedFile);
- fetch('https:///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;
+ fetch('https:///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');
+ };
- const payload = {
- product_image: `https:///images/storage/product_uploads/${filename}`,
- };
+ img.src = e.target.result;
+ };
- console.log('Payload:', payload);
- const token = '';
- return fetch('https:///api/v1/products/' + productId, {
- method: 'PATCH',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + token,
- },
- body: JSON.stringify(payload)
- });
- })
- .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');
- };
+ reader.readAsDataURL(file);
+ });
- img.src = e.target.result;
- };
+ promises.push(promise);
+ }
- reader.readAsDataURL(file);
- }
- }
+ Promise.all(promises)
+ .then(filenames => {
+ const updatedImages = existingImages.concat(filenames.map(filename => `https:///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/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);
+ });
+ }
+ }
diff --git a/admin/update-token-session.php b/admin/update-token-session.php
index 3423690..9162fc5 100644
--- a/admin/update-token-session.php
+++ b/admin/update-token-session.php
@@ -6,7 +6,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($input['token'])) {
// Update the session token
- $_SESSION['token'] = $input['token'];
+ $_SESSION["token"] = $input['token'];
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Token not provided']);
diff --git a/functions.php b/functions.php
index b234e4f..48f1680 100644
--- a/functions.php
+++ b/functions.php
@@ -28,6 +28,38 @@ function simpleProducts($category)
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);
@@ -450,13 +482,12 @@ function vendorExists($email)
return $count;
}
-
-function sendEmail($fName, $lName, $email, $phone, $message)
+function sendEmail_obanana($fName, $lName, $email, $phone, $message)
{
if($_SESSION["is_test"]==true && $_SESSION["test_email_rcpt"]!=""){
- $email = $_SESSION["test_email_rcpt"];
+ $testEmail = $_SESSION["test_email_rcpt"];
}
- $message2 = "
+ $msgto_obanana = "
Greetings from Obanana!
Name: $fName $lName
@@ -465,6 +496,66 @@ function sendEmail($fName, $lName, $email, $phone, $message)
Message: $message
";
+ $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!
+
+ Hi! $fName $lName
+
+ Thank you for contacting us.
+ We will get back to you soon.
+ ";
$data = [
"Messages" => [
[
@@ -480,7 +571,126 @@ function sendEmail($fName, $lName, $email, $phone, $message)
],
"Subject" => "Obanana Contact Us Form",
"TextPart" => "Greetings from Obanana!",
- "HTMLPart" => $message2
+ "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!
+
+ Email: $cstm_email
+ Product Name: $prd_name
+ Product Quantity: $prd_qnty
+
+ Message: $message
+ ";
+ $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_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!
+
+ Hi!
+
+ Thank you for contacting us.
+ We will get back to you soon.
+ ";
+ $data = [
+ "Messages" => [
+ [
+ "From" => [
+ "Email" => "webdev@obanana.com",
+ "Name" => "Obanana B2B"
+ ],
+ "To" => [
+ [
+ // "Email" => $cstm_email,
+ "Email" => "stacyjoycemapano@gmail.com",
+
+ "Name" => "Subscriber"
+ ]
+ ],
+ "Subject" => "Obanana Contact Us Form",
+ "TextPart" => "Greetings from Obanana!",
+ "HTMLPart" => $msgto_inquirer
]
]
];
@@ -1279,6 +1489,9 @@ function editProduct(
$vendorId,
$productName,
$stock,
+ $ndd,
+ $sdd,
+ $freeSf,
$price,
$salePrice,
$weight,
@@ -1315,6 +1528,11 @@ function editProduct(
'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(
diff --git a/same_day_delivery.php b/same_day_delivery.php
index c4efae7..fefb77f 100644
--- a/same_day_delivery.php
+++ b/same_day_delivery.php
@@ -11,7 +11,6 @@ if ($_SESSION["userId"] <> "") {
} else {
$_SESSION["isLoggedIn"] = false;
}
-
?>
@@ -100,79 +99,7 @@ if ($_SESSION["userId"] <> "") {
-