Jump to content
cstech

Display hosting package on home page

Recommended Posts

18 hours ago, cstech said:

Hello, I tried and followed the hook from Brian in this thread https://whmcs.community/topic/271417-product-info-on-custom-pages/ to display a hosting package in home page unfortunately it not work and no error displayed.

post the hook code, and the code added to the template so that I can see what you're trying to use...

Share this post


Link to post
Share on other sites

Hello Brian, here the hook 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function homepage_products_hook($vars)
{
	$products = Capsule::table('tblproducts')
		->join('tblpricing', 'tblproducts.id', '=', 'tblpricing.relid')
		->where('tblpricing.type', 'product')
		->where('tblproducts.hidden','0')
		->where('tblproducts.gid','1')	
		->select('tblproducts.id','tblproducts.name','tblproducts.description','tblpricing.monthly')
		->orderBy('tblproducts.order')						
		->groupBy('tblproducts.id')
		->get();
	$results = json_decode(json_encode($products), true);
	return array("myproducts" => $results);
}
add_hook("ClientAreaPage", 1, "homepage_products_hook");
?>

 

2 hours ago, brian! said:

and the code added to the template

I don't added any code to the six default template, and I don't know wich the code and where I should add it

Share this post


Link to post
Share on other sites
20 hours ago, cstech said:

I don't added any code to the six default template, and I don't know wich the code and where I should add it

aahh - there be the problem... all that hook does is create the array and pass it to the template - you will need to output it in the template.

as a basic example, the table code in the post below could output the array...

for example, if you were outgoing to output this on the homepage, then you could change the hook from ClientAreaPage to ClientAreaPageHome, and you would edit homepage.tpl

in practice, what you will probably want to do it output it in the same style as your own website / cart, e.g copy code from one of the products.tpl templates and adjust the variables used to your new custom array... it's one of those situations that is relatively easy to do (the layout design may take some time), but lengthy to explain... but have a play, and if you have any questions, you only have to ask.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you Brian for your useful help

4 hours ago, brian! said:

in practice, what you will probably want to do it output it in the same style as your own website / cart, e.g copy code from one of the products.tpl templates and adjust the variables used to your new custom array...

The output is not so far from the original templates>>orderforms>>premium_comparison>>products.tpl  

The missing rendering is space between

<li>sentance in description</li>

And the important two missing are price of product and the not working of Order button 

Share this post


Link to post
Share on other sites
On 19/02/2019 at 21:17, cstech said:

The output is not so far from the original templates>>orderforms>>premium_comparison>>products.tpl  

oh trust you to use one of the templates that uses a very complicated $products array in the cart - that would be an extremely complicated array to reproduce if it had to cover all eventualities... there is a reason why using data feeds is much simpler!

in terms of showing price, then the hook already grabs the monthly price (ideally you'd be choosing a currency in that hook too), but to output a monthly price, you would replace...

                                                {if $product.bid}
                                                    {$LANG.bundledeal}
                                                    {if $product.displayprice}
                                                        <br /><br /><span>{$product.displayPriceSimple}</span>
                                                    {/if}
                                                {elseif $product.paytype eq "free"}
                                                    {$LANG.orderfree}
                                                {elseif $product.paytype eq "onetime"}
                                                    {$product.pricing.onetime} {$LANG.orderpaymenttermonetime}
                                                {else}
                                                    {if $product.pricing.hasconfigoptions}
                                                        {$LANG.from}
                                                    {/if}
                                                    {$product.pricing.minprice.cycleText}
                                                    <br>
                                                    {if $product.pricing.minprice.setupFee}
                                                        <small>{$product.pricing.minprice.setupFee->toPrefixed()} {$LANG.ordersetupfee}</small>
                                                    {/if}
                                                {/if}

with...

{$product.monthly}

now it won't be formatted for a currency (you could do that in the hook if you had to), but it's probably simpler to just add it to the output...

${$product.monthly} USD

and in terms of the button link, you would replace...

<a href="{$smarty.server.PHP_SELF}?a=add&amp;{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="order-button" id="product{$product@iteration}-order-button">{$LANG.ordernowbutton}</a>

with...

<a href="cart.php?a=add&amp;pid={$product.id}" class="order-button" id="product{$product@iteration}-order-button">{$LANG.ordernowbutton}</a>

I should also add that in the hook, i've changed "myproducts" to "products" to minimise the changes required in the template.

  • Like 1

Share this post


Link to post
Share on other sites

Hi! @brian! hope you're well
Please last ask about show products on home page using six template with premium_comparaison

I use this hook to dispaly name of product group 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_getProductGroups($vars){

   # Get Product Groups
           $getProductGroups = Capsule::table('tblproductgroups')
                               ->where('tblproductgroups.hidden', '0')
							   ->where('tblproductgroups.id', '6')
                               ->select('id', 'name', 'headline', 'tagline')
                               ->orderBy('order', 'asc')
                               ->get();

   $encodedata = json_encode($getProductGroups);
   $decodedata = json_decode($encodedata, true);

   return array("productgroup" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

I use translation of product group through, Products/Services>>Edit Group>>Translate 
Please how I can have the translation work for the home page?

 

Thank you in advance 

Share this post


Link to post
Share on other sites

Hi @cstech

18 hours ago, cstech said:

Hi! @brian! hope you're well

i'm 98% through a massive server migration process and everything seems ok... 🤞

18 hours ago, cstech said:

I use this hook to display name of product group 

before going any further, I should say that as a matter of housekeeping, you will find it easier to do everything in the same hook, e.g get products, groups etc... there's no need to use separate hooks for each little bit...

if we forget about translations for a minute, then you're hook could be trimmed down to...

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_getProductGroups($vars){

	$getProductGroups = Capsule::table('tblproductgroups')->where('tblproductgroups.id','6')->select('id','name','headline','tagline')->first();
	$decodedata = json_decode(json_encode($getProductGroups), true);
	return array("productgroup" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

there's no need for the orderBy as you're only going to get a maximum of one result (unless there's a corruption in the db!), and you don't really need to check that the group isn't hidden.

18 hours ago, cstech said:

I use translation of product group through, Products/Services>>Edit Group>>Translate 
Please how I can have the translation work for the home page?

two ways - one option would be to continue using capsule and join your query with the tbldynamic_translations database table (which as the name implies, stores the translations for each language)... if you ever get some spare time, i'd suggest playing with that as you will learn the usefulness of joining tables in queries...

the alternative way is far simpler, because WHMCS already has a built in method for doing it...

<?php

use WHMCS\Product\Group;

function hook_getProductGroups($vars){
	
	$myproductgroup = Group::find('6');
	return array("productgroup" => $myproductgroup);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

yeah, that's it - no long-winded joins, wheres, selects etc... 🙂

in the homepage.tpl template, you will now have access to the $productgroup array and can access your desired information by using {$productgroup->name) etc...

Product Name = {$productgroup->name}
Product Headline = {$productgroup->headline}
Product Tagline = {$productgroup->tagline}

if there is a dynamic translation for the name/headline/tagline in the current language, it's value will be the translated name etc; if there isn't a translation, it will use the default value. thanks.png

Share this post


Link to post
Share on other sites
4 hours ago, brian! said:

i'm 98% through a massive server migration process and everything seems ok... 🤞

Surly you took a good coffee at this time  💪

4 hours ago, brian! said:

the alternative way is far simpler

I try to configure the far simpler methode. Unfortunately don't want to work for me 

As a Hook

<?php

use WHMCS\Product\Group;

function hook_getProductGroups($vars){
	
	$myproductgroup = Group::find('6');
	return array("productgroup" => $myproductgroup);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

With on homepage.tpl

{$productgroup->name}
{$productgroup->headline}
{$productgroup->tagline}

I got error (.... something went wrong and we couldn't process your request) 

 

Share this post


Link to post
Share on other sites

did you enable display errors in general settings - that will give you more details...

one possible cause would be if you had two hooks running with the same function name - I hope you modified the existing hook, and not created another one with the same function name ???

Share this post


Link to post
Share on other sites
32 minutes ago, brian! said:

I hope you modified the existing hook, and not created another one with the same function name ???

I created another one with another fuction name 

 

47 minutes ago, brian! said:

did you enable display errors in general settings - that will give you more details...

I just enabled it it!

Share this post


Link to post
Share on other sites
3 hours ago, cstech said:

I created another one with another fuction name 

and I hope they weren't both trying to return the same variable!

Share this post


Link to post
Share on other sites
56 minutes ago, brian! said:

and I hope they weren't both trying to return the same variable!

I got this error 

exception 'Whoops\Exception\ErrorException' with message 'syntax error, unexpected 'use' (T_USE)' in /xxx/xxx/public_html/client/includes/hooks/grouplang.php:3
Stack trace:
#0 /xxx/xxx/public_html/client/vendor/whmcs/whmcs-foundation/lib/Utility/Error/Run.php(0): WHMCS\Utility\Error\Run->handleError(4, 'syntax error, u...', '/xxx/xxx/...', 3)
#1 [internal function]: WHMCS\Utility\Error\Run->handleShutdown()
#2 {main}

The line 3 in the hook contains

use WHMCS\Product\Group;

 

Share this post


Link to post
Share on other sites
17 hours ago, brian! said:

which version of WHMCS are you using ??

Version: 7.7.1

Share this post


Link to post
Share on other sites
Just now, cstech said:

Version: 7.7.1

then it's weird that it doesn't work - post the entire hook here, and disable any other clientareapage** hooks and see if that makes a difference..

Share this post


Link to post
Share on other sites
5 minutes ago, brian! said:

post the entire hook here

<?php

use WHMCS\Product\Group;

function hook_ProductGroupsLang($vars){
	
	$productgroup = Group::find('6');
	return array("productgroups" => $productgroup);
}
add_hook("ClientAreaPageHome", 1, "hook_ProductGroupsLang");

 

7 minutes ago, brian! said:

disable any other clientareapage** hooks

I do it, I shoud backup my file before doing it. 
Unfortunately WHMCS don't give us a version to use on local server for trainings 

Share this post


Link to post
Share on other sites

I deleted all other hooks. I created a new hook with your exact syntax 

<?php

use WHMCS\Product\Group;

function hook_getProductGroups($vars){
	
	$myproductgroup = Group::find('6');
	return array("productgroup" => $myproductgroup);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

And I added on the homepage.tpl 

{$productgroup->name}
{$productgroup->headline}
{$productgroup->tagline}

Now error shown and no hook results

Share this post


Link to post
Share on other sites

what about if you use this...

<?php

use WHMCS\Product\Group;

function hook_getProductGroups($vars){
	
	$myproductgroup = Group::find('6');
	$mygroupname = $myproductgroup->name;
	$mygrouphead = $myproductgroup->headline;
	$mygrouptag = $myproductgroup->tagline;
	return array("productgroupname" => $mygroupname, "productgrouphead" => $mygrouphead, "productgrouptag" => $mygrouptag);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");

N4wH3P1.png

that will give you three variables that you can use in the template - {$productgroupname}, {$productgrouphead} and {$productgrouptag} - this for me is working fine in my v7.7.1 dev.

Share this post


Link to post
Share on other sites
37 minutes ago, brian! said:

what about if you use this...

Thank you for your all code, unfortunately don't work for me! no error and no hook result. it is your code ok with PHP v 5.6.30?

Share this post


Link to post
Share on other sites
1 minute ago, cstech said:

Thank you for your all code, unfortunately don't work for me! no error and no hook result.

so if you add {debug} to the homepage.tpl template, the popup window is not showing those three variables ??

2 minutes ago, cstech said:

it is your code ok with PHP v 5.6.30?

it should be - that's what i'm using on the dev. 🙂

if you can't get this to work, then you'll have to resort to querying the database as I mentioned earlier.

Share this post


Link to post
Share on other sites
4 minutes ago, brian! said:

so if you add {debug} to the homepage.tpl template, the popup window is not showing those three variables ??

 Nothings happened!

 

5 minutes ago, brian! said:

then you'll have to resort to querying the database as I mentioned earlier.

Please can show me how 

Share this post


Link to post
Share on other sites

If you have added the {debug} to the homepage.tpl file as mentioned and it did not open a separate window when you view the home page of your whmcs install, then did you edit your custom template vs the built in one?   If you edited the custom one, do you have any pop-up block alerts perhaps that is stopping that window from opening? 

Share this post


Link to post
Share on other sites
1 hour ago, steven99 said:

If you have added the {debug} to the homepage.tpl file as mentioned and it did not open a separate window when you view the home page of your whmcs install, then did you edit your custom template vs the built in one?

I tested the hook with adding {$productgroupname} {$productgrouphead}{$productgrouptag} {debug} at the end of the homepage.tpl in six native template, no things happend nor error nor separted windows opened! 
I use chrome v 72.0.3626.119 with adblock disabled. 

All methodes provided by @brian! worked so good, except this for automated translation of name group, products headline and tagline on homepage!  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines