diff --git a/htdocs/product/list.php b/htdocs/product/list.php index e1eed666587..9d4dbb3f716 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -126,7 +126,14 @@ $type = GETPOST("type", 'alpha'); // Show/hide child product variants $show_childproducts = 0; if (isModEnabled('variants')) { - $show_childproducts = GETPOST('search_show_childproducts'); + // An HTML checkbox does not submit anything when unchecked, so a hidden + // "search_show_childproducts=0" companion field is emitted next to the + // checkbox (see below). GETPOSTISSET() then lets us distinguish a + // resubmission with the checkbox off from a request that does not carry + // the filter at all, and the value is read as a strict 0/1 flag. + if (GETPOSTISSET('search_show_childproducts')) { + $show_childproducts = GETPOSTINT('search_show_childproducts'); + } } $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id; @@ -383,7 +390,7 @@ if (empty($reshook)) { $search_finished = ''; //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type. - $show_childproducts = ''; + $show_childproducts = 0; $search_import_key = ''; $search_accountancy_code_sell = ''; $search_accountancy_code_sell_intra = ''; @@ -829,7 +836,7 @@ if ($fourn_id > 0) { $param .= "&fourn_id=".urlencode((string) ($fourn_id)); } if ($show_childproducts) { - $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); + $param .= "&search_show_childproducts=".urlencode((string) $show_childproducts); } if ($type != '') { $param .= '&type='.urlencode((string) ($type)); @@ -979,7 +986,11 @@ if (isModEnabled('category') && $user->hasRight('categorie', 'read')) { // Show/hide child variant products if (isModEnabled('variants')) { $moreforfilter .= '
'; - $moreforfilter .= ''; + // Companion hidden field ensures search_show_childproducts is always + // posted, even when the checkbox below is unchecked, so the unchecked + // state survives the filter/pagination submit and is parsed as 0/1. + $moreforfilter .= ''; + $moreforfilter .= ''; $moreforfilter .= ' '; $moreforfilter .= '
'; }