Jump to content

Query Location Hook


Kevin K

Recommended Posts

I am in search of a hook that will query the database and pull the location information that is stored in configurable options table. I am then going to post this information on the homepage in a custom table that we are designing. Basically it will show the name of the location for each active hosting service . Right now we just need the sql to pull the database information from the configurable options and I believe we can do the rest as far as displaying it.

We have a configurable option group called DataCenter locations with an id of'8'. Within that configurable option it is called Server Location with 2 values (United Stated, Netherlands). We need to pull the location (configurable option) assigned to the hosting service.

So basically it will look like this:

Hosting Account 1 -> Hosting package -> Server Location (configurable option) -> Cost

Hosting Account 2 -> Hosting package -> Server Location (configurable option) ->  Cost

I am willing to pay a reasonable amount for this sql query/hook although any free contribution is always appreciated.

Link to comment
Share on other sites

5 minutes ago, pRieStaKos said:

You have added the location to a config.option ? Why not at server (Settings > Product/Services > Servers) ?

Sorry I should have stated that the configurable options work with an addon module that assigns the server the hosting account is setup on based of the location option (configurable options) that is selected on the order form.  This is for shared hosting/reseller hosting, not servers. 

Link to comment
Share on other sites

2 hours ago, pRieStaKos said:

So the request is a query to get a config.option named Server Location ?

Yes that would work or even just to get an output of all the configurable option ids and their values,  from there we can pull the id we need into the clientareahome.tpl. 

Edited by Kevin K
Link to comment
Share on other sites

Something like this ?

<?php
add_hook('ClientAreaPageHome', 1, function($vars) {
    $client = Menu::context('client');
    $servicesObj = Service::ofUser($client->id)->Active();
    
    foreach ($servicesObj->customFieldValues as $cf) {
            if ($cf->value && $cf->customField->fieldName == "Server Location") {
                $services[$service->id]['serverlocation'] = $cf->value;
            }
        }
    // Return variables to template
  return array("services" => $services);
});

 

Edited by pRieStaKos
Link to comment
Share on other sites

1 minute ago, Kevin K said:

Thanks for taking a shot at this. I really appreciate it! Although I am getting the following error:

 


Error: Class 'Service' not found in /home/********/****************/includes/hooks/server_location_homepage.php:4

 

Yes. Sorry about that.

Add 

use WHMCS/Service/Service;

before add_hook()

Link to comment
Share on other sites

<?php
add_hook('ClientAreaPageHome', 1, function($vars) {
    $client = Menu::context('client');
    $servicesObj = Service::ofUser($client->id)->Active();
    
    foreach ($servicesObj->customFieldValues as $cf) {
            if ($cf->value && $cf->customField->fieldName == "Server Location") {
                $locations[$servicesObj->id]['serverlocation'] = $cf->value;
            }
        }
    // Return variables to template
  error_log(print_r($locations, true), 3, __DIR__.'/locations.txt');
  return array("locations" => $locations);
});

 

Edited by pRieStaKos
Link to comment
Share on other sites

1 minute ago, Kevin K said:

I am guessing that the locations.txt would be in the /includes/hooks directory? If that is the case, the file has not been created.

<?php
add_hook('ClientAreaPageHome', 1, function($vars) {
    $client = Menu::context('client');
	error_log(print_r($client, true), 3, __DIR__.'/client.txt');
    $servicesObj = Service::ofUser($client->id)->Active();
    error_log(print_r($servicesObj, true), 3, __DIR__.'/service.txt');
    foreach ($servicesObj->customFieldValues as $cf) {
            if ($cf->value && $cf->customField->fieldName == "Server Location") {
				error_log("Server Location => {$cf->value}\n", 3, __DIR__.'/customField.txt');
                $locations[$servicesObj->id]['serverlocation'] = $cf->value;
            }
        }
    // Return variables to template
  error_log(print_r($locations, true), 3, __DIR__.'/locations.txt');
  return array("locations" => $locations);
});

Try this again and check which of the files is not been created and that would be the issue point.

Link to comment
Share on other sites

2 minutes ago, Kevin K said:

Tried with the six template and the same result. No files created and $locations not in {debug}.

OK, Just a simple check:

<?php
add_hook('ClientAreaPageHome', 1, function($vars) {
     error_log("This is a hook test", 3, __DIR__.'/hook.txt');
});

Check if file is created. Try to replace __DIR__. with the full path of your hook directory. Also check hook file to have the same permissions as other hook files.

Link to comment
Share on other sites

9 minutes ago, pRieStaKos said:

OK, Just a simple check:


<?php
add_hook('ClientAreaPageHome', 1, function($vars) {
     error_log("This is a hook test", 3, __DIR__.'/hook.txt');
});

Check if file is created. Try to replace __DIR__. with the full path of your hook directory. Also check hook file to have the same permissions as other hook files.

Ya that created the hook.txt

Link to comment
Share on other sites

32 minutes ago, pRieStaKos said:

You need to add error_log line-by-line to check which variable is not been set and why.

I cannot reproduce your issue as this is on your side and template.

Although, the function is what you are looking for.

Ok I think I am getting somewhere now.  There was an error in the  snippet you provided. Oh well it happens to the best of us, 😜

You had me add:

use WHMCS/Service/Service;

It was supposed to be:

use WHMCS\Service\Service;

 

Although now I am getting the following error when trying to load the client area:

BadMethodCallException: Call to undefined method WHMCS\Service\Service::ofUser() in /home/**********/************/vendor/illuminate/support/Traits/ForwardsCalls.php:50

 

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