Well, I was looking for some better solution of my case and stubled this post. Here.. I have a site with a catalogue of tyres where the manufacturer is the parent for models and model as the parent for model variants. I have about 10 manufacturers and all of them has about a dozen models and each model has tens of varians.
Now I need to write a snippet which could return needed model variants (!) by some 3 or 4 values (which are stored in TVs).
As I’m no good php coder I wrote a snippet that ..
- gets all documents from DB with template field equal to ...say 9 (which is my model variant template)
[li]starts a cycle where it looks through all of rows...findin matching documents:
for ($i = 0; $i < $limit; $i++)
{
$row = $modx->db->getRow($result);
$id = $row["id"];
settype($id,"integer");
$pagetitle = $row["pagetitle"];
$pid = $row["parent"];
$parentinfo = $modx -> getDocument($pid,"pagetitle, parent");
$ppagetitle = $parentinfo["pagetitle"];
$modinfo = $modx->getTemplateVarOutput("thumb",$pid);
$thumb = $modinfo["thumb"];
$ppid = $parentinfo["parent"];
$ppinfo = $modx -> getDocument($ppid,"pagetitle");
$pppagetitle = $ppinfo["pagetitle"];
$modinfo = $modx->getTemplateVarOutput('type_size_1',$id);
$ts1 = $modinfo['type_size_1'];
$modinfo = $modx->getTemplateVarOutput('type_size_2',$id);
$ts2 = $modinfo['type_size_2'];
$modinfo = $modx->getTemplateVarOutput('r',$id);
$ro = $modinfo['r'];
$modinfo = $modx->getTemplateVarOutput('season',$pid);
$seas = $modinfo['season'];
$modinfo = $modx->getTemplateVarOutput('price',$id);
$pr = $modinfo['price'];
if (($ts1 == $type_size_1 || $type_size_1 == $all) && ($ts2 == $type_size_2 || $type_size_2 == $all) && ($ro == $r || $r == $all) && ($seas == $season || $season == $all) && ($ppid == $man || $man == $all) && ($pr <= $price || $price == $all))
{
$list .= "<div class='thumb-select'><a href='/[~$id~]'><img src='$thumb' alt='$pppagetitle $ppagetitle $pagetitle'>$pppagetitle $ppagetitle</a><br />$ts1/$ts2 R$ro$seas<br /><span class='price'>$pr р.</span></div>";
$res++;
}
}
$list .= "</div>";
if ($res == 0) {$output .= "<p class='result'>К сожалению, по запросу <b>типоразмер <i>$type_size_1</i>/<i>$type_size_2</i> R<i>$r</i>, сезон: <i>$season</i>, цена не более: <i>$price</i></b> ничего не найдено.</p>";}
else {
$output .= "<p class='result'>По запросу <b>типоразмер <i>$type_size_1</i>/<i>$type_size_2</i> R<i>$r</i>, сезон: <i>$season</i>, цена не более: <i>$price руб.</i></b> найдено $res позиций:</p>".$list;
$output .= "<p><a href='/[~266~]?p=$next'>-></p>";
}
Well
that works ...but it can take dramatically long time if 4-5 values are given.
Could someone giv advice on that?