Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some minor changes to Module #4

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions 1_Installation_files/includes/modules/product_finder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* Product Finder module
* includes/modules/product_finder.php
Expand All @@ -9,7 +11,7 @@
$pf_category_depth = (int)PRODUCT_FINDER_CATEGORY_DEPTH; //USER defined category depth
//Note that most of this convoluted POST and GET coding is purely to allow PF to work without javascript...and then behave logically when the dropdowns are changed in various non-logical orders
//noscript
$js_disabled = ($_POST['js_disabled'] == 'true' ? true : false);
$js_disabled = (isset($_POST['js_disabled']) && $_POST['js_disabled'] === 'true');
if (isset($_GET['pf_dd1_prev'])) {//this page load is a result of a complete PF selection and so was a redirect with GET parameters, and should be in a category
$prev_dd1 = (int)$_GET['pf_dd1_prev'];
$prev_dd2 = (int)$_GET['pf_dd2_prev'];
Expand All @@ -25,22 +27,24 @@
$post_dd2 = !empty($_POST['pf_dd2']) ? (int)$_POST['pf_dd2'] : -1;
$post_dd3 = !empty($_POST['pf_dd3']) ? (int)$_POST['pf_dd3'] : -1;

if ($js_disabled && ($post_dd1 == $prev_dd1 && $post_dd2 == $prev_dd2 && $post_dd3 > 0)) {//noscript, a complete NEW selection has been made, so go to that category
if ($js_disabled && empty($_GET['pf_ns']) && ($post_dd1 === $prev_dd1) && ($post_dd2 === $prev_dd2) && ($post_dd3 > 0)) {//noscript, a complete NEW selection has been made, so go to that category
$cp = $pf_base_category . '_' . $post_dd1 . '_' . $post_dd2 . '_' . $post_dd3; //destination category
$link = zen_href_link(FILENAME_DEFAULT,
'cPath=' . $cp . '&pf_dd1_prev=' . $post_dd1 . '&pf_dd2_prev=' . $post_dd2 . '&pf_dd3_prev=' . $post_dd3 . '&pf_ns=1'); // pf_dd1/2/3_prev: used to populate dropdowns with the selected category data
zen_redirect($link);
} elseif (($post_dd1 != $prev_dd1) && ($post_dd1 > 0) && ($post_dd3 == $prev_dd3)) {//noscript, only dd1 has changed: reload the existing page but reset dd2 and dd3
$link = zen_href_link(FILENAME_DEFAULT, 'cPath=' . $cp . '&pf_dd1_prev=' . $post_dd1 . '&pf_dd2_prev=' . $post_dd2 . '&pf_dd3_prev=' . $post_dd3 . '&pf_ns=1');
zen_redirect($link); //final parameter is the post value to know what was completely selected
} elseif (($post_dd1 !== $prev_dd1) && ($post_dd1 > 0) && ($post_dd3 === $prev_dd3)) {//noscript, only dd1 has changed: reload the existing page but reset dd2 and dd3
$post_dd2 = -1;
$post_dd3 = -1;
} elseif (($post_dd2 != $prev_dd2) && ($post_dd2 > 0) && ($post_dd3 == $prev_dd3)) {//noscript, only dd2 has changed: reload the existing page but reset dd3
} elseif (($post_dd2 !== $prev_dd2) && ($post_dd2 > 0) && ($post_dd3 === $prev_dd3)) {//noscript, only dd2 has changed: reload the existing page but reset dd3
$post_dd3 = -1;
}

$pid = false;
//get current page location if in a category
if (isset($cPath) && $cPath != '') {//$cPath is only set on a category/product page
if (isset($cPath) && $cPath !== '') {//$cPath is only set on a category/product page
$pf_cPaths = explode('_', $cPath);
if ($pf_cPaths[0] != $pf_base_category) {
if (!empty($_GET['products_id'])) {
$pid = (int)$_GET['products_id'];
}
if ((int)$pf_cPaths[0] !== $pf_base_category) {
$pf_cPaths = '';
}
} else {
Expand Down Expand Up @@ -71,21 +75,20 @@
} else {
$pf_dd3_selected = -1;
}

//prepopulate dropdowns when arriving at a product/category page inside the Product Finder parent category
$pf_dd1_array = pf_get_subcategories($pf_base_category); //build the array for dropdown1
$pf_dd2_array = pf_get_subcategories($pf_dd1_selected); //build the array for dropdown2
$pf_dd3_array = pf_get_subcategories($pf_dd2_selected); //build the array for dropdown3

$cp = isset($cPath) && $cPath != '' ? 'cPath=' . $cPath : ''; //if on a category page, stay there until a complete new selection made (redirect). If on another page, stay there too!
echo zen_draw_form('productFinderform', zen_href_link($_GET['main_page'], $cp), 'post', 'id="productFinderform"'); //this action is overridden when JS in use
$cp = isset($cPath) && $cPath !== '' ? 'cPath=' . $cPath : ''; //if on a category page, stay there until a complete new selection made (redirect). If on another page, stay there too!
echo zen_draw_form('productFinderform', zen_href_link($_GET['main_page'], $cp . ($pid ? '&products_id=' . $pid : '')), 'post', 'id="productFinderform"'); //this action is overridden when JS in use
//pass current states so code can determine what has changed on each submit and act according, or not.
echo zen_draw_hidden_field('pf_dd1_prev', $pf_dd1_selected);
echo zen_draw_hidden_field('pf_dd2_prev', $pf_dd2_selected);
echo zen_draw_hidden_field('pf_dd3_prev', $pf_dd3_selected);
?>
<!--bof product finder -->
<div id="productFinder"
<div id="productFinder">
<noscript>
<?php echo zen_draw_hidden_field('js_disabled', 'true'); ?>
</noscript>
Expand Down Expand Up @@ -123,5 +126,5 @@
</ul>
<?php echo '</form>'; ?>
</div>
<!--bof product finder -->
<!--eof product finder -->