thoraxe Posted January 18, 2013 Share Posted January 18, 2013 So, I am somehow finding it impossible to accomplish an external validation in a way that makes any sense. Using the hooks example of creating a forum account, one thing that you would have to do is validate that the forum username is actually available. The most sensible way to provide a forum username as part of a product would be a custom field on your product for the forum username. When the customer comes to whmcs portal, they click a product to order, and are taken to the required options page, where they enter their desired username (joe). If you use the ShoppingCartValidateProductUpdate hook, you can actually generate an error when someone clicks to add a product to the cart. But there's a problem -- even if I make the hook part of my custom server module, it doesn't seem to have access to module variables. For example, inside of a module on the CreateAccount action, you have access to variables like $params["serverhostname"]. Inside of the hook, there are no params. This means you can't acces any of the relevant information you would need for an API endpoint. global $errormessage; $errormessage = "params: ".json_encode($params)."<br>vars: ".json_encode($vars); If I use this within ShoppingCartValidateProductUpdate, vars has some data, but params is null. Is there any way to get access to the module's params (ex serverhostname) within the hook? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS JamesX Posted January 18, 2013 Share Posted January 18, 2013 (edited) Check in the $smarty array. Aside from that, you should do what I said before with the errormessage variable; use ".=" instead of "=". Edited January 18, 2013 by WHMCS JamesX 0 Quote Link to comment Share on other sites More sharing options...
thoraxe Posted January 18, 2013 Author Share Posted January 18, 2013 Hi, Good call on the .= and not = Here's the sample test code: function hook_jumpmail_validate_user($vars) { $command = "logactivity"; $adminuser = "erikjacobs"; $values["description"] = json_encode($_SESSION); global $errormessage; $errormessage .= "params: ".json_encode($params)."<br>smarty: ".json_encode($smarty); } add_hook("ShoppingCartValidateProductUpdate",1,"hook_jumpmail_validate_user"); Unfortunately, the output for smarty is also null: params: null smarty: null WHMCS' suggestion was to use the SQL helper functions to query the database directly to get access to the module's server configuration. That's really ugly, but hopefully they'll add support for the module params within the module's hooks. I'll see if I can hack my way through it. 0 Quote Link to comment Share on other sites More sharing options...
cappac Posted May 25, 2013 Share Posted May 25, 2013 The product table can be queried like this (to read eg. module configoptions): function hook_template_ShoppingCartValidateProductUpdate($vars) { global $errormessage, $pid; /* ob_start(); //print_r($_SESSION['cart']); print_r($vars); $errormessage .= "<li>".ob_get_contents(); ob_end_clean(); */ // Workaround, need actual product ID to get product config data from DB // seems $pid does the trick $table = "tblproducts"; $fields = "*"; $where = array("id"=>$pid); $result = select_query($table,$fields,$where); $product = mysql_fetch_array($result); $lfp = @fopen('./_log_validate.txt', 'w'); fwrite($lfp, date('M j Y G:i:s').": ".print_r($product,true)."\n\n"); @fclose($lfp); Note the $pid 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.