|
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
|
|
|
'Order.Reference' => array( |
|
29
|
|
|
'filter' => 'PartialMatchFilter', |
|
30
|
|
|
'title' => 'Order No' |
|
31
|
|
|
), |
|
32
|
|
|
'Order.FirstName' => array( |
|
33
|
|
|
'filter' => 'PartialMatchFilter', |
|
34
|
|
|
'title' => 'First Name' |
|
35
|
|
|
), |
|
36
|
|
|
'Order.Email' => array( |
|
37
|
|
|
'filter' => 'PartialMatchFilter', |
|
38
|
|
|
'title' => 'Email' |
|
39
|
|
|
) |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
43
|
|
|
'Order.Reference' => 'Order No', |
|
44
|
|
|
'Created' => 'Created', |
|
45
|
|
|
'Order.Name' => 'Name', |
|
46
|
|
|
'Order.LatestEmail' => 'Email', |
|
47
|
|
|
'Title' => 'Title', |
|
48
|
|
|
'SentToCustomer' => 'Emailed' |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
private static $singular_name = "Order Log Entry"; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
private static $plural_name = "Order Status Log Entries"; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
private static $default_sort = "\"Created\" DESC"; |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function canDelete($member = null) |
|
59
|
|
|
{ |
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function canEdit($member = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
8 |
|
public function populateDefaults() |
|
69
|
|
|
{ |
|
70
|
8 |
|
parent::populateDefaults(); |
|
71
|
8 |
|
$this->updateWithLastInfo(); |
|
72
|
8 |
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
public function onBeforeWrite() |
|
75
|
|
|
{ |
|
76
|
4 |
|
parent::onBeforeWrite(); |
|
77
|
4 |
|
if (!$this->AuthorID && $memberID = Member::currentUserID()) { |
|
|
|
|
|
|
78
|
4 |
|
$this->AuthorID = $memberID; |
|
|
|
|
|
|
79
|
4 |
|
} |
|
80
|
4 |
|
if (!$this->Title) { |
|
|
|
|
|
|
81
|
|
|
$this->Title = "Order Update"; |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
4 |
|
} |
|
84
|
|
|
|
|
85
|
4 |
|
public function validate() |
|
86
|
|
|
{ |
|
87
|
4 |
|
$validationResult = parent::validate(); |
|
88
|
4 |
|
if (!$this->OrderID) { |
|
|
|
|
|
|
89
|
|
|
$validationResult->error('there is no order id for Order Status Log'); |
|
90
|
|
|
} |
|
91
|
4 |
|
return $validationResult; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
8 |
|
protected function updateWithLastInfo() |
|
95
|
|
|
{ |
|
96
|
8 |
|
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
|
8 |
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|