|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
5
|
|
|
* @package: ecommerce |
|
6
|
|
|
* @sub-package: model |
|
7
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
8
|
|
|
**/ |
|
9
|
|
|
class OrderStep_Sent extends OrderStep implements OrderStepInterface |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $emailClassName = 'Order_StatusEmail'; |
|
15
|
|
|
|
|
16
|
|
|
private static $db = array( |
|
|
|
|
|
|
17
|
|
|
'SendDetailsToCustomer' => 'Boolean', |
|
18
|
|
|
'EmailSubjectGift' => 'Varchar(200)', |
|
19
|
|
|
'CustomerMessageGift' => 'HTMLText' |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
23
|
|
|
'CustomerCanEdit' => 0, |
|
24
|
|
|
'CustomerCanCancel' => 0, |
|
25
|
|
|
'CustomerCanPay' => 0, |
|
26
|
|
|
'Name' => 'Send Order', |
|
27
|
|
|
'Code' => 'SENT', |
|
28
|
|
|
'ShowAsInProcessOrder' => 1 |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
private static $field_labels = [ |
|
|
|
|
|
|
32
|
|
|
'EmailSubjectGift' => 'Email subject', |
|
33
|
|
|
'CustomerMessageGift' => 'Customer message' |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The OrderStatusLog that is relevant to the particular step. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $relevantLogEntryClassName = 'OrderStatusLog_DispatchPhysicalOrder'; |
|
42
|
|
|
|
|
43
|
|
|
public function getCMSFields() |
|
44
|
|
|
{ |
|
45
|
|
|
$fields = parent::getCMSFields(); |
|
46
|
|
|
$fields->addFieldToTab('Root.Main', new HeaderField('ActuallySendDetails', _t('OrderStep.ACTUALLYSENDDETAILS', 'Send details to the customer?'), 3), 'SendDetailsToCustomer'); |
|
47
|
|
|
$fields->addFieldsToTab( |
|
48
|
|
|
'Root.CustomerMessage', |
|
49
|
|
|
[ |
|
50
|
|
|
HeaderField::create( |
|
51
|
|
|
'GiftHeader', |
|
52
|
|
|
_t('OrderStep.SEPARATE_DELIVERY', 'Message for separate shipping address ...') |
|
53
|
|
|
), |
|
54
|
|
|
TextField::create( |
|
55
|
|
|
'EmailSubjectGift', |
|
56
|
|
|
_t('OrderStep.EmailSubjectGift', 'Subject') |
|
57
|
|
|
), |
|
58
|
|
|
HTMLEditorField::create( |
|
59
|
|
|
'CustomerMessageGift', |
|
60
|
|
|
_t('OrderStep.CustomerMessageGift', 'Message') |
|
61
|
|
|
)->setRows(5) |
|
62
|
|
|
] |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
return $fields; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
*initStep: |
|
70
|
|
|
* makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
|
71
|
|
|
* should be able to run this function many times to check if the step is ready. |
|
72
|
|
|
* |
|
73
|
|
|
* @see Order::doNextStatus |
|
74
|
|
|
* |
|
75
|
|
|
* @param Order object |
|
76
|
|
|
* |
|
77
|
|
|
* @return bool - true if the current step is ready to be run... |
|
78
|
|
|
**/ |
|
79
|
|
|
public function initStep(Order $order) |
|
80
|
|
|
{ |
|
81
|
|
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
*doStep: |
|
86
|
|
|
* should only be able to run this function once |
|
87
|
|
|
* (init stops you from running it twice - in theory....) |
|
88
|
|
|
* runs the actual step. |
|
89
|
|
|
* |
|
90
|
|
|
* @see Order::doNextStatus |
|
91
|
|
|
* |
|
92
|
|
|
* @param Order object |
|
93
|
|
|
* |
|
94
|
|
|
* @return bool - true if run correctly. |
|
|
|
|
|
|
95
|
|
|
**/ |
|
96
|
|
|
public function doStep(Order $order) |
|
97
|
|
|
{ |
|
98
|
|
|
if ($this->RelevantLogEntry($order)) { |
|
99
|
|
|
return $this->sendEmailForStep( |
|
100
|
|
|
$order, |
|
101
|
|
|
$subject = $this->CalculatedEmailSubject($order), |
|
102
|
|
|
$message = $this->CalculatedCustomerMessage($order), |
|
103
|
|
|
$resend = false, |
|
104
|
|
|
$this->SendDetailsToCustomer ? false : true, |
|
|
|
|
|
|
105
|
|
|
$this->getEmailClassName() |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
*nextStep: |
|
112
|
|
|
* returns the next step (after it checks if everything is in place for the next step to run...). |
|
113
|
|
|
* |
|
114
|
|
|
* @see Order::doNextStatus |
|
115
|
|
|
* |
|
116
|
|
|
* @param Order $order |
|
117
|
|
|
* |
|
118
|
|
|
* @return OrderStep | Null (next step OrderStep object) |
|
|
|
|
|
|
119
|
|
|
**/ |
|
120
|
|
|
public function nextStep(Order $order) |
|
121
|
|
|
{ |
|
122
|
|
|
if (!$this->SendDetailsToCustomer || $this->hasBeenSent($order)) { |
|
|
|
|
|
|
123
|
|
|
return parent::nextStep($order); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. |
|
131
|
|
|
* |
|
132
|
|
|
* @param FieldList $fields |
|
133
|
|
|
* @param Order $order |
|
134
|
|
|
* |
|
135
|
|
|
* @return FieldList |
|
136
|
|
|
**/ |
|
137
|
|
|
public function addOrderStepFields(FieldList $fields, Order $order) |
|
138
|
|
|
{ |
|
139
|
|
|
$fields = parent::addOrderStepFields($fields, $order); |
|
140
|
|
|
$title = _t('OrderStep.MUSTENTERDISPATCHRECORD', ' ... To move this order to the next step please enter dispatch details.'); |
|
141
|
|
|
$fields->addFieldToTab('Root.Next', $order->getOrderStatusLogsTableField('OrderStatusLog_DispatchPhysicalOrder', $title), 'ActionNextStepManually'); |
|
142
|
|
|
|
|
143
|
|
|
return $fields; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* For some ordersteps this returns true... |
|
148
|
|
|
* |
|
149
|
|
|
* @return bool |
|
150
|
|
|
**/ |
|
151
|
|
|
protected function hasCustomerMessage() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->SendDetailsToCustomer; |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Explains the current order step. |
|
158
|
|
|
* |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
|
|
protected function myDescription() |
|
162
|
|
|
{ |
|
163
|
|
|
return _t('OrderStep.SENT_DESCRIPTION', 'During this step we record the delivery details for the order such as the courrier ticket number and whatever else is relevant.'); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function CalculatedEmailSubject($order = null) |
|
|
|
|
|
|
167
|
|
|
{ |
|
168
|
|
|
$v = null; |
|
169
|
|
|
if($order && $order->IsSeparateShippingAddress()) { |
|
170
|
|
|
$v = $this->EmailSubjectGift; |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
if(! $v) { |
|
173
|
|
|
$v = $this->EmailSubject; |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $v; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function CalculatedCustomerMessage($order = null) |
|
|
|
|
|
|
180
|
|
|
{ |
|
181
|
|
|
$v = null; |
|
182
|
|
|
if($order && $order->IsSeparateShippingAddress()) { |
|
183
|
|
|
$v = $this->CustomerMessageGift; |
|
|
|
|
|
|
184
|
|
|
} |
|
185
|
|
|
if(! $v) { |
|
186
|
|
|
$v = $this->CustomerMessage; |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
return $v; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
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.