Kevin K Posted December 13, 2021 Share Posted December 13, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 13, 2021 Share Posted December 13, 2021 You have added the location to a config.option ? Why not at server (Settings > Product/Services > Servers) ? 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 13, 2021 Author Share Posted December 13, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 So the request is a query to get a config.option named Server Location ? 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 (edited) 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 December 14, 2021 by Kevin K 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 (edited) 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 December 14, 2021 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 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 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 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() 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 Thanks that fixed it, but I am not seeing any of the Server Location values outputed in the {debug}. I have added a couple screenshots of the info I am trying to pull. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 You cannot see $services in {debug} ? Change its name to something else. 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 15 minutes ago, pRieStaKos said: You cannot see $services in {debug} ? Change its name to something else. I changed to: return array("services" => $locations); and still the $locations is not available in debug. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 1 minute ago, Kevin K said: I changed to: return array("services" => $locations); and still the $locations is not available in debug. Place an error_log for $locations to see if array is set. If not, check the if statement. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 (edited) <?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 December 14, 2021 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 1 minute ago, pRieStaKos said: Place an error_log for $locations to see if array is set. If not, check the if statement. Not exactly sure how this is done. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 1 minute ago, Kevin K said: Not exactly sure how this is done. Check my last edit. 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 6 minutes ago, pRieStaKos said: Check my last edit. 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. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 Well none of the files were created. 😒 Included a screenshot showing locations is not available in debug. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 Switch to six template and check again, plz 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 6 minutes ago, pRieStaKos said: Switch to six template and check again, plz Tried with the six template and the same result. No files created and $locations not in {debug}. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 14, 2021 Share Posted December 14, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 14, 2021 Author Share Posted December 14, 2021 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 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 15, 2021 Author Share Posted December 15, 2021 Any further ideas on this? 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted December 15, 2021 Share Posted December 15, 2021 3 minutes ago, Kevin K said: Any further ideas on this? 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. 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 15, 2021 Author Share Posted December 15, 2021 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 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.