Listview with Count of related records

Hi

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

Regards

Halooooom

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:

<?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:

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

require_once('include/MVC/View/views/view.detail.php');

class AccountsViewDetail extends ViewDetail {


 	function __construct(){
 		parent::__construct();
 	}
 	    function display(){
            $account = new Account(); 
            $account->retrieve($_REQUEST['record']); 
            $contacts = $account->get_linked_beans('contacts','Contact'); 

            $total = count($contacts);
        
            $this->bean->field_c = $total;
            parent::display();
    }
}

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.