Last active
January 4, 2016 05:39
-
-
Save GreatPotato/8576955 to your computer and use it in GitHub Desktop.
Adds top spending and top ordering customers widget to the dashboard
This file contains hidden or 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
| public function listDashboardReports() | |
| { | |
| return array( | |
| 'top_customers_revenue'=>array('partial'=>'top_customers_revenue.htm', 'name'=>'Top spending customers'), | |
| 'top_customers_orders'=>array('partial'=>'top_customers_orders.htm', 'name'=>'Top ordering customers') | |
| ); | |
| } |
This file contains hidden or 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
| <h2>Top Ordering Customers</h2> | |
| <?php | |
| $obj = new Shop_Customer(); | |
| $obj->select('COUNT(shop_orders.id) AS "total_orders"'); | |
| $obj->join('shop_orders', 'shop_orders.customer_id = shop_customers.id'); | |
| $obj->where('shop_orders.customer_id > 0'); | |
| $obj->where('shop_orders.payment_processed IS NOT NULL'); | |
| $obj->group('shop_orders.customer_id'); | |
| $obj->order('COUNT(shop_orders.customer_id) DESC'); | |
| $customers = $obj->limit(5)->find_all(); | |
| $row_num = count($customers); | |
| ?> | |
| <table class="simpleList"> | |
| <thead> | |
| <tr> | |
| <th>Instagram username</th> | |
| <th>Name</th> | |
| <th>Email address</th> | |
| <th class="float current last">Total</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <? if (!$row_num): ?> | |
| <tr class="noData"><td colspan="3"><no data></td></tr> | |
| <? else: ?> | |
| <? foreach ($customers as $index => $customer): ?> | |
| <?php $url = url('shop/customers/preview/'.$customer->id); ?> | |
| <tr class="<?= Backend_Html::zebra('top_customers_orders') ?> <?= $row_num-1 == $index ? 'last' : null ?>"> | |
| <td class="link" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->x_instagram_username ? '@'.$customer->x_instagram_username : ''; ?></a></td> | |
| <td class="link" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->first_name; ?> <?php echo $customer->last_name; ?></a></td> | |
| <td class="link" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->email; ?></a></td> | |
| <td class="float link last" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->total_orders ? $customer->total_orders : '0'; ?></a></td> | |
| </tr> | |
| <? endforeach ?> | |
| <? endif ?> | |
| </tbody> | |
| <tfoot> | |
| <tr> | |
| <td> </td> | |
| <td> </td> | |
| <td> </td> | |
| <td class="last"> </td> | |
| </tr> | |
| </tfoot> | |
| </table> |
This file contains hidden or 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
| <h2>Top Spending Customers</h2> | |
| <?php | |
| $obj = new Shop_Customer(); | |
| $obj->select('SUM(shop_orders.total) AS "total_revenue"'); | |
| $obj->join('shop_orders', 'shop_orders.customer_id = shop_customers.id'); | |
| $obj->where('shop_orders.customer_id > 0'); | |
| $obj->where('shop_orders.payment_processed IS NOT NULL'); | |
| $obj->group('shop_orders.customer_id'); | |
| $obj->order('SUM(shop_orders.total) DESC'); | |
| $customers = $obj->limit(5)->find_all(); | |
| $row_num = count($customers); | |
| ?> | |
| <table class="simpleList"> | |
| <thead> | |
| <tr> | |
| <th>Instagram username</th> | |
| <th>Name</th> | |
| <th>Email address</th> | |
| <th class="float current last">Total</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <? if (!$row_num): ?> | |
| <tr class="noData"><td colspan="3"><no data></td></tr> | |
| <? else: ?> | |
| <? foreach ($customers as $index => $customer): ?> | |
| <?php $url = url('shop/customers/preview/'.$customer->id); ?> | |
| <tr class="<?= Backend_Html::zebra('top_customers_revenue') ?> <?= $row_num-1 == $index ? 'last' : null ?>"> | |
| <td class="link" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->x_instagram_username ? '@'.$customer->x_instagram_username : ''; ?></a></td> | |
| <td class="link"<?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->first_name; ?> <?php echo $customer->last_name; ?></a></td> | |
| <td class="link"<?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->email; ?></a></td> | |
| <td class="float link last" <?= click_link($url) ?>><a href="<?= $url ?>"><?php echo $customer->total_revenue ? $customer->total_revenue : '0.00'; ?></a></td> | |
| </tr> | |
| <? endforeach ?> | |
| <? endif ?> | |
| </tbody> | |
| <tfoot> | |
| <tr> | |
| <td> </td> | |
| <td> </td> | |
| <td> </td> | |
| <td class="last"> </td> | |
| </tr> | |
| </tfoot> | |
| </table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment