M
M
medvedgoff2021-03-05 14:50:13
MODX
medvedgoff, 2021-03-05 14:50:13

Counting the number of only those resources that are shown in the menu?

Online store, products that are in stock are resources that are shown in the menu hidemenu 0; You need to count the number of products in the category that are in stock.

The standard pdomenu solution to display all child resources is not suitable, it considers all resources that hidemenu 0 and 1.

Вывод двух уровней ресурсов с подсчетом количества вложенных:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lunegov, 2021-03-06
@medvedgoff

You have to use your own snippet.
To do this, move the category output code to a separate chunk:


Chunk svoeImyaChanka :
<li ><a href="" ></a> ()</li>

Snippet childrenCounter :
<?php
/**
 * childrenCounter
 *
 * DESCRIPTION
 *
 * Сниппет выводит количество дочерних ресурсов для ресурса с указанным id.
 *
 * PROPERTIES:
 *
 * &id целое число. Default: ID текущего ресурса
 *
 * USAGE:
 *
 * 
 *
 */
$id = (int) $modx->getOption('id', $scriptProperties);
if (!isset($scriptProperties['id'])) {
    $id = $modx->resource->get('id');
}
$q = $modx->newQuery('modResource');
$q->where(array(
   'parent' => $id,
   'deleted' => 0,
   'published' => 1,
   'hidemenu' => 0
));
$counter = $modx->getCount('modResource', $q);
return $counter;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question