We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24531
    • 213 Posts
    Hi there!
    i’m writing extender for ditto, to get options from treasure chest. the part of setting custom ditto placeholders is a bit confusing and i don’t get it at all.

    if (!function_exists("tcPriceGetter")) {
    	function tcPriceGetter($resource) {
    		global $modx;
    		
    		$productID = $resource["tcProductID"];
    		$table = $modx->getFullTableName('treasure_chest');
    		$query = "SELECT amount FROM $table WHERE id='$productID'";
    		
    
    		$result = $modx->db->query($query);
    		$tcPrice = $modx->db->getValue($result);
    		$modx->setPlaceholder('tcquery', $query);
    		return ($tcPrice < 1) ? 'No price found' : $tcPrice;
    
    		}
    
    }
    
    if (!function_exists("tcOptGetter")) {
    	function tcOptGetter($resource) {
    		global $modx;
    		
    		$productID = $resource["tcProductID"];
    		$table = $modx->getFullTableName('treasure_chest');
    				
    		/* my own additions */
    		$options = "SELECT * FROM $table WHERE id='$productID'";
    		$options_query = $modx->db->query($options);
    		$product = $modx->db->getRow($options_query);
    		    foreach ($product as $key => $value)
                {
                    if ($value == null)
                    {
                        // Get rid of any NULL Values
                        unset($product[$key]);
                    }
                }
    			
    			return $product;
    
    
    		}
    
    }
    
    	$placeholders['tcPrice'] = array(array("tcProductID","*"),"tcPriceGetter");
    
    



    tcPriceGetter is function i took somewhere on these forums and it sets price in [+tcPrice+] right
    what i need to do is to set several custom placeholders based on $product[$key]
    but i don’t know how to set it right, all my experiments failed.

    what’s is an asterisk in array(array("tcProductID","*"),"tcPriceGetter")?
    tcProductIdD is a TV for every product document.

    help please!
      • 24531
      • 213 Posts
      nevermind, there was a problem with my ftp client which changed case of file so the old extender wasn’t overwritten.
        • 24531
        • 213 Posts
        but then again how i can return array from the function and set a placeholder which array key is $x?