Created
June 3, 2019 06:58
-
-
Save qwertik17/99ddbc0daa719216f5f114090e087b6e to your computer and use it in GitHub Desktop.
change priority resources for modx revo
This file contains hidden or 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
| <?php | |
| $templates = array(13,18,19); | |
| foreach ($templates as $template) { | |
| //Получаем количество товаров с положительным рейтингом | |
| $query = $modx->newQuery('modResource'); | |
| $query->select(array('modResource.id as id','TemplateVarResources.value as value')); | |
| $query->innerJoin('modTemplateVarResource','TemplateVarResources'); | |
| $query->where(array( | |
| 'TemplateVarResources.tmplvarid:=' => '133', | |
| 'template' => $template, | |
| 'TemplateVarResources.value:>' => 0 | |
| )); | |
| $goods_not_null = $modx->getCollection('modResource',$query); | |
| $goods_not_null_count = count($goods_not_null); | |
| //Получаем все товары | |
| $query = $modx->newQuery('modResource'); | |
| $query->select(array('modResource.id as id','TemplateVarResources.value as value')); | |
| $query->innerJoin('modTemplateVarResource','TemplateVarResources'); | |
| $query->where(array( | |
| 'TemplateVarResources.tmplvarid:=' => '133', | |
| 'template' => $template | |
| )); | |
| $goods_all = $modx->getCollection('modResource',$query); | |
| $goods_all_count = count($goods_all); | |
| $percent = $goods_not_null_count / ($goods_all_count / 100); // % соотношение товаров с положительным рейтингом ко всем товарам | |
| if ($percent > 3) { // обновляем товары только если положительный рейтинг есть у достаточного количества товаров | |
| foreach($goods_all as $tovar) { | |
| $value = $tovar->get('value'); | |
| if ($value > 10) { // если приоритет больше 10, то вычитаем значение пропорциальное рейтингу | |
| $pre_value = $value - (round($value * 0.1)); | |
| } else { // если приоритет меньше 10, то вычитаем 1 | |
| $pre_value = $value - 1; | |
| } | |
| // ограничиваем новые значения диапазоном от -50 до 50 | |
| if ($pre_value > 50) $pre_value = 50; | |
| if ($pre_value < -50) $pre_value = -50; | |
| $tovar->setTVvalue('priority', $pre_value); | |
| } | |
| } | |
| } | |
| return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment