From 2e7af254bdda505f316f86039343a5bca6e4137d Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Mon, 9 Dec 2013 08:26:54 +0100 Subject: [PATCH] Fixed potential foreach warning in Cumulative Filter --- system/modules/isotope/docs/CHANGELOG-2.0.md | 1 + .../Isotope/Module/CumulativeFilter.php | 84 ++++++++++--------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/system/modules/isotope/docs/CHANGELOG-2.0.md b/system/modules/isotope/docs/CHANGELOG-2.0.md index 3db17c8e66..c04f39ea70 100644 --- a/system/modules/isotope/docs/CHANGELOG-2.0.md +++ b/system/modules/isotope/docs/CHANGELOG-2.0.md @@ -14,6 +14,7 @@ Version 2.0.0 (????-??-??) - Calling Product::setActive() when there's no product available - Surcharges were not available in notifications - PSP did not take order to check currency +- Potential foreach warning in Cumulative Filter Version 2.0.rc2 (2013-11-22) diff --git a/system/modules/isotope/library/Isotope/Module/CumulativeFilter.php b/system/modules/isotope/library/Isotope/Module/CumulativeFilter.php index 2229062380..5e4d25e81a 100644 --- a/system/modules/isotope/library/Isotope/Module/CumulativeFilter.php +++ b/system/modules/isotope/library/Isotope/Module/CumulativeFilter.php @@ -104,54 +104,58 @@ protected function generateFilter() $blnShowClear = false; $arrFilters = array(); - foreach ($this->iso_filterFields as $strField) { - $blnTrail = false; - $arrItems = array(); - $arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField); // Use the default routine to initialize options data - - foreach ($arrWidget['options'] as $option) { - $varValue = $option['value']; - - // skip zero values (includeBlankOption) - if ($varValue === '' || $varValue === '-') { - continue; + $this->iso_filterFields = deserialize($this->iso_filterFields); + + if (is_array($this->iso_filterFields) && count($this->iso_filterFields)) { // Can't use empty() because its an object property (using __get) + foreach ($this->iso_filterFields as $strField) { + $blnTrail = false; + $arrItems = array(); + $arrWidget = \Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField], $strField); // Use the default routine to initialize options data + + foreach ($arrWidget['options'] as $option) { + $varValue = $option['value']; + + // skip zero values (includeBlankOption) + if ($varValue === '' || $varValue === '-') { + continue; + } + + $strFilterKey = $strField . '=' . $varValue; + $blnActive = (Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null); + $blnTrail = $blnActive ? true : $blnTrail; + + $arrItems[] = array + ( + 'href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)), + 'class' => ($blnActive ? 'active' : ''), + 'title' => specialchars($option['label']), + 'link' => $option['label'], + ); } - $strFilterKey = $strField . '=' . $varValue; - $blnActive = (Isotope::getRequestCache()->getFilterForModule($strFilterKey, $this->id) !== null); - $blnTrail = $blnActive ? true : $blnTrail; + if (!empty($arrItems) || ($this->iso_iso_filterHideSingle && count($arrItems) < 2)) { + $objClass = RowClass::withKey('class')->addFirstLast(); - $arrItems[] = array - ( - 'href' => \Haste\Util\Url::addQueryString('cumulativefilter=' . base64_encode($this->id . ';' . ($blnActive ? 'del' : 'add') . ';' . $strField . ';' . $varValue)), - 'class' => ($blnActive ? 'active' : ''), - 'title' => specialchars($option['label']), - 'link' => $option['label'], - ); - } + if ($blnTrail) { + $objClass->addCustom('sibling'); + } - if (!empty($arrItems) || ($this->iso_iso_filterHideSingle && count($arrItems) < 2)) { - $objClass = RowClass::withKey('class')->addFirstLast(); + $objClass->applyTo($arrItems); - if ($blnTrail) { - $objClass->addCustom('sibling'); - } + $objTemplate = new \Isotope\Template($this->navigationTpl); - $objClass->applyTo($arrItems); + $objTemplate->level = 'level_2'; + $objTemplate->items = $arrItems; - $objTemplate = new \Isotope\Template($this->navigationTpl); + $arrFilters[$strField] = array + ( + 'label' => $arrWidget['label'], + 'subitems' => $objTemplate->parse(), + 'isActive' => $blnTrail, + ); - $objTemplate->level = 'level_2'; - $objTemplate->items = $arrItems; - - $arrFilters[$strField] = array - ( - 'label' => $arrWidget['label'], - 'subitems' => $objTemplate->parse(), - 'isActive' => $blnTrail, - ); - - $blnShowClear = $blnTrail ? true : $blnShowClear; + $blnShowClear = $blnTrail ? true : $blnShowClear; + } } }