I have a table name stat_customer
look like this:
I want to add a column page_view
to customer collection to show at grid page. page_view
is total page view of product page for each customer. My SQL query looks like:
SELECT sum(
page_view
) as page_view, customer_id FROMstat_customer
WHEREpage_type
= 'product' GROUP BYcustomer_id
;
But I don't know how to join it with customer collection. Can anyone help me please ?
UPDATE
I'm trying this way:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left');
$collection->addExpressionAttributeToSelect("page_view", "sum({{page_view}})", "page_view");
$collection->groupByAttribute("page_view");
$this->setCollection($collection);
return parent::_prepareCollection();
}
But getting this error:
Fatal error: Call to a member function getBackend() on a non-object in E:\XAMPP\htdocs\stat\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php on line 513
page_view
calculated by my query to customer grid.