Compare commits

..

No commits in common. "1c40f338e1d53e2f051cd866eedceaa6f2ec9426" and "1e876e09acfe63a449ef36e86c6365ccce23ea8d" have entirely different histories.

7 changed files with 289 additions and 437 deletions

View File

@ -81,7 +81,7 @@ if ($_SESSION["isLoggedIn"] == true and $_SESSION["user_type"] == "admin"){
<?php
}
?>
<form action="../login_action.php" method="post">
<form action="/login_action.php" method="post">
<div class="mb-3 mt-3">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="name">

View File

@ -852,212 +852,168 @@ $products = productList();
</div>
</div>
<script>
function deleteVendor(vendorId){
function deleteVendor(vendorId){
let text = "Please confirm delete action!\nClick OK or Cancel button.";
if (confirm(text) == true) {
window.open("vendor-delete-action.php?id=" + vendorId, "_self");
}
}
function uploadFile(vendorId) {
const originalEmail = document.getElementById('email-' + vendorId).defaultValue;
const updatedEmail = document.getElementById('email-' + vendorId).value;
const isEmailModified = originalEmail !== updatedEmail;
validateEmail(vendorId).then(isEmailAvailable => {
if (!isEmailAvailable) {
// Display an error message and prevent form submission
$('#email-error-message-' + vendorId).text('Email is already in use').show();
} else {
// Proceed with form submission
$('#email-error-message-' + vendorId).text('').hide();
if (isEmailModified) {
validateEmail(vendorId).then(isEmailAvailable => {
if (!isEmailAvailable) {
$('#email-error-message-' + vendorId).text('Email is already in use').show();
} else {
$('#email-error-message-' + vendorId).text('').hide();
// Rest of the code for file upload and API request
var fileInput = document.getElementById('fileInput' + vendorId);
var file = fileInput.files[0];
var fileInput = document.getElementById('fileInput' + vendorId);
var file = fileInput.files[0];
const updatedUser = document.getElementById('user_login-' + vendorId).value;
const firstName = document.getElementById('firstName-' + vendorId).value;
const lastName = document.getElementById('lastName-' + vendorId).value;
const updatedEmail = document.getElementById('email-' + vendorId).value;
const phone = document.getElementById('phone-' + vendorId).value;
const description = document.getElementById('description-' + vendorId).value;
const status = document.getElementById('status-' + vendorId).value;
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
const barangay = document.getElementById('barangay-' + vendorId).value;
const city = document.getElementById('city-' + vendorId).value;
const province = document.getElementById('province-' + vendorId).value;
const country = document.getElementById('country-' + vendorId).value;
const updatedUser = document.getElementById('user_login-' + vendorId).value;
const firstName = document.getElementById('firstName-' + vendorId).value;
const lastName = document.getElementById('lastName-' + vendorId).value;
const phone = document.getElementById('phone-' + vendorId).value;
const description = document.getElementById('description-' + vendorId).value;
const status = document.getElementById('status-' + vendorId).value;
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
const barangay = document.getElementById('barangay-' + vendorId).value;
const city = document.getElementById('city-' + vendorId).value;
const province = document.getElementById('province-' + vendorId).value;
const country = document.getElementById('country-' + vendorId).value;
// Check if a file is selected for upload
if (file) {
var formData = new FormData();
formData.append('image_id', vendorId);
formData.append('category', 'vendor');
formData.append('image', file);
var formData = new FormData();
formData.append('image_id', vendorId);
formData.append('category', 'vendor');
formData.append('image', file); // Include the file data in the form data
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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://<?php echo $_SESSION["data_endpoint"]; ?>/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 = {
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
user_login: updatedUser,
first_name: firstName,
last_name: lastName,
user_email: updatedEmail,
phone: phone,
vendor_description: description,
status: status,
address: [{
address_1: updatedAddress1,
address_2: updatedAddress2,
barangay: barangay,
city: city,
province: province,
country: country,
}]
};
const payload = {
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
user_login: updatedUser,
first_name: firstName,
last_name: lastName,
user_email: updatedEmail,
phone: phone,
vendor_description: description,
status: status,
address: [{
address_1: updatedAddress1,
address_2: updatedAddress2,
barangay: barangay,
city: city,
province: province,
country: country,
}]
};
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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);
});
}
});
}else {
$('#email-error-message-' + vendorId).text('').hide();
const updatedUser = document.getElementById('user_login-' + vendorId).value;
const firstName = document.getElementById('firstName-' + vendorId).value;
const lastName = document.getElementById('lastName-' + vendorId).value;
const updatedEmail = document.getElementById('email-' + vendorId).value;
const phone = document.getElementById('phone-' + vendorId).value;
const description = document.getElementById('description-' + vendorId).value;
const status = document.getElementById('status-' + vendorId).value;
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
const barangay = document.getElementById('barangay-' + vendorId).value;
const city = document.getElementById('city-' + vendorId).value;
const province = document.getElementById('province-' + vendorId).value;
const country = document.getElementById('country-' + vendorId).value;
var fileInput = document.getElementById('fileInput' + vendorId);
var file = fileInput.files[0];
var formData = new FormData();
formData.append('image_id', vendorId);
formData.append('category', 'vendor');
formData.append('image', file);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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 = {
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
user_login: updatedUser,
first_name: firstName,
last_name: lastName,
user_email: updatedEmail,
phone: phone,
vendor_description: description,
status: status,
address: [{
address_1: updatedAddress1,
address_2: updatedAddress2,
barangay: barangay,
city: city,
province: province,
country: country,
}]
};
// Make API request using the extracted filename
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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);
});
}
}
function validateEmail(vendorId) {
var emailInput = document.getElementById('email-' + vendorId);
var email = emailInput.value;
if (email.trim() !== '') {
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/search?q=' + email)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Failed to check email availability');
}
})
.then(data => {
const isEmailAvailable = parseInt(data.results.length) === 0;
$('#email-error-message-' + vendorId).text(isEmailAvailable ? '' : 'Email is already in use').show();
return isEmailAvailable;
})
.catch(error => {
console.error('Error during email validation:', error);
return false;
});
} else {
$('#email-error-message-' + vendorId).text('').hide();
return Promise.resolve(true);
}
}
// Make another API request using the extracted filename
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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);
});
} else {
// If no file selected, only update the email
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
user_login: updatedUser,
first_name: firstName,
last_name: lastName,
user_email: updatedEmail,
vendor_description: description,
status: status,
phone: phone,
address: [{
address_1: updatedAddress1,
address_2: updatedAddress2,
barangay: barangay,
city: city,
province: province,
country: country,
}]
})
})
.then(response => {
if (response.ok) {
console.log('Email update successful');
location.reload();
} else {
console.error('Email update failed');
}
})
.catch(error => {
console.error('Error during fetch:', error);
});
}
}
});
}
function validateEmail(vendorId) {
var emailInput = document.getElementById('email-' + vendorId);
var email = emailInput.value;
if (email.trim() !== '') {
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/search?q=' + email)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Failed to check email availability');
}
})
.then(data => {
const isEmailAvailable = parseInt(data.results.length) === 0;
$('#email-error-message-' + vendorId).text(isEmailAvailable ? '' : 'Email is already in use').show();
return isEmailAvailable;
})
.catch(error => {
console.error('Error during email validation:', error);
return false;
});
} else {
$('#email-error-message-' + vendorId).text('').hide();
return Promise.resolve(true);
}
}
</script>
<!-- <script>

View File

@ -35085,7 +35085,7 @@ input[type=email]:focus::-webkit-input-placeholder {
.ec-vendor-profile-card .ec-vendor-block-profile .ec-vendor-block-img .ec-vendor-block-bg {
width: 100%;
height: 200px;
background-image:none;
background-image: url(../images/banner/7.jpg);
background-size: cover;
background-position: center;
background-repeat: no-repeat;

View File

@ -1384,23 +1384,17 @@ function getOrderbyVendorId($id)
return $response;
}
function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $courierName, $paymentStatus, $paymentReference, $token)
function editOrderStatus($orderId, $status, $currentStatus, $trackingNumber, $courierName, $token)
{
$curl = curl_init();
$data = array(
'status' => $status
);
if ($currentStatus == "TO SHIP" || $currentStatus == "To Ship") {
if ($currentStatus == "TO SHIP" || $currentStatus == "T Ship") {
// $data['tracking_number'] = $trackingNumber;
$data['tracking_number'] = $trackingNumber;
$data['courier_name'] = $courierName;
}
if ($currentStatus == "TO RECEIVE" || $currentStatus == "To Receive") {
// $data['tracking_number'] = $trackingNumber;
$data['payment']['status'] = $paymentStatus;
$data['payment']['reference_number'] = $paymentReference;
}
$params3 = json_encode($data);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$_SESSION["data_endpoint"]."/api/v1/orders/" . $orderId,

View File

@ -5,19 +5,15 @@ $orderId = $_SESSION['vendorOrderId'];
$currentStatus = $_POST['order_status'];
$trackingNumber = $_POST['tracking_number'];
$courirerName = $_POST['courier_name'];
$paymentReference = $_POST['payment_reference'];
$token = $_SESSION['token'];
// $status = "TO SHIP";
if ($currentStatus === 'TO PAY' || $currentStatus === 'To Pay') {
$status = 'TO SHIP';
$paymentStatus = 'UNPAID';
} elseif ($currentStatus === 'TO SHIP' || $currentStatus === 'To Ship') {
$status = 'TO RECEIVE';
$paymentStatus = 'UNPAID';
} elseif ($currentStatus === 'TO RECEIVE' || $currentStatus === 'To Receive') {
$status = 'COMPLETED';
$paymentStatus = 'PAID';
}
$response = editOrderStatus(
@ -26,8 +22,6 @@ $response = editOrderStatus(
$currentStatus,
$trackingNumber,
$courirerName,
$paymentStatus,
$paymentReference,
$token
);
$array = json_decode($response,true);

View File

@ -199,10 +199,6 @@ $array = json_decode($result, true);
<label for="inputEmail4" class="form-label">Payment Status</label>
<input type="text" class="form-control slug-title" value="<?php echo $array['payment']['status'] ?>" readonly>
</div>
<div class="col-md-6" style="display:none;">
<label for="inputEmail4" class="form-label">Payment Reference</label>
<input type="text" name="payment_reference" class="form-control slug-title" value="<?php echo htmlspecialchars($array['payment']['reference_number']); ?>">
</div>
<div class="col-md-6">
<label for="inputEmail4" class="form-label">Status</label>
<input type="text" class="form-control slug-title" name="order_status" value="<?php echo $array['status'] ?>" readonly>

View File

@ -137,20 +137,14 @@ if ($_SESSION["userId"] <> "") {
<div class="ec-vendor-dashboard-card ec-vendor-setting-card">
<div class="ec-vendor-card-body">
<?php
// var_dump($vendor);
?>
<div class="row">
<div class="col-md-12">
<div class="ec-vendor-block-profile">
<!-- 02-23-2023 Jun Jihad Vendor Header Paceholder -->
<div class="ec-vendor-block-img space-bottom-30 ">
<?php
if (!isset($vendorData['vendor_banner']) || empty($vendorData['vendor_banner'])) {
$banner_style = 'background-color: orange !important; background-image: none !important; width: 100% !important; height: 200px !important; background-size: cover !important; background-position: center !important; border-radius: 5px !important;';
} else {
$banner_style = 'background-image: url(' . $vendorData['vendor_banner'] . ') !important; width: 100% !important; height: 200px !important; background-size: cover !important; background-position: center !important; background-repeat: no-repeat !important; background-blend-mode: overlay !important; background-color: rgba(0, 0, 0, 0.6) !important; border-radius: 5px !important;';
}
?>
<div class="ec-vendor-block-bg" style="<?php echo $banner_style; ?>">
<div class="ec-vendor-block-bg profBg" style="background-color:orange; background-image: url(<?php echo $vendorData['vendor_banner'] ?>) !important;" id="myElement">
<a href="#" class="btn btn-lg btn-primary" data-link-action="editmodal" title="Edit Detail" data-bs-toggle="modal" data-bs-target="#edit_modal">Edit Detail</a>
</div>
@ -163,17 +157,10 @@ if ($_SESSION["userId"] <> "") {
<h5 class="name"><?php echo $vendorData['user_login'] ?></h5>
</div>
</div>
<!-- 02-23-2023 Jun Jihad Vendor Header Paceholder -->
<!-- 02-23-2023 Jun Jihad Vendor Description -->
<div class="ec-vendor-block-about space-bottom-30">
<h5>About Us</h5>
<?php if (!empty($vendorData['vendor_description'])): ?>
<p><?php echo $vendorData['vendor_description']; ?></p>
<?php else: ?>
<p>No description available.</p>
<?php endif; ?>
<p><?php echo $vendorData["vendor_description"] ?></p>
</div>
<!-- 02-23-2023 Jun Jihad Vendor Description -->
<h5>Account Information</h5>
<div class="row">
@ -181,7 +168,7 @@ if ($_SESSION["userId"] <> "") {
<div class="ec-vendor-detail-block ec-vendor-block-email space-bottom-30">
<h6>E-mail address </h6>
<ul>
<li style="padding:3%"><strong><?php echo $vendorData["user_email"] ?></strong></li>
<li><strong><?php echo $vendorData["user_email"] ?></strong></li>
</ul>
</div>
</div>
@ -189,7 +176,7 @@ if ($_SESSION["userId"] <> "") {
<div class="ec-vendor-detail-block ec-vendor-block-contact space-bottom-30">
<h6>Contact nubmer</h6>
<ul>
<li style="padding:3%"><strong><?php echo $vendorData["phone"] ?></strong></li>
<li><strong><?php echo $vendorData["phone"] ?></strong></li>
</ul>
</div>
</div>
@ -352,7 +339,6 @@ if ($_SESSION["userId"] <> "") {
const firstName = document.getElementById('cfirstname-').value;
const lastName = document.getElementById('clastname-').value;
const phone = document.getElementById('cphone-').value;
const description = document.getElementById('cdescription-').value;
// If no file selected, only update the email
fetch(`https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/${vendorid}`, {
@ -365,7 +351,6 @@ if ($_SESSION["userId"] <> "") {
first_name: firstName,
last_name: lastName,
phone: phone,
vendor_description:description
})
})
.then(response => {
@ -388,22 +373,24 @@ if ($_SESSION["userId"] <> "") {
<script>
const vendorid = `<?php echo $_SESSION["LoggedInVendorId"]; ?>`;
document.addEventListener('DOMContentLoaded', function() {
const provinceSelect = $('#provinceSelect');
const citySelect = $('#citySelect');
const barangaySelect = $('#barangaySelect');
// Get the select elements
const provinceSelect = $('#provinceSelect'); // Use jQuery to select the element
const citySelect = $('#citySelect'); // Use jQuery to select the element
const barangaySelect = $('#barangaySelect'); // Use jQuery to select the element
// Initialize Select2 on the provinceSelect, citySelect, and barangaySelect elements
provinceSelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high'
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
citySelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high'
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
barangaySelect.select2({
dropdownParent: $('#secondModal'),
containerCssClass: 'select2-zindex-high'
containerCssClass: 'select2-zindex-high' // Optional, add a custom class for styling
});
// Fetch provinces data
@ -417,19 +404,23 @@ if ($_SESSION["userId"] <> "") {
}
})
.then(provincesData => {
// Iterate through the provinces data and add options
provincesData.forEach(province => {
const option = new Option(province.name, province.code);
provinceSelect.append(option);
});
// Add an extra option manually
const extraOption = new Option('Metro Manila', '130000000');
provinceSelect.append(extraOption);
// Add event listener to provinceSelect
provinceSelect.on('change', function() {
// Clear existing options in citySelect and barangaySelect
citySelect.html('<option value="" disabled selected hidden>Select City</option>');
barangaySelect.html('<option value="" disabled selected hidden>Select Barangay</option>');
// Fetch and update cities/municipalities based on the selected province
updateCities();
});
})
@ -437,11 +428,13 @@ if ($_SESSION["userId"] <> "") {
console.error('Error:', error);
});
// Function to update city/municipality options based on the selected province
function updateCities() {
const selectedProvinceCode = provinceSelect.val();
const selectedProvinceCode = provinceSelect.val(); // Use val() to get the selected value with Select2
if (selectedProvinceCode) {
let citiesEndpoint;
if (selectedProvinceCode === '130000000') {
// Check if Metro Manila is selected
citiesEndpoint = 'https://psgc.gitlab.io/api/regions/130000000/cities-municipalities/';
} else {
citiesEndpoint = `https://psgc.gitlab.io/api/provinces/${selectedProvinceCode}/cities-municipalities/`;
@ -457,6 +450,7 @@ if ($_SESSION["userId"] <> "") {
}
})
.then(citiesData => {
// Iterate through the cities data and add options
citiesData.forEach(city => {
const option = new Option(city.name, city.code);
citySelect.append(option);
@ -467,9 +461,13 @@ if ($_SESSION["userId"] <> "") {
});
}
}
// Add event listener to citySelect
citySelect.on('change', function() {
// Clear existing options in barangaySelect
barangaySelect.html('<option value="" disabled selected hidden>Select Barangay</option>');
// Fetch and update barangays based on the selected city/municipality
const selectedCityCode = citySelect.val();
if (selectedCityCode) {
fetch(`https://psgc.gitlab.io/api/cities-municipalities/${selectedCityCode}/barangays/`)
@ -482,6 +480,7 @@ if ($_SESSION["userId"] <> "") {
}
})
.then(barangaysData => {
// Iterate through the barangays data and add options
barangaysData.forEach(barangay => {
const option = new Option(barangay.name, barangay.code);
barangaySelect.append(option);
@ -496,11 +495,14 @@ if ($_SESSION["userId"] <> "") {
$('#submitBtn').on('click', function() {
// Retrieve existing addresses from the API
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid)
.then(response => response.json())
.then(data => {
// Get the existing addresses array
const existingAddresses = data.address || [];
// Get the new address details
const firstName = $('#addressFirstName').val();
const lastName = $('#addressLastName').val();
const contact = $('#addressContact').val();
@ -512,6 +514,7 @@ if ($_SESSION["userId"] <> "") {
const country = $('#addressCountry').val();
// Create a new address object
const newAddress = {
first_name: firstName,
last_name: lastName,
@ -524,8 +527,10 @@ if ($_SESSION["userId"] <> "") {
country: country,
};
// Add the new address to the existing addresses
existingAddresses.push(newAddress);
// Make a PATCH request to update the addresses array
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
@ -538,13 +543,16 @@ if ($_SESSION["userId"] <> "") {
})
.then(response => {
if (response.ok) {
// Handle success (e.g., show a success message)
location.reload();
} else {
// Handle error
console.error('Failed to submit data');
alert('Failed to submit data');
}
})
.catch(error => {
// Handle network or other errors
console.error('Error:', error);
alert('Error submitting data');
});
@ -702,18 +710,11 @@ if ($_SESSION["userId"] <> "") {
<label><i class="fi-rr-edit"></i></label>
</div>
<div class="thumb-preview ec-preview">
<div class="image-thumb-preview">
<?php
if (!isset($vendorData['vendor_banner']) || empty($vendorData['vendor_banner'])) {
$banner_style2 = 'background-color: orange !important; background-image: none !important; width: 100% !important; height: 200px !important; background-size: cover !important; background-position: center !important; border-radius: 5px !important;';
echo '<div class="image-thumb-preview ec-image-preview v-img" style="' . $banner_style2 . '"></div>';
} else {
echo '<img class="image-thumb-preview ec-image-preview v-img" src="' . $vendorData['vendor_banner'] . '" alt="edit" />';
}
?>
<div class="image-thumb-preview">
<img class="image-thumb-preview ec-image-preview v-img" src=<?php echo $vendorData['vendor_banner'] ?> alt="edit" />
</div>
</div>
</div>
</div>
</div>
<div class="ec-vendor-block-detail">
<div class="thumb-upload">
@ -722,201 +723,118 @@ if ($_SESSION["userId"] <> "") {
<label><i class="fi-rr-edit"></i></label>
</div>
<div class="thumb-preview ec-preview">
<div class="image-thumb-preview">
<?php if (!empty($vendorData['vendor_image'])): ?>
<img class="image-thumb-preview ec-image-preview v-img" src="<?php echo $vendorData['vendor_image']; ?>" alt="edit" />
<?php else: ?>
<img class="image-thumb-preview ec-image-preview v-img" src="https://yourteachingmentor.com/wp-content/uploads/2020/12/istockphoto-1223671392-612x612-1.jpg" alt="edit" />
<?php endif; ?>
</div>
<div class="image-thumb-preview">
<img class="image-thumb-preview ec-image-preview v-img" src=<?php echo $vendorData['vendor_image'] ?> alt="edit" />
</div>
</div>
</div>
</div>
<script>
function uploadVendorProfileImage() {
var vendorid = '<?php echo $_SESSION["LoggedInVendorId"] ?>';
var file = document.getElementById('imageUpload').files[0];
if (file) {
const reader = new FileReader();
function uploadVendorProfileImage() {
var vendorid = '<?php echo $_SESSION["LoggedInVendorId"] ?>';
var file = document.getElementById('imageUpload').files[0];
if (file) {
var formData = new FormData();
formData.append('image_id', vendorid);
formData.append('category', 'vendor');
formData.append('image', file);
reader.onload = function(event) {
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;
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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;
if (img.width > maxWidth) {
newWidth = maxWidth;
newHeight = newWidth / aspectRatio;
}
const payload = {
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
if (newHeight > maxHeight) {
newHeight = maxHeight;
newWidth = newHeight * aspectRatio;
}
};
canvas.width = newWidth;
canvas.height = newHeight;
ctx.drawImage(img, 0, 0, newWidth, newHeight);
console.log('Payload:', payload);
canvas.toBlob((blob) => {
const resizedFile = new File([blob], file.name, {
type: 'image/jpeg'
});
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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);
});
}
}
var formData = new FormData();
formData.append('image_id', vendorid);
formData.append('category', 'vendor');
formData.append('image', resizedFile);
function uploadProfileBanner() {
var vendorid = '<?php echo $_SESSION["LoggedInVendorId"] ?>';
var file = document.getElementById('thumbUpload01').files[0];
if (file) {
var formData = new FormData();
formData.append('image_id', vendorid + '_banner');
formData.append('category', 'vendor');
formData.append('image', file);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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 = encodeURI(result.filename);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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 = {
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
};
const payload = {
vendor_banner: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
console.log('Payload:', payload);
};
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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');
};
img.src = event.target.result;
};
reader.readAsDataURL(file);
}
}
function uploadProfileBanner() {
var vendorid = '<?php echo $_SESSION["LoggedInVendorId"] ?>';
var file = document.getElementById('thumbUpload01').files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
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 (img.width > maxWidth) {
newWidth = maxWidth;
newHeight = newWidth / aspectRatio;
}
if (newHeight > maxHeight) {
newHeight = maxHeight;
newWidth = newHeight * aspectRatio;
}
canvas.width = newWidth;
canvas.height = newHeight;
ctx.drawImage(img, 0, 0, newWidth, newHeight);
canvas.toBlob((blob) => {
const resizedFile = new File([blob], file.name, {
type: 'image/jpeg'
});
var formData = new FormData();
formData.append('image_id', vendorid + '_banner');
formData.append('category', 'vendor');
formData.append('image', resizedFile);
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/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 = encodeURI(result.filename);
// const filename = result.filename;
const payload = {
vendor_banner: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
};
console.log('Payload:', payload);
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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');
};
img.src = event.target.result;
};
reader.readAsDataURL(file);
}
}
console.log('Payload:', payload);
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
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);
});
}
}
</script>
<div class="ec-vendor-upload-detail">
<form class="row g-3">
@ -940,12 +858,6 @@ function uploadProfileBanner() {
<label for="cphone-" class="text-dark font-weight-medium pt-3 mb-2">Contact Number</label>
<input type="text" class="form-control" id="cphone-" value="<?php echo $vendorData['phone'] ?>">
</div>
<!-- 02-23-2023 Jun Jihad Vendor Description Field-->
<div class="form-group">
<label for="cdescription-" class="text-dark font-weight-medium pt-3 mb-2">Vendor Description</label>
<textarea class="form-control" id="cdescription-"><?php echo $vendorData['vendor_description']; ?></textarea>
</div>
<!-- 02-23-2023 Jun Jihad Vendor Description Field-->
<!-- <div class="col-md-12 space-t-15">
<button type="submit" class="btn btn-primary">Update</button>