Jump to content
IamAQ

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

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
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. 🙂

Share this post


Link to post
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.


  • Similar Content

    • By sawfly
      Hi to all. I had a task to migrate old custom page (from 5th version) to 7th version. I have a problem with a primary navbar
      I am getting navbar with 6 items in it
      count(Menu::primaryNavbar()->getChildren()); // 6 But on the site in the primary navbar, there are 7 items. I tried to check out in hook the code above and got 7; There is no 'affiliates' item in the navbar. Maybe someone knows how to get full primary navbar as in all pages on the site
    • By larryk
      I am trying to create a custom WHMCS page without any sidebars. I only want it to show the top bar where clients can choose language, etc.
      I have this code currently:
      <?php define("CLIENTAREA",true); //define("FORCESSL",true); // Uncomment to force the page to use https:// require("init.php"); $ca = new WHMCS_ClientArea(); $ca->setPageTitle("Support Center"); $ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname')); $ca->addToBreadCrumb('support.php','HostAble Support'); $ca->addToBreadCrumb('support-center.php','Support Center'); $ca->initPage(); # Check login status if ($ca->isLoggedIn()) { # User is logged in - put any code you like here # Here's an example to get the currently logged in clients first name $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".$ca->getUserID()); $data = mysql_fetch_array($result); $clientname = $data[0]; $ca->assign('clientname', $clientname); } else { # User is not logged in } # Define the template filename to be used without the .tpl extension $ca->setTemplate('supportcenter'); $ca->output(); ?> But obviously it isnt working, it just shows the page but with the sidebars and navigation bar too.
      Thank you if you can help me :)
    • By Dimitra
      Hi,
      I need some help with a custom page I have created.
       
      I have created a new custom page named whois (created with whoislookup.tpl and whoislookup.php), where I have put the code for the bulk search from bulkdomainchecker.tpl. The page is actually a copy of bulkdomaintransfer.tpl, but with different name and php file. I want to use it as a whois search, so the client searches for a registered domain and the results display the domain with the WHOIs button.
       
      My problem is that I can't make the page display any domain information. I have tried to include files from the feeds folder but nothing. Every element related to domain (domain results, pricing table etc) is empty.
       
      How can I make it work and display the results in this page? Any help would be appreciated.
       
      Thank you.
  • 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