Jump to content

access to module params within module hooks?


thoraxe

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated