Hy,
I’m actually working on TC on modx version 9.6.3.
I just modified a bit your code to mix 2 tips you already made before.
- a small tv for easy creating a shop item page(dropdown list)
- a Ditto call to create a list of items
I personnally didn’t like to insert for each document a tv called productid.
(but i kept nearly all your code to make the upagrade easy)
So in this way, i just need to associate my new document with the dropdown TV
Ditto + tcgetvalue will do the rest.
Here is a ditto call in the Ditto template(an image for example)
<img src="[[tcgetvalue? &label=`image` &idDoc=`[+id+]` &productid=`[+productid+]`]]" alt="[+pagetitle+]" />
I have just added idDoc
Here is the snippet modified
<?php
//search for TV's id by "name" and "ItemId"(name of your TV)
$result = $modx->db->select("id", "modx_site_tmplvars", "name = 'itemId'","", "1");
$id_item = $modx->db->getValue($result);
//search TV value by this $id_tem
$result = $modx->db->select("value,tmplvarid", "modx_site_tmplvar_contentvalues", "tmplvarid = '".$id_item."' AND contentid = '".$idDoc."' ","", "1");
$value_item = $modx->db->getValue($result);
//keep the original code to simlify upgrades
$productid=$value_item;
$result = $modx->db->select("*", $modx->getFullTableName('treasure_chest'), "id = '".$productid."'" );
$tcinfo = $modx->db->getRow($result);
if($label=="amount") return $tcinfo['amount'];
if($label=="image") return $tcinfo['image'];
if($label=="item") return $tcinfo['item_name'];
if($label=="id") return $tcinfo['id'];
?>
Again, this is just a kind of mix with your 2 codes on TC.
I’m sure there is a way to simplify the code and make it more simple
I hope this can be handy for somebody.
Thanks again for your help.