Jump to content

Adding Client's products and services details on custom.php page.


IamAQ

Recommended Posts

Hello, 

I am trying to add client's products and services list to the custom.php page, 
I have use the local API and added this code in custom.php file,

 $command = 'GetClientsProducts';
 $postData = array(
     'clientid' => '1',
     'stats' => true,
 );
 $adminUsername = 'admin'// Optional for WHMCS 7.2 and later
 
 $results = localAPI($command$postData$adminUsername);
 print_r($results); 

It displays the results in Json format with print_r, but  I don't understand how I can use this in .tpl file to display the client's products on the page.
Please Help!

Link to comment
Share on other sites

7 hours ago, IamAQ said:

I am trying to add client's products and services list to the custom.php page, 

if you are going to do this via the API, then the custom page would look roughly along the lines of below (adjust titles, breadcrumbs, template names etc for your own needs.)...

<?php
use WHMCS\ClientArea;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Title');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', 'ToS');
$ca->initPage();
if ($ca->isLoggedIn()) {
	$command = 'GetClientsProducts';
	$postData = array('clientid' => $ca->getUserID(),'stats' => true,);
	$results = localAPI($command, $postData);
	if ($results['result'] == "success") {
		$ca->assign('services', $results['products']['product']);
	}
}
$ca->setTemplate('tos');
$ca->output();
7 hours ago, IamAQ said:

It displays the results in Json format with print_r, but  I don't understand how I can use this in .tpl file to display the client's products on the page.

you assign the results of the API query (or at least the parts of it that you need for your purpose) to a variable/array and then the template will be able to access it.

for example, you could copy the template code from clientareaproducts.tpl and that would (more or less) work - the SSL info would likely be missing, a few fields in the template code would have to be changed (name, status, prices etc) to suit the returned array (or the array modified to suit the template) - I don't think prices and dates would even be formatted correctly either.

Link to comment
Share on other sites

6 hours ago, brian! said:

for example, you could copy the template code from clientareaproducts.tpl and that would (more or less) work - the SSL info would likely be missing, a few fields in the template code would have to be changed (name, status, prices etc) to suit the returned array (or the array modified to suit the template) - I don't think prices and dates would even be formatted correctly either.

So, How can I fix this? How would I know what variables I should use for this?
If have fixed the name , price and status issue, but no luck with sslStatus, how can I fix this,?


 

Edited by IamAQ
Link to comment
Share on other sites

17 hours ago, IamAQ said:

So, How can I fix this?

by working backwards... e.g first you have to decide what the desired output is going to be (I just guessed you wanted to mirror the services page - you don't have to)... then when you know what you want it to look like, you take a look at what data you need to obtain from the database (or elsewhere) for that page... time spent doing this now is going to save you time in the long run.

17 hours ago, IamAQ said:

How would I know what variables I should use for this?

it's not until you know the difference between what you want and what you can initially get, that you can decide what the fix is going to be.

let me give you a trivial example, if you were using the clientareaproducts.tpl template for your output, it would be expecting to use $service.product for the product name, but the API on this custom page would return $service.name - so either you edit the template and change relevant references of 'product' for 'name', or you edit what the php page that is returning in the array... it doesn't really matter which on a custom page, whichever is the simpler method... the point being that unless you're piggybacking on an existing default template, your template will be custom and therefore can be changed without worrying that WHMCS is going to overwrite it.

aMSU1Ml.png

as I suspected yesterday - names, prices, status will be missing... the information is all in the returned array, but might have different key names... putting a {debug} in the template will be one way of showing you the $services array that the php is sending to the page and that can be used to work out what you have access to... and what may be missing.

formatting dates and prices will have to be done in the php file - you could use a hook, but you have access to the .php so you don't need to - the usual way would be to loop through the results array before you assign to the template and start applying formatting to the dates/prices... the good news in that respect is that you know the client will be logged in, so you'll be able to get their chosen currency etc.

18 hours ago, IamAQ said:

If have fixed the name , price and status issue, but no luck with sslStatus, how can I fix this,?

my inclination, and advice to you, would be to leave it out of the output - it's less hassle...

I doubt that you can use the API to get these values; the method used by WHMCS internally will likely be unavailable to you... so then you're left with querying the database - that could be done during the foreach loop previously mentioned, by looking up each domain value in the results array, with it's record in the tblsslstatus table and returning whether it's active or not.... and if it is active, it also returns an object inside the array that contains additional details....

you could save a hell of a lot of time/effort not trying to reproduce everything in the existing template but by cutting corners, e.g just returning whether the sslstatus is active or not and deciding the icon etc in the template....

personally, I wouldn't include it at all - or I might think about whether it would be easier to add whatever is going to be unique on this custom page, to the existing clientareaproducts template/page instead... because depending on what that it, it might be quicker than recreating the clientservices page. 🙂

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.

×
×
  • 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