Евгений

Евгений

Был в сети 25 ноября 2025, 09:46
Заказы принимаю
создал тв поле migx добавил слова testx testy в tv и в поле контент

<?php
switch ($modx->event->name) {
        case 'OnDocPublished':
        case 'OnBeforeDocFormSave':
        case 'OnDocFormSave':
            if ($resource->get('template') == 24 && !$resource->get('content')) $resource->set('published', 0);
            $res = $modx->getObject('modResource', 11);
            $words = $res->getTVValue('words'); // тут получить слова, распарсить строку, смотря что там вернет.
           
            $content = $resource->get('content');
            $pattern = '/(?:' . join('|', $words) . ')/i';
            $content = preg_replace($pattern, '', $content);
            
            $resource->set('content', $content);
            $resource->save();
        break;
              
}
но увы не подчищает
может разделитель в параметрах вывода TV или чтото в коде не так? как найти причину непонятно
подправил для поле tvFilters
<?php
$filterz = '';
if(isset($_GET['types'])) $filterz = $filterz.'types=='.$_GET['types'].',';
if(isset($_GET['config'])) $filterz = $filterz.'config=='.$_GET['config'].',';
if(isset($_GET['style'])) $filterz = $filterz.'style=='.$_GET['style'].',';
if(isset($_GET['fasad'])) $filterz = $filterz.'fasad=='.$_GET['fasad'].',';

if($filterz !=='') $filterz = substr($filterz,0,-1);

return $filterz;
словил такую ошибку
[pdoTools] Error 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"`TVtypes`.`value` LIKE '1\"' AND  ( `msProduct`.`parent` IN (2,24,5,6,7,8,9,10,' at line 1
пришел к такому решению:
[[!msProducts? &tpl=`tovartplCat` &limit=`64` &parents=`2` &tvFilters=`[[!where]]` &includeTVs=`types,config,style,fasad` ]]
<?php
$filterz = '';
if(isset($_GET['types'])) $filterz['types'] = $_GET['types'];
if(isset($_GET['config'])) $filterz['config'] = $_GET['config'];
if(isset($_GET['style'])) $filterz['style'] = $_GET['style'];
if(isset($_GET['fasad'])) $filterz['fasad'] = $_GET['fasad'];
if($filterz !=='') $filterz = substr($filterz,0,-1);

//if(!empty($filterz)) {$where = json_encode($filterz);} else {$where = '';}

return $filterz;
но чтото не завелось :(
добавил правки под новую
if(isset($_GET['types'])){$filterz[] = 'types=' . $_GET['types'];}
if(isset($_GET['config'])){$filterz[] = 'config=' . $_GET['config'];}
if(isset($_GET['style'])){$filterz[] = 'style=' . $_GET['style'];}
if(isset($_GET['fasad'])){$filterz[] = 'fasad=' . $_GET['fasad'];}
и where

if(isset($filterz)) { $where = $modx->toJSON(array($filterz)); } else { $where = ''; }
if(isset($filterz)) {
        $modx->log(1,print_r($filterz,1));
	$where = $modx->toJSON(array($filterz));
}
в итоге получаю в лог такое
[2022-10-12 06:31:26] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/37.include.cache.php : 28) Array
(
    [0] => types=1
    [1] => config=1
    [2] => style=1
    [3] => fasad=1
)
ну и в результатах фильтрации 0
вот такое при обновлении страницы и потом нажатии чекбоксов в фильтре, что это?
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 7) PHP warning: Undefined array key "types"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 10) PHP warning: Undefined array key "config"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 13) PHP warning: Undefined array key "style"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 16) PHP warning: Undefined array key "fasad"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 23) PHP warning: Undefined array key "sortby"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 28) PHP warning: Undefined array key "sortdir"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 37) PHP warning: Undefined array key "offset"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/components/minishop2/handlers/storage/session/cartsessionhandler.class.php : 15) PHP warning: Undefined array key "minishop2"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/components/minishop2/handlers/storage/session/cartsessionhandler.class.php : 15) PHP warning: Trying to access array offset on value of type null
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/components/minishop2/handlers/storage/session/ordersessionhandler.class.php : 22) PHP warning: Undefined array key "minishop2"
[2022-10-10 09:15:12] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/components/minishop2/handlers/storage/session/ordersessionhandler.class.php : 22) PHP warning: Trying to access array offset on value of type null
[2022-10-10 09:15:34] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 10) PHP warning: Undefined array key "config"
[2022-10-10 09:15:34] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 13) PHP warning: Undefined array key "style"
[2022-10-10 09:15:34] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 16) PHP warning: Undefined array key "fasad"
[2022-10-10 09:15:34] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 37) PHP warning: Undefined array key "offset"
[2022-10-10 09:15:34] (ERROR @ /home/host1834153/maltipuhome.ru/htdocs/www/core/cache/includes/elements/modsnippet/35.include.cache.php : 47) Array
(
    [0] => types=1
)