Created
December 10, 2013 10:56
-
-
Save Atorich/7888893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Контактенирует засабмиченную конфигурацию | |
* преобразует в массив, фильтрует все пустые и нулевые значения, | |
* подсчитывает количество совпадений | |
* и возвращает наибольший результат (id выбранного продукта) | |
* | |
* @return int configurable_id | |
*/ | |
public function getConfigurableId() { | |
$configurations = Yii::app()->request->getParam('configurations'); | |
$idString = ""; | |
foreach($configurations as $attr => $ids) { | |
$idString .= $ids; | |
} | |
$idArray = array_filter(explode('/', $idString), function($value) { | |
return intval($value) > 0; | |
}); | |
$idArray = array_count_values($idArray); | |
asort($idArray); | |
$idArray = array_flip($idArray); | |
return array_pop($idArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment