From c4f30aa999b8a1ca53ffa02dc9752dce3233fb72 Mon Sep 17 00:00:00 2001 From: raymart Date: Tue, 26 Mar 2024 16:21:14 +0800 Subject: [PATCH 1/3] add price matrix and function for edit & delete --- admin/header.php | 16 +- admin/product-edit-action.php | 1 + admin/product-edit.php | 122 +++++ admin/vendor-edit-product-action.php | 73 +++ admin/vendor-edit-product.php | 726 +++++++++++++++++++++++++++ admin/vendor-product-search.php | 2 +- 6 files changed, 931 insertions(+), 9 deletions(-) create mode 100644 admin/vendor-edit-product-action.php create mode 100644 admin/vendor-edit-product.php diff --git a/admin/header.php b/admin/header.php index 020fd67..49e0e23 100644 --- a/admin/header.php +++ b/admin/header.php @@ -9,14 +9,14 @@
-
-
- - -
-
+
+
+ + +
+
    diff --git a/admin/product-edit-action.php b/admin/product-edit-action.php index 62baaaf..09f9440 100644 --- a/admin/product-edit-action.php +++ b/admin/product-edit-action.php @@ -65,6 +65,7 @@ $response = editProduct( $color, $material, $size, + $priceMatrix, $token); $array = json_decode($response, true); $_SESSION['prodictId'] = $array['_id']; diff --git a/admin/product-edit.php b/admin/product-edit.php index 81cfeb2..1b25475 100644 --- a/admin/product-edit.php +++ b/admin/product-edit.php @@ -907,6 +907,33 @@ $vendorId = $_SESSION["vendorId"]; )
    + + +
    + + + + + + + + + + + $pair) : ?> + + + + + + + + +
    QuantityPrice (PHP)
    + +
    + +
    @@ -1021,6 +1048,100 @@ $vendorId = $_SESSION["vendorId"]; newquill.on('text-change', function() { document.getElementById('short-hidden-editor').value = newquill.root.innerHTML; }); + + // 3-20-24 raymart added function for price matrix + document.getElementById("add-row").addEventListener("click", function() { + var newRow = '' + + '' + + '' + + '' + + ''; + document.getElementById("price-matrix-body").insertAdjacentHTML('beforeend', newRow); + + var quantityInputs = document.querySelectorAll('.quantity-input'); + var lastIndex = quantityInputs.length - 1; + quantityInputs[lastIndex].addEventListener('blur', function(event) { + checkQuantity(event, lastIndex); + }); + }); + + document.getElementById("price-matrix-body").addEventListener("click", function(event) { + if (event.target.classList.contains("delete-row")) { + event.preventDefault(); + var rows = document.querySelectorAll("#price-matrix-body tr"); + if (rows.length > 1) { + event.target.closest("tr").remove(); + } else { + alert("At least one row is required."); + } + } + }); + + function checkQuantity(event, index) { + var currentInput = event.target; + var previousRow = currentInput.parentNode.parentNode.previousElementSibling; + var nextRow = currentInput.parentNode.parentNode.nextElementSibling; + + if (previousRow !== null) { + var previousQuantityInput = previousRow.querySelector('input[name="quantity[]"]'); + var currentQuantity = parseInt(currentInput.value); + var previousQuantity = parseInt(previousQuantityInput.value); + + if (currentQuantity <= previousQuantity) { + alert("Quantity must be greater than the previous row's quantity."); + currentInput.value = previousQuantity + 1; + } + } + + if (nextRow !== null) { + var nextQuantityInput = nextRow.querySelector('input[name="quantity[]"]'); + var nextQuantity = parseInt(nextQuantityInput.value); + + if (currentQuantity >= nextQuantity) { + alert("Quantity must be less than the next row's quantity."); + currentInput.value = nextQuantity - 1; + } + } + } + + function checkExistingQuantity(row) { + var currentInput = row.querySelector('input[name="quantity[]"]'); + var allRows = document.querySelectorAll("#price-matrix-body tr"); + var currentIndex = Array.from(allRows).indexOf(row); + + for (var i = currentIndex - 1; i >= 0; i--) { + var previousRow = allRows[i]; + var previousQuantityInput = previousRow.querySelector('input[name="quantity[]"]'); + var currentQuantity = parseInt(currentInput.value); + var previousQuantity = parseInt(previousQuantityInput.value); + + if (currentQuantity <= previousQuantity) { + alert("Quantity must be greater than the previous row's quantity."); + currentInput.value = previousQuantity + 1; + return; + } + } + + var nextRow = allRows[currentIndex + 1]; + if (nextRow !== undefined) { + var nextQuantityInput = nextRow.querySelector('input[name="quantity[]"]'); + var nextQuantity = parseInt(nextQuantityInput.value); + + if (currentQuantity >= nextQuantity) { + alert("Quantity must be less than the next row's quantity."); + currentInput.value = nextQuantity - 1; + return; + } + } + } + + document.getElementById("price-matrix-body").addEventListener("blur", function(event) { + if (event.target.tagName === "INPUT" && event.target.name === "quantity[]") { + checkExistingQuantity(event.target.closest("tr")); + } + }, true); + // 3-20-24 raymart added function for price matrix + +
    + + + +
    +
    +
    +
    +
    + + +
    +
    + + +
    +
    +
    +
    + + + +
    +
    + + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + +
    + +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + + + +
    +
    + + +
    +
    +
    + + +
    +
    + + +
    + + +
    + + + + + + + + + + + $pair) : ?> + + + + + + + + +
    QuantityPrice (PHP)
    + +
    + + + +
    + +
    +
    +
    + style="background-color: blue;"> + +
    +
    +
    +
    + style="background-color: blue;"> + +
    +
    +
    +
    + style="background-color: blue;"> + +
    +
    +
    +
    + +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/admin/vendor-product-search.php b/admin/vendor-product-search.php index b39152a..6395c78 100644 --- a/admin/vendor-product-search.php +++ b/admin/vendor-product-search.php @@ -785,7 +785,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"]; console.log("Session Token:", sessionToken); login(email, password, function() { // Removed the call to updateSessionToken - window.open("product-edit.php?id=" + productId, "_self"); + window.open("vendor-edit-product.php?id=" + productId, "_self"); }); } From 2fad9e25fcac8c120adaec96180a31b7b3dfccf1 Mon Sep 17 00:00:00 2001 From: raymart Date: Tue, 26 Mar 2024 16:22:35 +0800 Subject: [PATCH 2/3] search bar for vendor name --- admin/vendor-card.php | 597 +++--------------------------------------- 1 file changed, 37 insertions(+), 560 deletions(-) diff --git a/admin/vendor-card.php b/admin/vendor-card.php index 79fea72..f348835 100644 --- a/admin/vendor-card.php +++ b/admin/vendor-card.php @@ -80,564 +80,12 @@ $products = productList(); + + +
    - - -
    @@ -651,8 +99,16 @@ $products = productList();
    - +
    +
    +
    + + +
    +
    No Vendor Found.

    '; + } // $vendors = vendorList(); for ($x = $start; $x <= $end && $x < $totalVendors; $x++) { $vendor = $vendors[$x]; @@ -684,7 +161,7 @@ $products = productList(); if (isset($vendor['vendor_image']) && !empty($vendor['vendor_image'])) { echo 'Avatar Image '; } else { - echo 'Placeholder Image'; + echo 'Placeholder Image'; } ?>
    @@ -694,15 +171,15 @@ $products = productList();
    • - +
    • - + From 342edfe2a0d74f107c347bf7acbddf39373aff9d Mon Sep 17 00:00:00 2001 From: raymart Date: Tue, 26 Mar 2024 16:24:48 +0800 Subject: [PATCH 3/3] minor changes for catalog and product --- catalog-single-vendor.php | 92 ++++++++++++++++++++++++++------------- product-left-sidebar.php | 6 +-- 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/catalog-single-vendor.php b/catalog-single-vendor.php index b158760..d567c64 100644 --- a/catalog-single-vendor.php +++ b/catalog-single-vendor.php @@ -131,29 +131,6 @@ if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['cate -