1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EcommerceDashboardPanel_OrderCount extends EcommerceDashboardPanel |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $icon = "ecommerce_dashboard/images/icons/EcommerceDashboardPanel_OrderCount.png"; |
|
|
|
|
6
|
|
|
|
7
|
|
|
private static $has_one = array( |
|
|
|
|
8
|
|
|
'EcommerceCurrency' => 'EcommerceCurrency' |
9
|
|
|
); |
10
|
|
|
|
11
|
|
|
public function getLabelPrefix() |
12
|
|
|
{ |
13
|
|
|
$currencyStatement = ''; |
14
|
|
View Code Duplication |
if ($currency = $this->EcommerceCurrency()) { |
|
|
|
|
15
|
|
|
if ($currency->exists()) { |
16
|
|
|
$currencyStatement = ", in ".$currency->Code.', '; |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
return 'Orders Placed'.$currencyStatement; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public function getConfiguration() |
24
|
|
|
{ |
25
|
|
|
$fields = parent::getConfiguration(); |
26
|
|
|
$fields->push( |
27
|
|
|
DropdownField::create( |
28
|
|
|
"EcommerceCurrencyID", |
29
|
|
|
"Currency", |
30
|
|
|
EcommerceCurrency::get()->map() |
31
|
|
|
) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
return $fields; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function Content() |
38
|
|
|
{ |
39
|
|
|
$submittedOrders = $this->submittedOrders(); |
40
|
|
|
$submittedOrders = $submittedOrders->filter(array('CurrencyUsedID' => $this->EcommerceCurrencyID)); |
|
|
|
|
41
|
|
|
$count = $submittedOrders->count(); |
42
|
|
|
$sum = 0; |
43
|
|
|
$itemCount = 0; |
44
|
|
|
$html = ' |
45
|
|
|
<dl>'; |
46
|
|
|
$html .= ' |
47
|
|
|
<dt>Count of orders</dt> |
48
|
|
|
<dd>'.$count.'</dd>'; |
49
|
|
|
if ($count < $this->maxOrdersForLoop() && $count > 0) { |
50
|
|
|
foreach ($submittedOrders as $order) { |
51
|
|
|
$sum += $order->getSubTotal(); |
52
|
|
|
$itemCount += $order->getTotalItemsTimesQuantity(); |
53
|
|
|
} |
54
|
|
|
$sumDBField = DBField::create_field('Currency', $sum); |
55
|
|
|
$html .= ' |
56
|
|
|
<dt>Sum of sub-totals</dt> |
57
|
|
|
<dd>'.$sumDBField->Nice().'</dd>'; |
58
|
|
|
$averagePerOrder = ($sum / $count); |
59
|
|
|
$averagePerOrderDBField = DBField::create_field('Currency', $averagePerOrder); |
60
|
|
|
$html .= ' |
61
|
|
|
<dt>Average sub-total per order</dt> |
62
|
|
|
<dd>'.$averagePerOrderDBField->Nice().'</dd>'; |
63
|
|
|
$html .= ' |
64
|
|
|
<dt>Total count of items sold</dt> |
65
|
|
|
<dd>'.$itemCount.'</dd>'; |
66
|
|
|
$itemCountPerOrder = round($itemCount / $count, 3); |
67
|
|
|
$html .= ' |
68
|
|
|
<dt>Average items sold per order</dt> |
69
|
|
|
<dd>'.$itemCountPerOrder.'</dd>'; |
70
|
|
|
$costPerItem = $sum / $itemCount; |
71
|
|
|
$costPerItemDBField = DBField::create_field('Currency', $costPerItem); |
72
|
|
|
$html .= ' |
73
|
|
|
<dt>Average cost per item</dt> |
74
|
|
|
<dd>'.$costPerItemDBField->Nice().'</dd>'; |
75
|
|
|
} elseif ($count >= $this->maxOrdersForLoop()) { |
76
|
|
|
$html .= ' |
77
|
|
|
<dt>Sum of sub-totals</dt> |
78
|
|
|
<dd>Please reduce the number of orders to calculate the total.</dd>'; |
79
|
|
|
} else { |
|
|
|
|
80
|
|
|
//.. |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
$html .= ' |
85
|
|
|
</dl>'; |
86
|
|
|
|
87
|
|
|
return $html; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.