/
EventListener.php
105 lines (93 loc) · 2.72 KB
/
EventListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Message\Mothership\Discount;
use Message\Cog\Event\SubscriberInterface;
use Message\Cog\Event\EventListener as BaseListener;
use Message\Mothership\Commerce\Order\Events as OrderEvents;
use Message\Mothership\Commerce\Order\Event\Event as OrderEvent;
use Message\Mothership\ControlPanel\Event\Dashboard\DashboardEvent;
use Message\Mothership\Report\Event as ReportEvents;
/**
* Event listener for core Mothership Discount functionality.
*
* @author Laurence Roberts <laurence@message.co.uk>
*/
class EventListener extends BaseListener implements SubscriberInterface
{
/**
* {@inheritDoc}
*/
static public function getSubscribedEvents()
{
return array(
OrderEvents::CREATE_COMPLETE => array(
array('recordDiscountRevenue'),
),
// OrderEvents::DELETE_END => array(
// array('recordDiscountRevenueDeleted'),
// ),
DashboardEvent::DASHBOARD_INDEX => array(
'buildDashboardIndex'
),
'dashboard.commerce.discounts' => array(
'buildDashboardDiscounts',
),
ReportEvents\Events::REGISTER_REPORTS => [
'registerReports'
],
);
}
/**
* Add controller references to the dashboard index.
*
* @param DashboardEvent $event
*/
public function buildDashboardIndex(DashboardEvent $event)
{
// $event->addReference('Message:Mothership:Discount::Controller:Module:Dashboard:DiscountRevenue#index');
}
/**
* Add controller references to the discounts dashboard.
*
* @param DashboardEvent $event
*/
public function buildDashboardDiscounts(DashboardEvent $event)
{
// $event->addReference('Message:Mothership:Discount::Controller:Module:Dashboard:DiscountRevenue#index');
}
/**
* Record the additional discount statistics if the order was discounted.
*
* @param Event\Event $event
*/
public function recordDiscountRevenue(OrderEvent $event)
{
$order = $event->getOrder();
if ($order->totalDiscount > 0) {
$this->get('statistics')->get('discounted.sales.gross')
->counter->increment($order->totalGross);
$this->get('statistics')->get('discount.gross')
->counter->increment($order->totalDiscount);
}
}
/**
* Decrement the additional discount statistics if the order was discounted.
*
* @param Event\Event $event
*/
public function recordDiscountRevenueDeleted(OrderEvent $event)
{
$order = $event->getOrder();
if ($order->totalDiscount > 0) {
$this->get('statistics')->get('discounted.sales.gross')
->counter->decrement($order->totalGross);
$this->get('statistics')->get('discount.gross')
->counter->decrement($order->totalDiscount);
}
}
public function registerReports(ReportEvents\BuildReportCollectionEvent $event)
{
foreach ($this->get('discount.reports') as $report) {
$event->registerReport($report);
}
}
}