Listview with Count of related records


I’m using the ‘Product’ and ‘Product Categories’ modules

It would be great to see for each category in Listview, how many Products are in this category. Is this already possible in Version 7.10.4



You can see the amount of products in the subpanel as well, but if you want to see it in a custom field for example, you can do something like I did here to count users into related account.

create in custom / modules / the file logic_hooks_class.php:

    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
        class logic_hooks_class     {         
        function before_save_method($bean, $event, $arguments)         

            $query = "SELECT COUNT(*) FROM contacts WHERE deleted = 0";
            $result = $GLOBALS['db']->getOne($query);            
            $bean->field_c = $bean->field_c + $result; 


And in custom / modules / / views within view.detail.php:

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');


class AccountsViewDetail extends ViewDetail {

 	function __construct(){
 	    function display(){
            $account = new Account(); 
            $contacts = $account->get_linked_beans('contacts','Contact'); 

            $total = count($contacts);
            $this->bean->field_c = $total;

In the case of the above example, as I mentioned before, it was created for accounts -> contacts, you can do the same just by changing the paths.