I’m trying to pull content out of the TreasureChest table so I can display price values directly via Ditto.
I can pull the prices in via $modx->db->query if I hard code the product ID to the EVAL’d code, but not if I use $modx->getTemplateVar() to extract the product ID value.
The code works in product pages themselves, but when aggregated to another page the product ID TV content does not appear.
TV Content:
@EVAL
$productID = $modx->getTemplateVar('tcProductID', "", $modx->documentIdentifier);
$value = $productID['value'];
$query = "SELECT amount FROM modx_treasure_chest WHERE id=$value";
$tcPrice = $modx->db->query($query);
return $tcPrice;
I’ve also tried using PHx to extract content using a modified version of the phx:tv custom modifier I found on the wiki, but that errors out when passing the product ID value to the SQL statement too.
[+phx:price=`30?tcProductID`+]
<?php
if(strlen($options)>0) {
$data = explode("?",trim($options),2);
$id= (!empty($data[0]) && is_numeric($data[0])) ? $data[0]: '';
$tv= (!empty($data[1])) ? $data[1]: '';
$productID = $modx->getTemplateVar($tv, "", $id);
$value = $productID['value'];
$query = "SELECT amount FROM modx_treasure_chest WHERE id=$value";
$tcPrice = $modx->db->query($query);
return $tcPrice;
}
?>
Is this possible?