Forked from GreatPotato/gist:c62ff3b4abdffc8488e5
Last active
August 29, 2015 14:23
-
-
Save snetty/5584a5f80e1dfea27acf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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