Jump to content

Credit Balance in V6 Six Template


hpk

Recommended Posts

  • 2 months later...
  • 7 months later...
Many thanks - this was much needed!

 

Hi Sentq, I know that this is an old post, but I was hoping that you might be able to help me with a question in regard to the credit balance hook, I would like to hook it to a single product on the clientarea product details page, using a single pid, and not be shown anywhere else in the clientarea. Can this be done? if it can't can you suggest an alt.

 

Kev

Link to comment
Share on other sites

Hi Kev,

 

to do that open my actionhook file for editing and in line #26, right after:

 

   if ($filename!=='clientarea' || $clientid===0){
       return;
   }

 

add these lines:

   $allowedinproductids = array(6, 12, 14);
   $productInfo = Menu::context("service");

   if (!in_array($productInfo->packageid, $allowedinproductids)){
       return;
   }

 

replace 6, 12, and 14 with packageids you need this actionhook to display inside.

Link to comment
Share on other sites

Hi Kev,

 

to do that open my actionhook file for editing and in line #26, right after:

 

   if ($filename!=='clientarea' || $clientid===0){
       return;
   }

 

add these lines:

   $allowedinproductids = array(6, 12, 14);
   $productInfo = Menu::context("service");

   if (!in_array($productInfo->packageid, $allowedinproductids)){
       return;
   }

 

replace 6, 12, and 14 with packageids you need this actionhook to display inside.

 

Thankyou, you are awesome :)

 

By any chance, you would have a code/hook that would show the clientsproducts table on the home page would you? I know that I can copy and paste the code from the tpl, but I can't seem to work out how to get it to list the products,price,date etc in the table.

 

Once again thankyou.

Kev

Link to comment
Share on other sites

Hello,

 

Thank you for this hook! I don't understand why it isn't a standard feature in the Six theme.

 

One small request if I may, how do I only enable this hook only the primary client area page? (/clientarea.php)

Thank you :)

open ActionHook file for editing, after

   if ($filename!=='clientarea' || $clientid===0){
       return;
   }

 

add the following

   if ($_REQUEST['action']!=""){
       return;
   }

 

- - - Updated - - -

 

Thankyou, you are awesome :)

 

By any chance, you would have a code/hook that would show the clientsproducts table on the home page would you? I know that I can copy and paste the code from the tpl, but I can't seem to work out how to get it to list the products,price,date etc in the table.

 

Once again thankyou.

Kev

Glad you like it :)

 

you mean "Home Page Panel" right? http://docs.whmcs.com/Working_With_Client_Area_Home_Page_Panels

Link to comment
Share on other sites

  • 2 months later...

Thank you Sentq, this has been working perfectly on our clientsproductdetails.tpl page. I've had clients recently asking if they can also see it on their other client pages, go figure.

So I was just wondering can this code be modified so that if the client has the product id, can the $services.product be allowed to be shown on all the clients pages. Only if they have one of the allowedproductids.

 

<?php

/**
* Display Client's Credit Balance in Client Area
*
* @author WHMCMS
* @link   www.whmcms.com
* @since  WHMCS v6.0.0+
*/

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar
if (App::getCurrentFilename() == 'clientarea') {
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){

   $filename = basename($_SERVER['REQUEST_URI'], ".php");

   $parseFile = explode('.', $filename);

   $client = Menu::context("client");

   $clientid = intval($client->id);

   if ($parseFile['0']!=='clientarea' || $clientid===0){
       return;

   }

$allowedinproductids = array(70);
$productInfo = Menu::context("service");

   if (!in_array($productInfo->packageid, $allowedinproductids)){
       return;
   }  

   $primarySidebar->addChild('Client-Balance', array(
       'label' => "Account Balance",
       'uri' => '#',
       'order' => '1',
       'icon' => 'fa-university'
   ));

   # Get Currency
   $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();

   # Retrieve the panel we just created.
   $balancePanel = $primarySidebar->getChild('Client-Balance');

   // Move the panel to the end of the sorting order so it's always displayed
   // as the last panel in the sidebar.
   $balancePanel->moveToFront();
   $balancePanel->setOrder(0);

   # Add Balance.
   $balancePanel->addChild('balance-amount', array(
       'uri' => '#',
       'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
       'order' => 1
   ));


});
}

 

Thanks again in advance.

Kev

Edited by payless4domains
Link to comment
Share on other sites

Kev,

 

So I was just wondering can this code be modified so that if the client has the product id, can the $services.product be allowed to be shown on all the clients pages. Only if they have one of the allowedproductids

i'm slightly confused - is it a typo with regards to '$services.product' ?

do you want the credit sidebar to be shown if the client has a specified product, or do you want to do something else if he has the product?

Link to comment
Share on other sites

yes it is a little confusing, the following version will display it in clientarea.php and when client is viewing one of his services, it will only display if this product is one of the allowed products (line #17)

 

<?php

/**
* Display Client's Credit Balance in Client Area
*
* @author WHMCMS
* @link   www.whmcms.com
* @since  WHMCS v6.0.0+
*/

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){

   $allowedProductsId = array(1, 15, 20);

   $client = Menu::context("client");
   $service = Menu::context("serviceView");

   $clientid = intval($client->id);

   if (App::getCurrentFilename()!=='clientarea' || $clientid===0){
       return;
   }

   if (!in_array($service->packageid, $allowedProductsId) && is_integer($service->packageid)){
       return;
   }


$allowedinproductids = array(70);
$productInfo = Menu::context("service");

   if (!in_array($productInfo->packageid, $allowedinproductids)){
       return;
   }  

   $primarySidebar->addChild('Client-Balance', array(
       'label' => "Account Balance",
       'uri' => '#',
       'order' => '1',
       'icon' => 'fa-university'
   ));

   # Get Currency
   $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();

   # Retrieve the panel we just created.
   $balancePanel = $primarySidebar->getChild('Client-Balance');

   // Move the panel to the end of the sorting order so it's always displayed
   // as the last panel in the sidebar.
   $balancePanel->moveToFront();
   $balancePanel->setOrder(0);

   # Add Balance.
   $balancePanel->addChild('balance-amount', array(
       'uri' => '#',
       'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
       'order' => 1
   ));


});

Link to comment
Share on other sites

Hi brian & sentq,

 

Sorry for the confusion. And correct Brian "do you want the credit sidebar to be shown if the client has a specified product"

 

My clients are asking that if they have $allowedProductsId = array(70); (specified product),can they see their credit balance on all of their clientarea.php?,submitticket.php?,knowledgebase.php?(basiclly all loggedin pages) instead of just being able to see it on their clientarea.php?action=productdetails&id=70 page.

 

Thank you Sentq for posting the newly modified code, I think we are close to what I'm after but the code still only shows on the clientarea.php?action=productdetails&id=70 and not their other loggedin pages, due to my poor explanation at the start, is it possible to show on their pages?

 

Thanks again guys,

 

Kev

Link to comment
Share on other sites

Kev,

 

you could do it by querying the database to see if the client has one of the products in your array...

 

<?php

/**
* Display Client's Credit Balance in Client Area
*
* @author WHMCMS
* @link   www.whmcms.com
* @since  WHMCS v6.0.0+
*/

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){

   $client = Menu::context("client");
   $clientid = intval($client->id);
   $allowedinproductids = array(70);

   $clientproducts = Capsule::table('tblhosting')
               ->where('userid',$clientid)
               ->whereIn('packageid', $allowedinproductids)
               ->count();

   if (App::getCurrentFilename()!=='clientarea' || $clientid===0 || $clientproducts==0){
       return;
   }

   $primarySidebar->addChild('Client-Balance', array(
       'label' => "Account Balance",
       'uri' => '#',
       'order' => '1',
       'icon' => 'fa-university'
   ));

   # Get Currency
   $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();

   # Retrieve the panel we just created.
   $balancePanel = $primarySidebar->getChild('Client-Balance');

   // Move the panel to the end of the sorting order so it's always displayed
   // as the last panel in the sidebar.
   $balancePanel->moveToFront();
   $balancePanel->setOrder(0);

   # Add Balance.
   $balancePanel->addChild('balance-amount', array(
       'uri' => '#',
       'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
       'order' => 1
   ));

});

so this will count how many of the allowed products the client has and, if it's 1 or more, will show the sidebar on all client area pages.

 

I suppose the way to do it through the class documentation would be to check the client -> $services array, but the above database method should work equally well.

Link to comment
Share on other sites

Thanks Brian, That works excellent on all of the clientarea pages.

 

I use a hook on all loggedin pages, clientarea.php and any other ones to show clients product data, can we link this hook in with that one so that the client's balance shows on all loggedin pages? as I understand that the reason that the above code doesn't show on cart pages,ticket pages or any custom pages etc is that the product id syntax is not linked to those pages.

 

This is the hook to show clients product data.

 


<?php

add_hook( 'ClientAreaPage', 1, function( $vars ) {

   $user   =   Menu :: context( 'client' );
   $data   =   array( 'showproductdata' => false );

   if (! $user ) return $data;

   $products = localAPI(
       'getclientsproducts',
       array(
           'clientid' => $user->getAttribute( 'id' ),
       ),
       'admin' );


   if (! $products || $products['result'] != 'success' || $products['totalresults'] == 0 || count( $products['products'] ) == 0 ) return $data;

   $data['showproductdata']    =   true;
   $product    =   $products['products']['product'][0];
   $info       =   null;
   $title      =   $product['translated_name'];
   $status     =   $product['status'];

   switch( $product['pid'] ) :
   case '70' :
       $info = 'membership';
       break;

   endswitch;
   $data['myproduct']  =   array( 'info' => $info, 'title' => $title, 'status' => $status);

   return $data;




});


Link to comment
Share on other sites

Thanks Brian, That works excellent on all of the clientarea pages.

I use a hook on all loggedin pages, clientarea.php and any other ones to show clients product data, can we link this hook in with that one so that the client's balance shows on all loggedin pages?

if you wanted to show the sidebar on all pages, you could just remove the reference to the clientarea in the if statement.. e.g change...

 

    if (App::getCurrentFilename()!=='clientarea' || $clientid===0 || $clientproducts==0){
       return;
   }

to...

 

    if ($clientproducts==0){
       return;
   }

because this sidebar for you is now only showing when the client has specific product(s), I don't think we need to check that $clientid is not identical to 0 - if it were, $clientprodusts will be too... but you can put it back in if you wish.

 

as I understand that the reason that the above code doesn't show on cart pages,ticket pages or any custom pages etc is that the product id syntax is not linked to those pages.

not quite - it didn't work outside of the client area was because, logically, the original hook specified that it only worked in the client area... remove that limitation and it will work everywhere.... except the cart! :roll:

and the reason why it doesn't work in the cart is a simple one - sentq's hook modifies the primary sidebar... but the cart uses the secondary sidebar only, not the primary - so it is added, but as the primary sidebar is not displayed, you never get to see it! :)

the fix would be to use a second hook, either in one file or separately, that modifies both primary and secondary sidebars...

 

<?php

/**
* Display Client's Credit Balance in Client Area
*
* @author WHMCMS (slightly tweaked by brian!)
* @link   www.whmcms.com
* @since  WHMCS v6.0.0+
*/

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaSidebars', 1, function ()
{
   $primarySidebar = Menu::primarySidebar();
   $secondarySidebar = Menu::secondarySidebar();

   $client = Menu::context("client");
   $clientid = intval($client->id);
   $allowedinproductids = array(45);

   $clientproducts = Capsule::table('tblhosting')
               ->where('userid',$clientid)
               ->whereIn('packageid', $allowedinproductids)
               ->count();

   $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();

   $clientbalance = "'label' => 'Account Balance',
           'uri' => '#',
           'order' => '1',
           'icon' => 'fa-university'";

   if ($clientproducts==0){
       return;
   }

   if (App::getCurrentFilename()!=='cart'){
       $primarySidebar->addChild('Client-Balance', array($clientbalance));
       $balancePanel = $primarySidebar->getChild('Client-Balance');
   }
   else {
       $secondarySidebar->addChild('Client-Balance', array($clientbalance));
       $balancePanel = $secondarySidebar->getChild('Client-Balance');
   }
   $balancePanel->moveToFront();
   $balancePanel->setOrder(0);
   $balancePanel->addChild('balance-amount', array(
       'uri' => '#',
       'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
       'order' => 1
   ));    
});

the above hook should use the secondary sidebar in the cart, and the primary sidebar everywhere else. :idea:

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