Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Created June 29, 2015 09:51
Show Gist options
  • Save GreatPotato/c62ff3b4abdffc8488e5 to your computer and use it in GitHub Desktop.
Save GreatPotato/c62ff3b4abdffc8488e5 to your computer and use it in GitHub Desktop.
<?php
class My_Module extends Core_ModuleBase
{
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onExtendCustomerModel', $this, 'extend_customer_model');
}
public function extend_customer_model($customer, $context)
{
$total_orders = 'SELECT COUNT(shop_orders.id) FROM shop_orders WHERE shop_orders.customer_id = shop_customers.id';
$customer->define_column('total_orders', 'Total orders');
$customer->calculated_columns['total_orders'] = array(
'sql' => $total_orders,
'type' => db_number
);
$total_spend = 'SELECT IFNULL(SUM(shop_orders.total), 0) FROM shop_orders WHERE shop_orders.customer_id = shop_customers.id';
$customer->define_column('total_spend', 'Total spend')->currency(true);
$customer->calculated_columns['total_spend'] = array(
'sql' => $total_spend,
'type' => db_float
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment