1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Data class that keeps a log of a single |
5
|
|
|
* status of an order. |
6
|
|
|
* |
7
|
|
|
* @package shop |
8
|
|
|
*/ |
9
|
|
|
class OrderStatusLog extends DataObject |
10
|
|
|
{ |
11
|
|
|
private static $db = array( |
|
|
|
|
12
|
|
|
'Title' => 'Varchar(100)', |
13
|
|
|
'Note' => 'Text', |
14
|
|
|
'DispatchedBy' => 'Varchar(100)', |
15
|
|
|
'DispatchedOn' => 'Date', |
16
|
|
|
'DispatchTicket' => 'Varchar(100)', |
17
|
|
|
'PaymentCode' => 'Varchar(100)', |
18
|
|
|
'PaymentOK' => 'Boolean', |
19
|
|
|
'SentToCustomer' => 'Boolean', |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
private static $has_one = array( |
|
|
|
|
23
|
|
|
'Author' => 'Member', |
24
|
|
|
'Order' => 'Order', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private static $searchable_fields = array( |
|
|
|
|
28
|
|
|
"Note" => "PartialMatchFilter", |
29
|
|
|
'DispatchTicket' => 'PartialMatchFilter', |
30
|
|
|
'PaymentCode' => 'PartialMatchFilter', |
31
|
|
|
'PaymentOK', |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
private static $summary_fields = array( |
|
|
|
|
35
|
|
|
"Created" => "Date", |
36
|
|
|
"OrderID" => "OrderID", |
37
|
|
|
"Title" => "Title", |
38
|
|
|
"SentToCustomer" => "SentToCustomer", |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
private static $field_labels = array( |
|
|
|
|
42
|
|
|
"SentToCustomer" => "Send this update as a message to the customer", |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
private static $singular_name = "Order Log Entry"; |
|
|
|
|
46
|
|
|
|
47
|
|
|
private static $plural_name = "Order Status Log Entries"; |
|
|
|
|
48
|
|
|
|
49
|
|
|
private static $default_sort = "\"Created\" DESC"; |
|
|
|
|
50
|
|
|
|
51
|
|
|
public function canDelete($member = null) |
52
|
|
|
{ |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function canEdit($member = null) |
57
|
|
|
{ |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
5 |
|
public function populateDefaults() |
62
|
|
|
{ |
63
|
5 |
|
parent::populateDefaults(); |
64
|
5 |
|
$this->updateWithLastInfo(); |
65
|
5 |
|
} |
66
|
|
|
|
67
|
1 |
|
public function onBeforeWrite() |
68
|
|
|
{ |
69
|
1 |
|
parent::onBeforeWrite(); |
70
|
1 |
|
if (!$this->AuthorID && $memberID = Member::currentUserID()) { |
|
|
|
|
71
|
1 |
|
$this->AuthorID = $memberID; |
|
|
|
|
72
|
1 |
|
} |
73
|
1 |
|
if (!$this->Title) { |
|
|
|
|
74
|
|
|
$this->Title = "Order Update"; |
|
|
|
|
75
|
|
|
} |
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
public function validate() |
79
|
|
|
{ |
80
|
1 |
|
$validationResult = parent::validate(); |
81
|
1 |
|
if (!$this->OrderID) { |
|
|
|
|
82
|
|
|
$validationResult->error('there is no order id for Order Status Log'); |
83
|
|
|
} |
84
|
1 |
|
return $validationResult; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function onAfterWrite() |
88
|
|
|
{ |
89
|
1 |
|
if ($this->SentToCustomer) { |
|
|
|
|
90
|
|
|
$this->order()->notifier->sendStatusChange($this->Title, $this->Note); |
|
|
|
|
91
|
|
|
} |
92
|
1 |
|
} |
93
|
|
|
|
94
|
5 |
|
protected function updateWithLastInfo() |
95
|
|
|
{ |
96
|
5 |
|
if ($this->OrderID) { |
|
|
|
|
97
|
|
|
if ( |
98
|
1 |
|
$latestLog = OrderStatusLog::get()->filter('OrderID', $this->OrderID)->sort('Created', 'DESC')->first() |
|
|
|
|
99
|
1 |
|
) { |
100
|
|
|
$this->DispatchedBy = $latestLog->DispatchedBy; |
|
|
|
|
101
|
|
|
$this->DispatchedOn = $latestLog->DispatchedOn; |
|
|
|
|
102
|
|
|
$this->DispatchTicket = $latestLog->DispatchTicket; |
|
|
|
|
103
|
|
|
$this->PaymentCode = $latestLog->PaymentCode; |
|
|
|
|
104
|
|
|
$this->PaymentOK = $latestLog->PaymentOK; |
|
|
|
|
105
|
|
|
} |
106
|
1 |
|
} |
107
|
5 |
|
} |
108
|
|
|
} |
109
|
|
|
|