Fli
11-25-2014, 03:56 PM
Change products sorting on WHMCS Upgrade page + show product descriptions
At a time im writing this, WHMCS client area / upgrade page lists hosting packages from several groups in bad order and dont showing descriptions of these packages.
To set order according to category, then according to package id, follow this tutorial. Backup already existing files before modiffications.
create new file in:
/includes/classes/Smarty/plugins
or in:
/includes/smarty/plugins
(create file in one directory which do exist)
filename: modifier.sortby.php
file content:
<?php## sorts an array of named arrays by the supplied fields
function array_sort_by_fields(&$data, $sortby){ static $sort_funcs = array(); if (empty($sort_funcs[$sortby])) { $code = "\$c=0;"; foreach (split(',', $sortby) as $key) { $d = '1'; if (substr($key, 0, 1) == '-') { $d = '-1'; $key = substr($key, 1); } if (substr($key, 0, 1) == '#') { $key = substr($key, 1); $code .= "if ( \$a['$key'] > \$b['$key']) return $d * 1;\n";$code .= "if ( \$a['$key'] < \$b['$key']) return $d * -1;\n"; } else { $code .= "if ( (\$c = strcasecmp(\$a['$key'],\$b['$key'])) != 0 ) return $d * \$c;\n"; } } $code .= 'return $c;'; $sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code); } else { $sort_func = $sort_funcs[$sortby]; } uasort($data, $sort_func); }
## Modifier: sortby - allows arrays of named arrays to be sorted by a given field#
function smarty_modifier_sortby($arrData, $sortfields) { array_sort_by_fields($arrData, $sortfields); return $arrData;}
Then modiffy upgrade.tpl file that is located in your template folder /templates/templatename/
find:
{foreach key=num item=upgradepackage from=$upgradepackages}
replace by:
{foreach key=num item=upgradepackage from=$upgradepackages|@sortby:"gid,pid"}
to show description:
replace:
<strong>{$upgradepackage.groupname} - {$upgradepackage.name}</strong>
by:
<strong>{$upgradepackage.groupname} - {$upgradepackage.name}</strong>
<br>{$upgradepackage.description}
to truncate description:
{$upgradepackage.description|truncate:50}
At a time im writing this, WHMCS client area / upgrade page lists hosting packages from several groups in bad order and dont showing descriptions of these packages.
To set order according to category, then according to package id, follow this tutorial. Backup already existing files before modiffications.
create new file in:
/includes/classes/Smarty/plugins
or in:
/includes/smarty/plugins
(create file in one directory which do exist)
filename: modifier.sortby.php
file content:
<?php## sorts an array of named arrays by the supplied fields
function array_sort_by_fields(&$data, $sortby){ static $sort_funcs = array(); if (empty($sort_funcs[$sortby])) { $code = "\$c=0;"; foreach (split(',', $sortby) as $key) { $d = '1'; if (substr($key, 0, 1) == '-') { $d = '-1'; $key = substr($key, 1); } if (substr($key, 0, 1) == '#') { $key = substr($key, 1); $code .= "if ( \$a['$key'] > \$b['$key']) return $d * 1;\n";$code .= "if ( \$a['$key'] < \$b['$key']) return $d * -1;\n"; } else { $code .= "if ( (\$c = strcasecmp(\$a['$key'],\$b['$key'])) != 0 ) return $d * \$c;\n"; } } $code .= 'return $c;'; $sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code); } else { $sort_func = $sort_funcs[$sortby]; } uasort($data, $sort_func); }
## Modifier: sortby - allows arrays of named arrays to be sorted by a given field#
function smarty_modifier_sortby($arrData, $sortfields) { array_sort_by_fields($arrData, $sortfields); return $arrData;}
Then modiffy upgrade.tpl file that is located in your template folder /templates/templatename/
find:
{foreach key=num item=upgradepackage from=$upgradepackages}
replace by:
{foreach key=num item=upgradepackage from=$upgradepackages|@sortby:"gid,pid"}
to show description:
replace:
<strong>{$upgradepackage.groupname} - {$upgradepackage.name}</strong>
by:
<strong>{$upgradepackage.groupname} - {$upgradepackage.name}</strong>
<br>{$upgradepackage.description}
to truncate description:
{$upgradepackage.description|truncate:50}