diff --git a/admin/update-token-session.php b/admin/update-token-session.php index 9162fc5..90017b6 100644 --- a/admin/update-token-session.php +++ b/admin/update-token-session.php @@ -1,5 +1,5 @@ "; + // You can add your logic here +} +$minPrice = isset($_POST['minPrice']) ? $_POST['minPrice'] : null; +$maxPrice = isset($_POST['maxPrice']) ? $_POST['maxPrice'] : null; +if(isset($categoryFinal)){ + header("location: shop-list-left-sidebar.php?$categoryFinal&minPrice=$minPrice&maxPrice=$maxPrice"); + +}else{ + +header("location: shop-list-left-sidebar.php?&minPrice=$minPrice&maxPrice=$maxPrice"); + +} +// 02-21-2024 Jun Jihad Search Filter Action diff --git a/shop-list-left-sidebar.php b/shop-list-left-sidebar.php index cc2f1c5..a5b085f 100644 --- a/shop-list-left-sidebar.php +++ b/shop-list-left-sidebar.php @@ -9,12 +9,112 @@ if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = false; } $productSearchResult = $_SESSION["productSearchResult"]; -// var_dump($product); +// 02-19-2024 Jun Jihad Search Filter +$filteredProducts = []; +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $minPrice = ($_POST['minPrice'] !== '' && is_numeric($_POST['minPrice'])) ? floatval($_POST['minPrice']) : null; + $maxPrice = ($_POST['maxPrice'] !== '' && is_numeric($_POST['maxPrice'])) ? floatval($_POST['maxPrice']) : null; + echo "Min Price: " . ($minPrice !== null ? $minPrice : "null") . "
"; + echo "Max Price: " . ($maxPrice !== null ? $maxPrice : "null") . "
"; + if (isset($_POST['category'])) { + $selectedCategories = $_POST['category']; + foreach ($selectedCategories as $selectedCategory) { + $category = strtolower(trim($selectedCategory)); + foreach ($productSearchResult['results'] as $result) { + $productCategory = strtolower(trim($result['product']['product_category'])); + $productPrice = isset($result['product']['sale_price']) ? $result['product']['sale_price'] : $result['product']['regular_price']; -// if (isset($_SESSION["productSearchResult"])) { -// $productSearchResult = $_SESSION["productSearchResult"]; -// var_dump($productSearchResult) + if ($minPrice === null) { + $minPrice = 0; + } + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } + if ( + $productCategory == $category && + ($productPrice >= $minPrice) && + ($productPrice <= $maxPrice) + ) { + $filteredProducts[] = $result; + } + } + } + } else { + // If no category is selected, filter only by price range + foreach ($productSearchResult['results'] as $result) { + $productPrice = isset($result['product']['sale_price']) ? $result['product']['sale_price'] : $result['product']['regular_price']; + if ($minPrice === null) { + $minPrice = 0; + } + + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } + + if (($productPrice >= $minPrice) && + ($productPrice <= $maxPrice) + ) { + $filteredProducts[] = $result; + } + } + } +} +if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['category'])) { + $filteredProducts = []; + $minPrice = isset($_GET['minPrice']) && $_GET['minPrice'] !== '' ? floatval($_GET['minPrice']) : null; + $maxPrice = isset($_GET['maxPrice']) && $_GET['maxPrice'] !== '' ? floatval($_GET['maxPrice']) : null; + + echo "Min Price: " . ($minPrice !== null ? $minPrice : "null") . "
"; + echo "Max Price: " . ($maxPrice !== null ? $maxPrice : "null") . "
"; + + $selectedCategories = isset($_GET['category']) ? $_GET['category'] : []; + + if (!empty($selectedCategories)) { + foreach ($selectedCategories as $selectedCategory) { + $category = strtolower(trim($selectedCategory)); + + foreach ($productSearchResult['results'] as $result) { + $product = $result['product']; + $productCategory = strtolower(trim($product['product_category'])); + $productPrice = isset($product['sale_price']) ? $product['sale_price'] : $product['regular_price']; + if ($minPrice === null) { + $minPrice = 0; + } + + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } + if ( + $productCategory == $category && + ($minPrice === null || $productPrice >= $minPrice) && + ($maxPrice === null || $productPrice <= $maxPrice) + ) { + $filteredProducts[] = $result; + } + } + } + } else { + foreach ($productSearchResult['results'] as $result) { + $product = $result['product']; + $productPrice = isset($product['sale_price']) ? $product['sale_price'] : $product['regular_price']; + if ($minPrice === null) { + $minPrice = 0; + } + + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } + if (($minPrice === null || $productPrice >= $minPrice) && + ($maxPrice === null || $productPrice <= $maxPrice) + ) { + $filteredProducts[] = $result; + } + } + } +} else { + $filteredProducts = $productSearchResult['results']; +} ?> @@ -158,40 +258,22 @@ $productSearchResult = $_SESSION["productSearchResult"]; -
No products found
'; - // } else { - // foreach ($productSearchResult["results"] as $productItem) { - // $product = $productItem["product"]; - // $product_image = !empty($product["product_image"]) ? $product["product_image"] : "https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/No-Image-Placeholder.svg/330px-No-Image-Placeholder.svg.png"; ?>
@@ -208,80 +290,43 @@ $productSearchResult = $_SESSION["productSearchResult"];
- -
"> -
- +
">
- 0) : ?> - Inquire Inquire -
- Showing - of item(s) + Showing - of item(s)
- -
- - -
-
-

Price

-
-
-
-
-
- - - -
-
+