Jump to content

How get the product/list of the customer on a custom page?


Bets

Recommended Posts

Hello,

I want get a list of products/services that have the customer ( like a clientarea.php?action=services page ).

Where exactly are this informations on database?

 

I followed the exemple on https://whmcs.community/topic/263133-retrieving-product-pricing-information-using-capsule/?tab=comments#comment-1209905 , worked pretty.

But i have no idea where is this informations.

Can give me a example plz?

 

Thank you guys :)

Link to comment
Share on other sites

16 hours ago, Bets said:

Can give me a example plz?

a better example hook might be the hhread below - i'm going to assume that this is for a client area page and that the client is already logged in.

<?php

# Product/Service List Hook
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

function products_list_hook($vars)
{
	$client = Menu::context('client'); 
	$services = Capsule::table('tblhosting')
				->join('tblproducts','tblhosting.packageid','=','tblproducts.id')
				->where('userid',$client->id)
				->select('tblhosting.*','tblproducts.name as product')
				->orderby('nextduedate','desc')
				->get();
	$results = json_decode(json_encode($services), true);
	return array("myservices" => $results);
}
add_hook("ClientAreaPage", 1, "products_list_hook");
?>

a clients product/services are stored in the tblhosting table - that will give you the majority of the information you want... however, it wouldn't give you the Product Name of the service, and so for that we need to check the tblproducts table - that is basically all the above hook is doing... it's creating that list and then passing it back to the template as an array.

and then in the template, you would output that array - that could be using a foreach loop, using DataTables (as I did in the example above), in a HomePagePanel etc.

Link to comment
Share on other sites

Hello,
I used another way, unsing internal api:

	
$command = 'GetClientsProducts';
$postData = array(
    'clientid' => $ca->getUserID(),
    'stats' => true,
);

$resultArray = localAPI($command, $postData);


global $smarty;

$products = $resultArray['products']['product'];
	
$smarty->assign("products", $products);

In the custom.tpl

{foreach $products as $product}
<a class="dropdown-item" href="?p={$product.name}&usr={$product.username}&ip={$product.serverip}&porta={$product.customfields.customfield[0].value}&tec={$product.customfields.customfield[1].value}&step=two">{$product.name} ( {$product.username} )</a>
{/foreach}

But thank you for the example. 🙂

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