Hi there and Happy Easter all!
I want to setup a relatedPages TV which lists all my products. I’ve found a snippet which I can list all resources form a particular parent, but my products are spread around the site, so this doesn’t do what I need.
I have two main folders of products:
Women (4)
Men (5)
But each folder then contains another folder for my product categories (shirts, jackets, shoes etc).
So the TV I found has this in the input options:
@EVAL return $modx->runSnippet('listMyResources',array('parent' => 4));
Then the snippet I found is this:
<?php
$parent = $modx->getOption('parent',$scriptProperties,4);
$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;
So this will find all the children from the parent 4, but all this does is display the categories within women (4) and no actual products because it only finds the direct children.
So, ideally I would pull in all children and grandchildren, bypassing containers.
Also, I need to set the ultimate parent as either Men or Women, so that I don’t pull in a list of men’s shoes as a related product option of a women’s dress.
Can anyone push me in the right direction?
Thanks!
Andy