Here is some code showing how to grab price and options info from the database and display it automatically, without the need to re-code your pages whenever you change product price or other settings. This is a pre-Widgets solution and so works with versions earlier than v4.4.
I decided to post this as a "How To" because while there are some useful posts on this area most were incomplete or not general enough and it seems like a common requirement. For example, I am grateful for the following thread which I borrowed heavily from: http://forum.whmcs.com/showthread.php?t=23273
My simplified code below should help people adapt this approach to their application more easily. If you save it as PHP and edit the paths in the "require" statements it renders a page with two tables. One of your domain registration pricing, and one showing your hosting plans in each currency. For example:
These are followed by output of more detail information on all your plans (not shown to keep the length of this post managable!). Anyway, here's the code which is fairly self explanatory:Code:Domain Pricing Extension Price .co.uk £0.00 .co.uk £0.00 .com £8.45 .com £13.49 .org £8.45 .org £13.49 .net £8.45 .net £13.49 .eu £16.95 .eu £26.95 Hosting Plans Hosting Plan Pay Monthly Pay Annually Freelance/Practitioner £3.99 £39.95/year (£3.33/month) Freelance/Practitioner $6.99 $67.95/year ($5.66/month) Fully Managed Hosting (Freelance/Practitioner) N/A £97.00/year (£8.08/month) Fully Managed Hosting (Freelance/Practitioner) N/A $169.00/year ($14.08/month) Freelance/Practitioner 4.99 49.95/year (4.16/month) Fully Managed Hosting (Freelance/Practitioner) N/A 125.00/year (10.42/month) Professional £7.49 £79.95/year (£6.66/month) Professional $12.99 $139.95/year ($11.66/month) Professional 9.99 99.95/year (8.33/month) Corporate £9.99 £99.95/year (£8.33/month) Corporate $16.99 $169.95/year ($14.16/month) Corporate 12.99 124.95/year (10.41/month) All Group & Plan Settings <snipped>
I haven't gone live yet, but sometime in the next few days you'll be able to see the end result at Managed Website HostingPHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
# WHMCS functions (note ./clients is the location of the WHMCS folder)
require("clients/dbconnect.php");
require("clients/includes/functions.php");
require("clients/includes/clientareafunctions.php");
require("clients/includes/currencyfunctions.php");
####################################################
# Domain Pricing Table
#
# This list prices in the -default- currency only
echo "<h2>Domain Pricing</h2>";
$result = mysql_query("
SELECT * FROM tblpricing
LEFT JOIN tbldomainpricing
ON tblpricing.relid = tbldomainpricing.id
WHERE tblpricing.type = 'domainregister'
") or die(mysql_error());
echo "<table width='300' border='0' class='mytable'>";
echo "<tr><th>Extension</th><th>Price</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
echo $row['extension'];
echo "</td><td>";
echo "£";
echo $row['msetupfee'];
echo "</td></tr>";
}
echo "</table>";
####################################################
# HOSTING PLAN TABLE
#
# This lists prices in -all- currencies.
echo "<h2>Hosting Plans</h2>";
$result = mysql_query("
SELECT p.name, p.description, t.monthly, t.quarterly,
t.semiannually, t.annually, c.code
FROM tblproducts AS p
INNER JOIN tblpricing AS t ON t.type='product' AND t.relid = p.id
INNER JOIN tblcurrencies AS c ON c.id = t.currency
WHERE p.hidden != 'on' AND p.type ='hostingaccount'
") or die(mysql_error());
// Used to map database code to currency symbol
$currency_symbol = array(
'USD' => '$',
'GBP' => '£',
'EUR' => '' // Euro (see http://www.cs.tut.fi/~jkorpela/html/euro.html)
);
echo "<table width='300' border='0'>";
echo "<tr valign=top>
<th>Hosting Plan</th>
<th>Pay Monthly</th>
<th>Pay Annually</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr valign=top>";
echo "<td>" . $row['name'] . "</td>";
// Some plans are not available monthly
if ($row['monthly'] < 0)
echo "<td>N/A</td>";
else
echo "<td>" . $currency_symbol[$row['code']] . $row['monthly'] . "</td>";
echo "<td>" . $currency_symbol[$row['code']] . $row['annually'] . "/year (" . $currency_symbol[$row['code']] . round($row['annually']/12,2) . "/month)</td>";
echo "</tr>";
}
echo "</table>";
#######################################################
# This shows how to get all settings for Groups & Plans
#
echo "<h2>All Group & Plan Settings</h2>";
echo "<b>Groups</b><br/>";
$whmcs_group_number = 0;
$result_groups = mysql_query("
SELECT DISTINCT tblproducts.gid, tblproductgroups.id, tblproductgroups.name,
tblproductgroups.order, tblproducts.type, tblproductgroups.hidden,
tblproducts.hidden FROM tblproductgroups, tblproducts
WHERE tblproducts.gid = tblproductgroups.id
AND tblproducts.type = 'hostingaccount'
AND tblproducts.hidden != 'on'
AND tblproductgroups.hidden != 'on'
ORDER BY tblproductgroups.order ASC
") or die(mysql_error());
while($row = mysql_fetch_assoc($result_groups)){
// populate multi-level array with individual hosting group details
echo "<br/>";
foreach ($row as $key => $value){
echo "$whmcs_group_number $key: $value<br/>"; // Debug
$whmcs_hosting_groups["$whmcs_group_number"]["$key"] = $value;
}
$whmcs_group_number++;
}
echo "<br><b>Plans</b><br/>";
$default_currency='1';
$groupid='1';
# get a list of plans and store them in an array for Smarty
$result = mysql_query("
SELECT *, tblproducts.name AS prodname, tblproducts.id AS prodid
FROM tblproducts, tblproductgroups, tblpricing
WHERE tblpricing.type = 'product'
AND tblproducts.id = tblpricing.relid
AND tblpricing.currency = '$default_currency'
AND tblproducts.gid=tblproductgroups.id
AND tblproducts.type='hostingaccount'
AND (tblproducts.hidden != 'on' AND tblproductgroups.hidden != 'on')
AND tblproducts.gid='$groupid' ORDER BY tblproducts.id ASC
") or die(mysql_error());
$whmcs_plan_number = 0;
while($row = mysql_fetch_assoc($result)){
$whmcs_plans[] = $row; # $data is the array created for use in the Smarty template.
// populate multi-level array with individual hosting package details
echo "<br/>";
foreach ($row as $key => $value){
echo "$key: $value<br/>"; // Debug
$whmcs_plans_feature["$whmcs_plan_number"]["$key"] = $value;
}
$whmcs_plan_number++;
$num_plans++;
}
echo "<br/>Total Plans: $num_plans<br/>";
?>
Mark

Reply With Quote