Skip to content

Instantly share code, notes, and snippets.

@Atorich
Created December 10, 2013 10:56
Show Gist options
  • Save Atorich/7888893 to your computer and use it in GitHub Desktop.
Save Atorich/7888893 to your computer and use it in GitHub Desktop.
/**
* Контактенирует засабмиченную конфигурацию
* преобразует в массив, фильтрует все пустые и нулевые значения,
* подсчитывает количество совпадений
* и возвращает наибольший результат (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