diff --git a/shop-list-left-sidebar-action.php b/shop-list-left-sidebar-action.php new file mode 100644 index 0000000..88b8ccb --- /dev/null +++ b/shop-list-left-sidebar-action.php @@ -0,0 +1,26 @@ +"; + // 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 069745e..a5b085f 100644 --- a/shop-list-left-sidebar.php +++ b/shop-list-left-sidebar.php @@ -9,20 +9,13 @@ if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = false; } $productSearchResult = $_SESSION["productSearchResult"]; - -// Filter products based on selected categories -// $category = strtolower(trim($_GET['category'])); - +// 02-19-2024 Jun Jihad Search Filter $filteredProducts = []; - -// Check if the form is submitted and categories are selected 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") . "
"; - - // Check if categories are selected if (isset($_POST['category'])) { $selectedCategories = $_POST['category']; foreach ($selectedCategories as $selectedCategory) { @@ -31,17 +24,12 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $productCategory = strtolower(trim($result['product']['product_category'])); $productPrice = isset($result['product']['sale_price']) ? $result['product']['sale_price'] : $result['product']['regular_price']; - // Set minPrice to 0 if it's null if ($minPrice === null) { $minPrice = 0; } - - // Set maxPrice to a very high value if it's null if ($maxPrice === null) { $maxPrice = PHP_FLOAT_MAX; } - - // Check if the product matches the selected category and falls within the price range if ( $productCategory == $category && ($productPrice >= $minPrice) && @@ -56,12 +44,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { foreach ($productSearchResult['results'] as $result) { $productPrice = isset($result['product']['sale_price']) ? $result['product']['sale_price'] : $result['product']['regular_price']; - // Set minPrice to 0 if it's null if ($minPrice === null) { $minPrice = 0; } - // Set maxPrice to a very high value if it's null if ($maxPrice === null) { $maxPrice = PHP_FLOAT_MAX; } @@ -73,71 +59,62 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { } } } -} // If the request method is GET and filter parameters are present in the URL -// If the request method is GET and filter parameters are present in the URL +} if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['category'])) { - // Initialize the filtered products array $filteredProducts = []; + $minPrice = isset($_GET['minPrice']) && $_GET['minPrice'] !== '' ? floatval($_GET['minPrice']) : null; + $maxPrice = isset($_GET['maxPrice']) && $_GET['maxPrice'] !== '' ? floatval($_GET['maxPrice']) : null; - // Get minPrice and maxPrice from the URL - $minPrice = isset($_GET['minPrice']) ? floatval($_GET['minPrice']) : null; - $maxPrice = isset($_GET['maxPrice']) ? floatval($_GET['maxPrice']) : null; + echo "Min Price: " . ($minPrice !== null ? $minPrice : "null") . "
"; + echo "Max Price: " . ($maxPrice !== null ? $maxPrice : "null") . "
"; - // Set default values for minPrice and maxPrice if they are null - if ($minPrice === null) { - $minPrice = 0; - } - - if ($maxPrice === null) { - $maxPrice = PHP_FLOAT_MAX; - } - - // Get selected categories $selectedCategories = isset($_GET['category']) ? $_GET['category'] : []; - // Check if categories are selected if (!empty($selectedCategories)) { - // Loop through each selected category foreach ($selectedCategories as $selectedCategory) { $category = strtolower(trim($selectedCategory)); - // Loop through each product in the search result 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; + } - // Check if the product matches the selected category and falls within the price range + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } if ( $productCategory == $category && - ($productPrice >= $minPrice) && - ($productPrice <= $maxPrice) + ($minPrice === null || $productPrice >= $minPrice) && + ($maxPrice === null || $productPrice <= $maxPrice) ) { $filteredProducts[] = $result; } } } } else { - // If no category is selected, filter only by price range foreach ($productSearchResult['results'] as $result) { $product = $result['product']; $productPrice = isset($product['sale_price']) ? $product['sale_price'] : $product['regular_price']; + if ($minPrice === null) { + $minPrice = 0; + } - // Check if the product falls within the price range - if (($productPrice >= $minPrice) && - ($productPrice <= $maxPrice) + if ($maxPrice === null) { + $maxPrice = PHP_FLOAT_MAX; + } + if (($minPrice === null || $productPrice >= $minPrice) && + ($maxPrice === null || $productPrice <= $maxPrice) ) { $filteredProducts[] = $result; } } } } else { - // If no filter parameters are present, display all products $filteredProducts = $productSearchResult['results']; } - - - ?> @@ -281,7 +258,6 @@ if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['cate -
@@ -342,22 +318,15 @@ if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['cate
-
$_POST['category'], 'minPrice' => $_POST['minPrice'], 'maxPrice' => $_POST['maxPrice']))); ?>"> + + + + +
+ -
  • @@ -472,12 +496,11 @@ if (!empty($_GET['minPrice']) || !empty($_GET['maxPrice']) || !empty($_GET['cate
  • - - + -->
    - +