|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This call can be used when you need input from the customer |
|
5
|
|
|
* in the order process. |
|
6
|
|
|
* |
|
7
|
|
|
* To use |
|
8
|
|
|
* |
|
9
|
|
|
* 1. create class that extends OrderStepController |
|
10
|
|
|
* 2. make sure the class has a $url_segment static var |
|
11
|
|
|
* 3. create content and/or form for page |
|
12
|
|
|
* 4. make sure you set up route (route.yml) to get to the |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class OrderStepController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
17
|
|
|
'error' => true, |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $alternativeContent = ""; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* when no action is selected |
|
27
|
|
|
* this action runs... |
|
28
|
|
|
*/ |
|
29
|
|
|
public function index($request) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->alternativeContent = '<p class="message bad">Sorry, we can not find the page you are looking for.</p>'; |
|
32
|
|
|
|
|
33
|
|
|
return $this->renderWith('Page'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* there is an error ... |
|
38
|
|
|
*/ |
|
39
|
|
|
public function error($request) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$this->alternativeContent = '<p class="message bad">Sorry, an error occurred, please contact us for more information....</p>'; |
|
42
|
|
|
|
|
43
|
|
|
return $this->renderWith('Page'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected static function name_of_controller_class() |
|
50
|
|
|
{ |
|
51
|
|
|
return get_called_class(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param Order $order |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected static function secure_hash($order) |
|
60
|
|
|
{ |
|
61
|
|
|
$obj = Injector::inst()->get(self::name_of_controller_class()); |
|
62
|
|
|
|
|
63
|
|
|
return $obj->secureHash($order); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function nameOfControllerClass() |
|
70
|
|
|
{ |
|
71
|
|
|
return self::name_of_controller_class(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* related OrderStatusLog class. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
abstract protected function nameOfLogClass(); |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* main content ... |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function Content($order = null) |
|
87
|
|
|
{ |
|
88
|
|
|
if ($this->alternativeContent) { |
|
89
|
|
|
return $this->alternativeContent; |
|
90
|
|
|
} |
|
91
|
|
|
return $this->standardContent($order); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string ($html) |
|
|
|
|
|
|
96
|
|
|
*/ |
|
97
|
|
|
protected function standardContent($order = null) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
user_error("Make sure to put some content here in classes that extend ".$this->class); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* the form on the field. |
|
104
|
|
|
* |
|
105
|
|
|
* @return Form |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function Form() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->Form; |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* code of related order step. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
abstract protected function codeOfRelevantOrderStep(); |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* used to secure page. |
|
121
|
|
|
* |
|
122
|
|
|
* @param Order $order |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
abstract protected function secureHash($order); |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @oaram string $action |
|
130
|
|
|
* |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public function Link($action = null) |
|
134
|
|
|
{ |
|
135
|
|
|
$link = '/'.Config::inst()->get($this->nameOfControllerClass(), 'url_segment').'/'; |
|
136
|
|
|
if ($action) { |
|
137
|
|
|
$link = $link.$action.'/'; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $link.$this->getOrderGetParams(); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function errorLink() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->Link('error'); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* is the order valid? |
|
150
|
|
|
* |
|
151
|
|
|
* @return bool |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function checkOrder($dataOrRequest = null) |
|
154
|
|
|
{ |
|
155
|
|
|
$order = $this->Order($dataOrRequest); |
|
156
|
|
|
if ($order && $order->exists()) { |
|
|
|
|
|
|
157
|
|
|
return true; |
|
158
|
|
|
} else { |
|
159
|
|
|
return false; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @var Order |
|
165
|
|
|
*/ |
|
166
|
|
|
private static $_order = null; |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* finds the order ... |
|
170
|
|
|
* |
|
171
|
|
|
* @param mixed |
|
172
|
|
|
* |
|
173
|
|
|
* @return Order |
|
|
|
|
|
|
174
|
|
|
*/ |
|
175
|
|
|
protected function Order($dataOrRequest = null) |
|
176
|
|
|
{ |
|
177
|
|
|
if (!self::$_order) { |
|
178
|
|
|
if ( |
|
179
|
|
|
is_array($dataOrRequest) && |
|
180
|
|
|
isset($dataOrRequest['OrderID']) && |
|
181
|
|
|
isset($dataOrRequest['OrderSessionID']) |
|
182
|
|
|
) { |
|
183
|
|
|
$id = intval($dataOrRequest['OrderID']); |
|
184
|
|
|
$sessionID = Convert::raw2sql($dataOrRequest['OrderSessionID']); |
|
185
|
|
|
} elseif (isset($_POST['OrderID']) && isset($_POST['OrderSessionID'])) { |
|
186
|
|
|
$id = intval($_POST['OrderID']); |
|
187
|
|
|
$sessionID = Convert::raw2sql($_POST['OrderSessionID']); |
|
188
|
|
|
} elseif (isset($_GET['OrderID']) && isset($_GET['OrderSessionID'])) { |
|
189
|
|
|
$id = intval($_GET['OrderID']); |
|
190
|
|
|
$sessionID = Convert::raw2sql($_GET['OrderSessionID']); |
|
191
|
|
|
} elseif ($dataOrRequest instanceof SS_HTTPRequest) { |
|
192
|
|
|
$id = intval($dataOrRequest->param('ID')); |
|
193
|
|
|
$sessionID = Convert::raw2sql($dataOrRequest->param('OtherID')); |
|
194
|
|
|
} else { |
|
195
|
|
|
$id = intval($this->request->param('ID')); |
|
196
|
|
|
$sessionID = Convert::raw2sql($this->request->param('OtherID')); |
|
197
|
|
|
} |
|
198
|
|
|
self::$_order = Order::get()->byID($id); |
|
|
|
|
|
|
199
|
|
|
if (self::$_order) { |
|
200
|
|
|
if ($this->secureHash(self::$_order) != $sessionID) { |
|
|
|
|
|
|
201
|
|
|
self::$_order = null; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return self::$_order; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @return string |
|
|
|
|
|
|
211
|
|
|
*/ |
|
212
|
|
|
protected function getOrderGetParams() |
|
213
|
|
|
{ |
|
214
|
|
|
if ($order = $this->Order()) { |
|
215
|
|
|
return '?OrderID='.$order->ID.'&OrderSessionID='.self::secure_hash($order); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return OrderStep |
|
221
|
|
|
*/ |
|
222
|
|
|
protected function orderStep() |
|
223
|
|
|
{ |
|
224
|
|
|
return DataObject::get_one( |
|
225
|
|
|
'OrderStep', |
|
226
|
|
|
array('Code' => $this->codeOfRelevantOrderStep()) |
|
227
|
|
|
); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|