source/Application/Model/VariantHandler.php
protected function _applyVariantSelectionsFilter($aSelections, $aFilter)
    {
        $iMaxActiveCount = 0;
        $sMostSuitableVariantId = null;
        $blPerfectFit = false;
        // applying filters, disabling/activating items
        if (($aFilter = $this->_cleanFilter($aFilter))) {
            $aFilterKeys = array_keys($aFilter);
            $iFilterKeysCount = count($aFilter);
            foreach ($aSelections as $sVariantId => &$aLineSelections) {
                $iActive = 0;
                foreach ($aFilter as $iKey => $sVal) {
                    if (strcmp($aLineSelections[$iKey]['hash'], $sVal) === 0) {
                        $aLineSelections[$iKey]['active'] = true;
                        $iActive++;
                    } else {
                        foreach ($aLineSelections as $iOtherKey => &$aLineOtherVariant) {
                            if ($iKey != $iOtherKey) {
                                $aLineOtherVariant['disabled'] = true;
                            }
                        }
                    }
                }
                foreach ($aLineSelections as $iOtherKey => &$aLineOtherVariant) {
                    if (!in_array($iOtherKey, $aFilterKeys)) {
                        $aLineOtherVariant['disabled'] = !($iFilterKeysCount == $iActive);
                    }
                }

                $blFitsAll = $iActive && (count($aLineSelections) == $iActive) && ($iFilterKeysCount == $iActive);
                if (($iActive > $iMaxActiveCount) || (!$blPerfectFit && $blFitsAll)) {
                    $blPerfectFit = $blFitsAll;
                    $sMostSuitableVariantId = $sVariantId;
                    $iMaxActiveCount = $iActive;
                }

                unset($aLineSelections);
            }
        }

        return [$aSelections, $sMostSuitableVariantId, $blPerfectFit];
    }
protected function _applyVariantSelectionsFilter($aSelections, $aFilter)
    {
        $iMaxActiveCount = 0;
        $sMostSuitableVariantId = null;
        $blPerfectFit = false;
        // applying filters, disabling/activating items
        if (($aFilter = $this->_cleanFilter($aFilter))) {
            $aFilterKeys = array_keys($aFilter);
            $iFilterKeysCount = count($aFilter);
            foreach ($aSelections as $sVariantId => &$aLineSelections) {
                $iActive = 0;
                foreach ($aFilter as $iKey => $sVal) {
                    if (strcmp($aLineSelections[$iKey]['hash'], $sVal) === 0) {
                        $aLineSelections[$iKey]['active'] = true;
                        $iActive++;
                    } else {
                        foreach ($aLineSelections as $iOtherKey => &$aLineOtherVariant) {
                            if ($iKey != $iOtherKey) {
                                $aLineOtherVariant['disabled'] = true;
                            }
                        }
                    }
                }
                foreach ($aLineSelections as $iOtherKey => &$aLineOtherVariant) {
                    if (!in_array($iOtherKey, $aFilterKeys)) {
                        $aLineOtherVariant['disabled'] = !($iFilterKeysCount == $iActive);
                    }
                }

                $blFitsAll = $iActive && (count($aLineSelections) == $iActive) && ($iFilterKeysCount == $iActive);
                if (($iActive > $iMaxActiveCount) || (!$blPerfectFit && $blFitsAll)) {
                    $blPerfectFit = $blFitsAll;
                    $sMostSuitableVariantId = $sVariantId;
                    $iMaxActiveCount = $iActive;
                }

                unset($aLineSelections);
            }
        }

        return [$aSelections, $sMostSuitableVariantId, $blPerfectFit];
    }
protected function _applyVariantSelectionsFilter ( $ aSelections , $ aFilter ) { $ iMaxActiveCount = 0 ; $ sMostSuitableVariantId = null ; $ blPerfectFit = false ; // applying filters, disabling/activating items if ( ( $ aFilter = $ this -> _cleanFilter ( $ aFilter ) ) ) { $ aFilterKeys = array_keys ( $ aFilter ) ; $ iFilterKeysCount = count ( $ aFilter ) ; foreach ( $ aSelections as $ sVariantId => & $ aLineSelections ) { $ iActive = 0 ; foreach ( $ aFilter as $ iKey => $ sVal ) { if ( strcmp ( $ aLineSelections [ $ iKey ] [ 'hash' ] , $ sVal ) === 0 ) { $ aLineSelections [ $ iKey ] [ 'active' ] = true ; $ iActive ++ ; } else { foreach ( $ aLineSelections as $ iOtherKey => & $ aLineOtherVariant ) { if ( $ iKey != $ iOtherKey ) { $ aLineOtherVariant [ 'disabled' ] = true ; } } } } foreach ( $ aLineSelections as $ iOtherKey => & $ aLineOtherVariant ) { if ( ! in_array ( $ iOtherKey , $ aFilterKeys ) ) { $ aLineOtherVariant [ 'disabled' ] = ! ( $ iFilterKeysCount == $ iActive ) ; } } $ blFitsAll = $ iActive && ( count ( $ aLineSelections ) == $ iActive ) && ( $ iFilterKeysCount == $ iActive ) ; if ( ( $ iActive > $ iMaxActiveCount ) || ( ! $ blPerfectFit && $ blFitsAll ) ) { $ blPerfectFit = $ blFitsAll ; $ sMostSuitableVariantId = $ sVariantId ; $ iMaxActiveCount = $ iActive ; } unset ( $ aLineSelections ) ; } } return [ $ aSelections , $ sMostSuitableVariantId , $ blPerfectFit ] ; }
Applies filter on variant selection array

@param array $aSelections selections
@param array $aFilter     filter

@return array
Applies filter on variant selection array