@EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(4,5,6)));$parent = $modx->getOption('parent',$scriptProperties,5);
$parentObj = $modx->getObject('modResource',$parent);
if (!($parentObj instanceof modResource)) { return ''; }
$resArray = $parentObj->getMany('Children');
$resources = array();
foreach($resArray as $res) {
if ($res instanceof modResource) {
$resources[] = $res->get('pagetitle') . '==' . $res->get('id');
}
}
$out = implode("||",$resources);
return $out;This question has been answered by BobRay. See the first response.
[[relatedProducts? &where=`[[CalculatedWhere]]` &input=`[[*relatedProducts]]` &tpl=`relatedProductsTpl`]]
$c = array(
'parent' => 4,
'parent' => 5,
'parent' => 6,
);
return $modx->toJSON($c);@EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(4,5,6)));$jsonString = $modx->toJSON($myArray);
$parent = $modx->setPlaceholder('CalculatedWhere', $jsonString);
// $parent = $modx->getOption('parent',$scriptProperties,5);
$parentObj = $modx->getObject('modResource',$parent);
if (!($parentObj instanceof modResource)) { return ''; }
$resArray = $parentObj->getMany('Children');
$resources = array();
foreach($resArray as $res) {
if ($res instanceof modResource) {
$resources[] = $res->get('pagetitle') . '==' . $res->get('id');
}
}
$out = implode("||",$resources);
return $out;[[!listProducts? &parents=`4,5,6`]]
$c = $modx->newQuery('modResource');
/* third argument is a default list */
$parents = $modx->getOption('parents', $scriptProperties, '4,5,6`, true);
$parents = explode(',', $parents)
$c->where(array(
'parent:IN' => $parents,
));
$resArray = $modx->getCollection('modResource', $c);
if (empty($resArray)) {
return 'No products found';
}
// etc.
$parents = $modx->resource->getTVValue('parents');
$parents = explode(',', $parents);@EVAL return $modx->runSnippet('listProducts',array('parent:IN' => array(4,5,6)));$c = $modx->newQuery('modResource');
$parents = $modx->getOption('parents', $scriptProperties, '4,5,6', true);
$parents = explode(',', $parents);
$c->where(array(
'parent:IN' => $parents,
));
$resArray = $modx->getCollection('modResource', $c);
if (empty($resArray)) {
return 'No products found';
}
foreach($resArray as $res) {
$resources[] = $res->get('pagetitle') . '==' . $res->get('id');
}
$out = implode("||",$resources);
return $out;if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; }
$tpl = $modx->getOption('tpl',$scriptProperties,'relatedProductsTpl');
if ($modx->getChunk($tpl) == '') { return 'We found some related pages, but don\'t know how to present it.'; }
$ids = explode('||', $input);
$output = array();
foreach ($ids as $key => $value) {
$resource = $modx->getObject('modResource',array(
'published' => 1,
'id' => $value));
if ($resource instanceof modResource) {
$ta = $resource->toArray();
$tvs = $resource->getTemplateVars();
foreach ($tvs as $tv) {
$ta[$tv->get('name')] = $tv->get('value');
}
$output[] = $modx->getChunk($tpl,$ta);
}
}
return implode('',$output);[[relatedProducts? &input=`[[*relatedProducts]]` &tpl=`relatedProductsTpl`]]