Вывод количества товаров в minishop2
        Уважаемые мастера MODXRevo! Cтолкнулся с проблемой вывода количества товаров в minishop2.
Вывод сделал через сниппет getChildCount
На сайте разместил
    
    
                                                                                
            Вывод сделал через сниппет getChildCount
<?php
$count = 0;
$parent = $modx->getOption('parent', $scriptProperties, 0);
$query = $modx->newQuery('modResource', array('parent' => $parent, 'deleted' => 0, 'published' => 1));
$query->select(array('count'=>'count(id)'));
if ($query->prepare() && $query->stmt->execute()) {
    $res = $query->stmt->fetch(PDO::FETCH_ASSOC);
    $count = $res['count'];
}
return $count;На сайте разместил
Всего [[!getChildCount? &parent=`[[*id]]`]] товаров в категорииКомментарии: 5
                Решили вопрос?
                    <?php
if (empty($parent)) {$parent = $modx->resource->id;}
$pids = array_merge(array($parent), $modx->getChildIds($parent));
$ids = array();
$q = $modx->newQuery('msProduct');
$q->where(array('class_key' => 'msProduct','parent:IN' => $pids,'published' => 1,'deleted' => 0));
$q->select('`msProduct`.`id`');
if ($q->prepare() && $q->stmt->execute()) {
    $ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
$q = $modx->newQuery('msProduct');
$q->leftJoin('msCategoryMember', 'Member', '`Member`.`product_id` = `msProduct`.`id`');
$q->where(array('class_key' => 'msProduct','Member.category_id:IN' => $pids,'published' => 1,'deleted' => 0));
$q->select('`msProduct`.`id`');
if ($q->prepare() && $q->stmt->execute()) {
  $ids2 = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
  if (!empty($ids2)) {
    $ids = array_unique(array_merge($ids, $ids2));
  }
}
return count($ids);
                Можно куда проще сделать.
                    $count = $modx->runSnippet('msProducts', [
    'parents' => $id,
    'returnIds' => true,
    'limit' => 0,
]);
$count = empty($count) ? 0 : count(explode(',', $count));{set $count = 'msProducts' | snippet : [
    'parents' => $id,
    'returnIds' => true,
    'limit' => 0,
]}
{set $count = !$count ? 0 : $count | split | length}
                Забавно, да? Я пишу ответ на твой комментарий. А потом мы пересекаемся через месяц на буяне) Земля круглая.            
                    
                Ну, я всегда это знал )))            
                    
                            Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
                    
             
             
                    
                    
                





