We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24414
    • 45 Posts
    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?
      • 18397
      • 3,250 Posts
      This extender with the following code should do the trick:
      if (!function_exists("exampleFunction")) {
      	function exampleFunction($resource) {
      		$productID = $resource["tcProductID"];
      		$query = "SELECT amount FROM modx_treasure_chest WHERE id=$productID";
      		$tcPrice = $modx->db->query($query);
      		return $tcPrice;
      	}
      }
      
      $filters["custom"]["exampleFilter"] = array("tcProductID","exampleFilter"); 
      
        • 24414
        • 45 Posts
        Excellent! Thanks for that smiley, will have a go with it in the morning - haven’t even really looked into extenders yet so I don’t think I ever would have though to use them...
          • 24414
          • 45 Posts
          Right...

          Hope I’m not missing the point here! Have had a look through extender files and the Ditto extender docs–

          Does the code posted filter by price?

          I would like to create a custom placeholder [+tcPrice+] to contain price, using document’s [*tcProductID*] (same value as ID from TreasureChest row) to select it from the modx_treasure_chest table.

          Saw the following code in example.extender.inc.php:

          $placeholders['example'] = array(array("pagetitle","*"),"exampleFunction","pagetitle");


          Or am I just confused?