1
|
|
|
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Class EE_Checkout |
5
|
|
|
* |
6
|
|
|
* Description |
7
|
|
|
* |
8
|
|
|
* @package Event Espresso |
9
|
|
|
* @subpackage core |
10
|
|
|
* @author Brent Christensen |
11
|
|
|
* @since 4.5.0 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class EE_Checkout { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* whether current request originated from the EE admin |
18
|
|
|
* @type bool |
19
|
|
|
*/ |
20
|
|
|
public $admin_request = FALSE; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* whether returning to edit attendee information or to retry a payment |
24
|
|
|
* @type bool |
25
|
|
|
*/ |
26
|
|
|
public $revisit = FALSE; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* whether the primary registrant is returning to edit attendee information or to retry a payment |
30
|
|
|
* @type bool |
31
|
|
|
*/ |
32
|
|
|
public $primary_revisit = FALSE; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* is registration allowed to progress or halted for some reason such as failing to pass recaptcha? |
36
|
|
|
* @type bool |
37
|
|
|
*/ |
38
|
|
|
public $continue_reg = TRUE; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* redirect to thank you page ? |
42
|
|
|
* @type bool |
43
|
|
|
*/ |
44
|
|
|
public $redirect = FALSE; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* generate the reg form or not ? |
48
|
|
|
* @type bool |
49
|
|
|
*/ |
50
|
|
|
public $generate_reg_form = TRUE; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* process a reg form submission or not ? |
54
|
|
|
* @type bool |
55
|
|
|
*/ |
56
|
|
|
public $process_form_submission = FALSE; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* tracks whether the TXN status modified during this checkout |
60
|
|
|
* |
61
|
|
|
* @type bool |
62
|
|
|
*/ |
63
|
|
|
public $txn_status_updated = FALSE; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* only triggered to true after absolutely everything has finished. |
67
|
|
|
* |
68
|
|
|
* @type bool |
69
|
|
|
*/ |
70
|
|
|
protected $exit_spco = FALSE; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* tracks whether any of the TXN's Registrations statuses modified during this checkout |
74
|
|
|
* indexed by registration ID |
75
|
|
|
* |
76
|
|
|
* @type array |
77
|
|
|
*/ |
78
|
|
|
protected $reg_status_updated = array(); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* total number of tickets that were in the cart |
82
|
|
|
* @type int |
83
|
|
|
*/ |
84
|
|
|
public $total_ticket_count = 0; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* corresponds loosely to EE_Transaction::remaining() |
88
|
|
|
* but can be modified by SPCO |
89
|
|
|
* |
90
|
|
|
* @type float |
91
|
|
|
*/ |
92
|
|
|
public $amount_owing = 0; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* the reg step slug from the incoming request |
96
|
|
|
* @type string |
97
|
|
|
*/ |
98
|
|
|
public $step = ''; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* the reg step slug for a step being edited |
102
|
|
|
* @type string |
103
|
|
|
*/ |
104
|
|
|
public $edit_step = ''; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* the action being performed on the current step |
108
|
|
|
* @type string |
109
|
|
|
*/ |
110
|
|
|
public $action = ''; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* reg_url_link for a previously saved registration |
114
|
|
|
* @type string |
115
|
|
|
*/ |
116
|
|
|
public $reg_url_link = ''; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* string slug for the payment method that was selected during the payment options step |
120
|
|
|
* @type string |
121
|
|
|
*/ |
122
|
|
|
public $selected_method_of_payment = ''; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* base url for the site's registration checkout page - additional url params will be added to this |
126
|
|
|
* @type string |
127
|
|
|
*/ |
128
|
|
|
public $reg_page_base_url = ''; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* base url for the site's registration cancelled page - additional url params will be added to this |
132
|
|
|
* @type string |
133
|
|
|
*/ |
134
|
|
|
public $cancel_page_url = ''; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* base url for the site's thank you page - additional url params will be added to this |
138
|
|
|
* @type string |
139
|
|
|
*/ |
140
|
|
|
public $thank_you_page_url = ''; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* base url for any redirects - additional url params will be added to this |
144
|
|
|
* @type string |
145
|
|
|
*/ |
146
|
|
|
public $redirect_url = ''; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* form of POST data for use with off-site gateways |
150
|
|
|
* @type string |
151
|
|
|
*/ |
152
|
|
|
public $redirect_form = ''; |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* array of query where params to use when retrieving cached registrations from $this->checkout->transaction |
156
|
|
|
* @type array |
157
|
|
|
*/ |
158
|
|
|
public $reg_cache_where_params = array(); |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX requests |
162
|
|
|
* @type EE_SPCO_JSON_Response |
163
|
|
|
*/ |
164
|
|
|
public $json_response; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* where we are going next in the reg process |
168
|
|
|
* @type EE_SPCO_Reg_Step |
169
|
|
|
*/ |
170
|
|
|
public $next_step; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* where we are in the reg process |
174
|
|
|
* @type EE_SPCO_Reg_Step |
175
|
|
|
*/ |
176
|
|
|
public $current_step; |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* $_cart - the current cart object |
180
|
|
|
* @var EE_CART |
181
|
|
|
*/ |
182
|
|
|
public $cart; |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* $_transaction - the current transaction object |
186
|
|
|
* @var EE_Transaction |
187
|
|
|
*/ |
188
|
|
|
public $transaction; |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* the related attendee object for the primary registrant |
192
|
|
|
* @type EE_Attendee |
193
|
|
|
*/ |
194
|
|
|
public $primary_attendee_obj; |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* $payment_method - the payment method object for the selected method of payment |
198
|
|
|
* @type EE_Payment_Method |
199
|
|
|
*/ |
200
|
|
|
public $payment_method; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* $payment - if a payment was successfully made during the reg process, |
204
|
|
|
* then here it is !!! |
205
|
|
|
* @type EE_Payment |
206
|
|
|
*/ |
207
|
|
|
public $payment; |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* if a payment method was selected that uses an on-site gateway, then this is the billing form |
211
|
|
|
* @type EE_Billing_Info_Form | EE_Billing_Attendee_Info_Form |
212
|
|
|
*/ |
213
|
|
|
public $billing_form; |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* the entire registration form composed of ALL of the subsections generated by the various reg steps |
217
|
|
|
* @type EE_Form_Section_Proper |
218
|
|
|
*/ |
219
|
|
|
public $registration_form; |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* array of EE_SPCO_Reg_Step objects |
223
|
|
|
* @type EE_SPCO_Reg_Step[] |
224
|
|
|
*/ |
225
|
|
|
public $reg_steps = array(); |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* array of EE_Payment_Method objects |
229
|
|
|
* @type EE_Payment_Method[] |
230
|
|
|
*/ |
231
|
|
|
public $available_payment_methods = array(); |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* class constructor |
237
|
|
|
* |
238
|
|
|
* @access public |
239
|
|
|
* @return \EE_Checkout |
|
|
|
|
240
|
|
|
*/ |
241
|
|
|
public function __construct( ) { |
242
|
|
|
$this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
|
|
|
|
243
|
|
|
$this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
244
|
|
|
$this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
245
|
|
|
$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE ); |
246
|
|
|
$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax; |
247
|
|
|
$this->reg_cache_where_params = array( 'order_by' => array( 'REG_count' => 'ASC' )); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* returns true if ANY reg status was updated during checkout |
254
|
|
|
* @return array |
255
|
|
|
*/ |
256
|
|
|
public function any_reg_status_updated() { |
257
|
|
|
foreach ( $this->reg_status_updated as $reg_status ) { |
258
|
|
|
if ( $reg_status ) { |
259
|
|
|
return true; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
return false; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param $REG_ID |
269
|
|
|
* @return array |
270
|
|
|
*/ |
271
|
|
|
public function reg_status_updated( $REG_ID ) { |
272
|
|
|
return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
|
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param $REG_ID |
279
|
|
|
* @param $reg_status |
280
|
|
|
*/ |
281
|
|
|
public function set_reg_status_updated( $REG_ID, $reg_status ) { |
282
|
|
|
$this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN ); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* exit_spco |
289
|
|
|
* |
290
|
|
|
* @return bool |
291
|
|
|
*/ |
292
|
|
|
public function exit_spco() { |
293
|
|
|
return $this->exit_spco; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* set_exit_spco |
300
|
|
|
* can ONLY be set by the Finalize_Registration reg step |
301
|
|
|
*/ |
302
|
|
|
public function set_exit_spco() { |
303
|
|
|
if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
304
|
|
|
$this->exit_spco = true; |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* reset_for_current_request |
314
|
|
|
* |
315
|
|
|
* @access public |
316
|
|
|
* @return void |
317
|
|
|
*/ |
318
|
|
|
public function reset_for_current_request() { |
319
|
|
|
$this->process_form_submission = FALSE; |
320
|
|
|
$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true ); |
321
|
|
|
$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax; |
322
|
|
|
$this->continue_reg = true; |
323
|
|
|
$this->redirect = false; |
324
|
|
|
// don't reset the cached redirect form if we're about to be asked to display it !!! |
325
|
|
|
if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) { |
326
|
|
|
$this->redirect_form = ''; |
327
|
|
|
} |
328
|
|
|
$this->redirect_url = ''; |
329
|
|
|
$this->json_response = new EE_SPCO_JSON_Response(); |
330
|
|
|
EE_Form_Section_Proper::reset_js_localization(); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
|
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* add_reg_step |
337
|
|
|
* |
338
|
|
|
* @access public |
339
|
|
|
* @param EE_SPCO_Reg_Step $reg_step_obj |
340
|
|
|
* @return void |
341
|
|
|
*/ |
342
|
|
|
public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) { |
343
|
|
|
$this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* skip_reg_step |
350
|
|
|
* if the current reg step does not need to run for some reason, |
351
|
|
|
* then this will advance SPCO to the next reg step, |
352
|
|
|
* and mark the skipped step as completed |
353
|
|
|
* |
354
|
|
|
* @access public |
355
|
|
|
* @param string $reg_step_slug |
356
|
|
|
* @return void |
357
|
|
|
* @throws \EE_Error |
358
|
|
|
*/ |
359
|
|
|
public function skip_reg_step( $reg_step_slug = '' ) { |
360
|
|
|
$step_to_skip = $this->find_reg_step( $reg_step_slug ); |
361
|
|
|
if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) { |
362
|
|
|
$step_to_skip->set_is_current_step( false ); |
363
|
|
|
$step_to_skip->set_completed(); |
364
|
|
|
// advance to the next step |
365
|
|
|
$this->set_current_step( $this->next_step->slug() ); |
366
|
|
|
// also reset the step param in the request in case any other code references that directly |
367
|
|
|
EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() ); |
368
|
|
|
// since we are skipping a step and setting the current step to be what was previously the next step, |
369
|
|
|
// we need to check that the next step is now correct, and not still set to the current step. |
370
|
|
|
if ( $this->current_step->slug() === $this->next_step->slug() ) { |
371
|
|
|
// correctly setup the next step |
372
|
|
|
$this->set_next_step(); |
373
|
|
|
} |
374
|
|
|
$this->set_reg_step_initiated( $this->current_step ); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
|
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* remove_reg_step |
382
|
|
|
* |
383
|
|
|
* @access public |
384
|
|
|
* @param string $reg_step_slug |
385
|
|
|
* @param bool $reset whether to reset reg steps after removal |
386
|
|
|
* @throws EE_Error |
387
|
|
|
*/ |
388
|
|
|
public function remove_reg_step( $reg_step_slug = '', $reset = true ) { |
389
|
|
|
unset( $this->reg_steps[ $reg_step_slug ] ); |
390
|
|
|
if ( $this->transaction instanceof EE_Transaction ) { |
391
|
|
|
/** @type EE_Transaction_Processor $transaction_processor */ |
392
|
|
|
$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
393
|
|
|
// now remove reg step from TXN and save |
394
|
|
|
$transaction_processor->remove_reg_step( $this->transaction, $reg_step_slug ); |
395
|
|
|
$this->transaction->save(); |
396
|
|
|
} |
397
|
|
|
if ( $reset ) { |
398
|
|
|
$this->reset_reg_steps(); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
|
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* set_reg_step_order |
406
|
|
|
* |
407
|
|
|
* @access public |
408
|
|
|
* @param string $reg_step_slug |
409
|
|
|
* @param int $order |
410
|
|
|
* @return void |
411
|
|
|
*/ |
412
|
|
|
public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) { |
413
|
|
|
if ( isset( $this->reg_steps[ $reg_step_slug ] )) { |
414
|
|
|
$this->reg_steps[ $reg_step_slug ]->set_order( $order ); |
415
|
|
|
} |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
|
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* set_current_step |
422
|
|
|
* |
423
|
|
|
* @access public |
424
|
|
|
* @param string $current_step |
425
|
|
|
* @return void |
426
|
|
|
*/ |
427
|
|
|
public function set_current_step( $current_step ) { |
428
|
|
|
// grab what step we're on |
429
|
|
|
$this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps ); |
|
|
|
|
430
|
|
|
// verify instance |
431
|
|
|
if ( $this->current_step instanceof EE_SPCO_Reg_Step ) { |
432
|
|
|
// we don't want to repeat completed steps if this is the first time through SPCO |
433
|
|
|
if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) { |
434
|
|
|
// so advance to the next step |
435
|
|
|
$this->set_next_step(); |
436
|
|
|
if ( $this->next_step instanceof EE_SPCO_Reg_Step ) { |
437
|
|
|
// and attempt to set it as the current step |
438
|
|
|
$this->set_current_step( $this->next_step->slug() ); |
439
|
|
|
} |
440
|
|
|
return; |
441
|
|
|
} |
442
|
|
|
$this->current_step->set_is_current_step( TRUE ); |
443
|
|
|
} else { |
444
|
|
|
EE_Error::add_error( |
445
|
|
|
__( 'The current step could not be set.', 'event_espresso' ), |
446
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
447
|
|
|
); |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
|
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* set_next_step |
455
|
|
|
* advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step |
456
|
|
|
* |
457
|
|
|
* @access public |
458
|
|
|
* @return void |
459
|
|
|
*/ |
460
|
|
|
public function set_next_step() { |
461
|
|
|
// set pointer to start of array |
462
|
|
|
reset( $this->reg_steps ); |
463
|
|
|
// if there is more than one step |
464
|
|
|
if ( count( $this->reg_steps ) > 1 ) { |
465
|
|
|
// advance to the current step and set pointer |
466
|
|
|
while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) { |
467
|
|
|
next( $this->reg_steps ); |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
// advance one more spot ( if it exists ) |
471
|
|
|
$this->next_step = next( $this->reg_steps ); |
472
|
|
|
// verify instance |
473
|
|
|
$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
474
|
|
|
// then back to current step to reset |
475
|
|
|
prev( $this->reg_steps ); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
|
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* get_next_reg_step |
483
|
|
|
* this simply returns the next step from reg_steps array |
484
|
|
|
* |
485
|
|
|
* @access public |
486
|
|
|
* @return EE_SPCO_Reg_Step | null |
487
|
|
|
*/ |
488
|
|
|
public function get_next_reg_step() { |
489
|
|
|
$next = next( $this->reg_steps ); |
490
|
|
|
prev( $this->reg_steps ); |
491
|
|
|
return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
|
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* get_prev_reg_step |
499
|
|
|
* this simply returns the previous step from reg_steps array |
500
|
|
|
* |
501
|
|
|
* @access public |
502
|
|
|
* @return EE_SPCO_Reg_Step | null |
503
|
|
|
*/ |
504
|
|
|
public function get_prev_reg_step() { |
505
|
|
|
$prev = prev( $this->reg_steps ); |
506
|
|
|
next( $this->reg_steps ); |
507
|
|
|
return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
|
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* sort_reg_steps |
514
|
|
|
* |
515
|
|
|
* @access public |
516
|
|
|
* @return void |
517
|
|
|
*/ |
518
|
|
|
public function sort_reg_steps() { |
519
|
|
|
$reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' ); |
520
|
|
|
uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback )); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
|
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* find_reg_step |
527
|
|
|
* finds a reg step by the given slug |
528
|
|
|
* |
529
|
|
|
* @access public |
530
|
|
|
* @param string $reg_step_slug |
531
|
|
|
* @return EE_SPCO_Reg_Step|null |
532
|
|
|
*/ |
533
|
|
|
public function find_reg_step( $reg_step_slug = '' ) { |
534
|
|
|
if ( ! empty( $reg_step_slug ) ) { |
535
|
|
|
// copy reg step array |
536
|
|
|
$reg_steps = $this->reg_steps; |
537
|
|
|
// set pointer to start of array |
538
|
|
|
reset( $reg_steps ); |
539
|
|
|
// if there is more than one step |
540
|
|
|
if ( count( $reg_steps ) > 1 ) { |
541
|
|
|
// advance to the current step and set pointer |
542
|
|
|
while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) { |
543
|
|
|
next( $reg_steps ); |
544
|
|
|
} |
545
|
|
|
return current( $reg_steps ); |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
return null; |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
|
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* reg_step_sorting_callback |
555
|
|
|
* |
556
|
|
|
* @access public |
557
|
|
|
* @param EE_SPCO_Reg_Step $reg_step_A |
558
|
|
|
* @param EE_SPCO_Reg_Step $reg_step_B |
559
|
|
|
* @return array() |
|
|
|
|
560
|
|
|
*/ |
561
|
|
|
public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) { |
562
|
|
|
// send finalize_registration step to the end of the array |
563
|
|
|
if ( $reg_step_A->slug() === 'finalize_registration' ) { |
564
|
|
|
return 1; |
565
|
|
|
} else if ( $reg_step_B->slug() === 'finalize_registration' ) { |
566
|
|
|
return -1; |
567
|
|
|
} |
568
|
|
|
if ( $reg_step_A->order() === $reg_step_B->order() ) { |
569
|
|
|
return 0; |
570
|
|
|
} |
571
|
|
|
return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
|
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* set_reg_step_initiated |
578
|
|
|
* |
579
|
|
|
* @access public |
580
|
|
|
* @param EE_SPCO_Reg_Step $reg_step |
581
|
|
|
* @throws \EE_Error |
582
|
|
|
*/ |
583
|
|
|
public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) { |
584
|
|
|
// call set_reg_step_initiated ??? |
585
|
|
|
if ( |
586
|
|
|
// first time visiting SPCO ? |
587
|
|
|
! $this->revisit |
588
|
|
|
&& ( |
589
|
|
|
// and displaying the reg step form for the first time ? |
590
|
|
|
$this->action === 'display_spco_reg_step' |
591
|
|
|
// or initializing the final step |
592
|
|
|
|| $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration |
593
|
|
|
) |
594
|
|
|
) { |
595
|
|
|
/** @type EE_Transaction_Processor $transaction_processor */ |
596
|
|
|
$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
597
|
|
|
// set the start time for this reg step |
598
|
|
|
if ( ! $transaction_processor->set_reg_step_initiated( $this->transaction, $reg_step->slug() ) ) { |
599
|
|
View Code Duplication |
if ( WP_DEBUG ) { |
600
|
|
|
EE_Error::add_error( |
601
|
|
|
sprintf( |
602
|
|
|
__( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ), |
603
|
|
|
$reg_step->name() |
604
|
|
|
), |
605
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
606
|
|
|
); |
607
|
|
|
} |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
|
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* set_reg_step_JSON_info |
616
|
|
|
* |
617
|
|
|
* @access public |
618
|
|
|
* @return void |
619
|
|
|
*/ |
620
|
|
|
public function set_reg_step_JSON_info() { |
621
|
|
|
EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array(); |
622
|
|
|
// pass basic reg step data to JS |
623
|
|
|
foreach ( $this->reg_steps as $reg_step ) { |
624
|
|
|
EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug(); |
625
|
|
|
} |
626
|
|
|
// reset reg step html |
627
|
|
|
// $this->json_response->set_reg_step_html( '' ); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
|
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* reset_reg_steps |
634
|
|
|
* |
635
|
|
|
* @access public |
636
|
|
|
* @return bool |
637
|
|
|
*/ |
638
|
|
|
public function reset_reg_steps() { |
639
|
|
|
$this->sort_reg_steps(); |
640
|
|
|
$this->set_current_step( EE_Registry::instance()->REQ->get( 'step' )); |
641
|
|
|
$this->set_next_step(); |
642
|
|
|
// the text that appears on the reg step form submit button |
643
|
|
|
$this->current_step->set_submit_button_text(); |
644
|
|
|
$this->set_reg_step_JSON_info(); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
|
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* get_registration_time_limit |
651
|
|
|
* |
652
|
|
|
* @access public |
653
|
|
|
* @return string |
654
|
|
|
*/ |
655
|
|
|
public function get_registration_time_limit() { |
656
|
|
|
|
657
|
|
|
$registration_time_limit = (float)( EE_Registry::instance() ->SSN->expiration() - time() ); |
658
|
|
|
$time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
659
|
|
|
$registration_time_limit = gmdate( $time_limit_format, $registration_time_limit ); |
660
|
|
|
return apply_filters( |
661
|
|
|
'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
662
|
|
|
$registration_time_limit |
663
|
|
|
); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
|
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* payment_required |
670
|
|
|
* @return boolean |
671
|
|
|
*/ |
672
|
|
|
public function payment_required() { |
673
|
|
|
// if NOT: |
674
|
|
|
// registration via admin |
675
|
|
|
// completed TXN |
676
|
|
|
// overpaid TXN |
677
|
|
|
// free TXN ( total = 0.00 ) |
678
|
|
|
// then payment required is TRUE |
679
|
|
|
return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
|
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* get_cart_for_transaction |
686
|
|
|
* |
687
|
|
|
* @access public |
688
|
|
|
* @param EE_Transaction $transaction |
689
|
|
|
* @return EE_Cart |
690
|
|
|
*/ |
691
|
|
|
public function get_cart_for_transaction( $transaction ) { |
692
|
|
|
$session = EE_Registry::instance()->load_core( 'Session' ); |
693
|
|
|
$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction, $session ) : null; |
|
|
|
|
694
|
|
|
// verify cart |
695
|
|
|
if ( ! $cart instanceof EE_Cart ) { |
696
|
|
|
$cart = EE_Registry::instance()->load_core( 'Cart' ); |
|
|
|
|
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
return $cart; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
|
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* initialize_txn_reg_steps_array |
706
|
|
|
* |
707
|
|
|
* @access public |
708
|
|
|
* @return array |
709
|
|
|
*/ |
710
|
|
|
public function initialize_txn_reg_steps_array() { |
711
|
|
|
$txn_reg_steps_array = array(); |
712
|
|
|
foreach ( $this->reg_steps as $reg_step ) { |
713
|
|
|
$txn_reg_steps_array[ $reg_step->slug() ] = FALSE; |
714
|
|
|
} |
715
|
|
|
return $txn_reg_steps_array; |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
|
719
|
|
|
|
720
|
|
|
/** |
721
|
|
|
* update_txn_reg_steps_array |
722
|
|
|
* |
723
|
|
|
* @access public |
724
|
|
|
* @return bool |
725
|
|
|
* @throws \EE_Error |
726
|
|
|
*/ |
727
|
|
|
public function update_txn_reg_steps_array() { |
728
|
|
|
$updated = false; |
729
|
|
|
/** @type EE_Transaction_Processor $transaction_processor */ |
730
|
|
|
$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
731
|
|
|
foreach ( $this->reg_steps as $reg_step ) { |
732
|
|
|
if ( $reg_step->completed() ) { |
733
|
|
|
$updated = $transaction_processor->set_reg_step_completed( $this->transaction, $reg_step->slug() ) |
734
|
|
|
? true |
735
|
|
|
: $updated; |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
if ( $updated ) { |
739
|
|
|
$this->transaction->save(); |
740
|
|
|
} |
741
|
|
|
return $updated; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
|
745
|
|
|
|
746
|
|
|
/** |
747
|
|
|
* stash_transaction_and_checkout |
748
|
|
|
* |
749
|
|
|
* @access public |
750
|
|
|
* @return void |
751
|
|
|
* @throws \EE_Error |
752
|
|
|
*/ |
753
|
|
|
public function stash_transaction_and_checkout() { |
754
|
|
|
if ( ! $this->revisit ) { |
755
|
|
|
$this->update_txn_reg_steps_array(); |
756
|
|
|
} |
757
|
|
|
$this->track_transaction_and_registration_status_updates(); |
758
|
|
|
// save all data to the db, but suppress errors |
759
|
|
|
//$this->save_all_data( FALSE ); |
760
|
|
|
// cache the checkout in the session |
761
|
|
|
EE_Registry::instance()->SSN->set_checkout( $this ); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
|
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* track_transaction_and_registration_status_updates |
768
|
|
|
* stores whether any updates were made to the TXN or it's related registrations |
769
|
|
|
* |
770
|
|
|
* @access public |
771
|
|
|
* @return bool |
772
|
|
|
* @throws \EE_Error |
773
|
|
|
*/ |
774
|
|
|
public function track_transaction_and_registration_status_updates() { |
775
|
|
|
// verify the transaction |
776
|
|
|
if ( $this->transaction instanceof EE_Transaction ) { |
777
|
|
|
/** @type EE_Transaction_Payments $transaction_payments */ |
778
|
|
|
$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
779
|
|
|
/** @type EE_Transaction_Processor $transaction_processor */ |
780
|
|
|
$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
781
|
|
|
// has there been a TXN status change during this checkout? |
782
|
|
|
if ( $transaction_payments->txn_status_updated() || $transaction_processor->txn_status_updated() ) { |
783
|
|
|
$this->txn_status_updated = true; |
784
|
|
|
} |
785
|
|
|
/** @type EE_Registration_Processor $registration_processor */ |
786
|
|
|
$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
787
|
|
|
// grab the saved registrations from the transaction |
788
|
|
|
foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
789
|
|
|
if ( $registration_processor->reg_status_updated( $registration->ID() ) ) { |
790
|
|
|
$this->set_reg_status_updated( $registration->ID(), true ); |
791
|
|
|
} |
792
|
|
|
} |
793
|
|
|
} |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
|
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* visit_allows_processing_of_this_registration |
800
|
|
|
* determines if the current SPCO visit should allow the passed EE_Registration to be used in processing. |
801
|
|
|
* one of the following conditions must be met: |
802
|
|
|
* EITHER: A) first time thru SPCO -> process ALL registrations ( NOT a revisit ) |
803
|
|
|
* OR : B) primary registrant is editing info -> process ALL registrations ( primary_revisit ) |
804
|
|
|
* OR : C) another registrant is editing info -> ONLY process their registration ( revisit AND their reg_url_link matches ) |
805
|
|
|
* |
806
|
|
|
* @access public |
807
|
|
|
* @param EE_Registration $registration |
808
|
|
|
* @return bool |
809
|
|
|
* @throws \EE_Error |
810
|
|
|
*/ |
811
|
|
|
public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
812
|
|
|
return ! $this->revisit |
813
|
|
|
|| $this->primary_revisit |
814
|
|
|
|| ( |
815
|
|
|
$this->revisit && $this->reg_url_link === $registration->reg_url_link() |
816
|
|
|
) |
817
|
|
|
? true |
818
|
|
|
: false; |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
|
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* _transaction_has_primary_registration |
825
|
|
|
* |
826
|
|
|
* @access private |
827
|
|
|
* @return bool |
828
|
|
|
*/ |
829
|
|
|
public function transaction_has_primary_registrant() { |
830
|
|
|
return $this->primary_attendee_obj instanceof EE_Attendee ? TRUE : FALSE; |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
|
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* save_all_data |
837
|
|
|
* simply loops through the current transaction and saves all data for each registration |
838
|
|
|
* |
839
|
|
|
* @access public |
840
|
|
|
* @param bool $show_errors |
841
|
|
|
* @return bool |
842
|
|
|
* @throws \EE_Error |
843
|
|
|
*/ |
844
|
|
|
public function save_all_data( $show_errors = TRUE ) { |
845
|
|
|
// verify the transaction |
846
|
|
|
if ( $this->transaction instanceof EE_Transaction ) { |
847
|
|
|
// save to ensure that TXN has ID |
848
|
|
|
$this->transaction->save(); |
849
|
|
|
// grab the saved registrations from the transaction |
850
|
|
|
foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
851
|
|
|
$this->_save_registration( $registration, $show_errors ); |
|
|
|
|
852
|
|
|
} |
853
|
|
|
} else { |
854
|
|
|
if ( $show_errors ) { |
855
|
|
|
EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
856
|
|
|
} |
857
|
|
|
return FALSE; |
858
|
|
|
} |
859
|
|
|
return TRUE; |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
|
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* _save_registration_attendee |
866
|
|
|
* |
867
|
|
|
* @param EE_Registration $registration |
868
|
|
|
* @param bool $show_errors |
869
|
|
|
* @return void |
870
|
|
|
* @throws \EE_Error |
871
|
|
|
*/ |
872
|
|
|
private function _save_registration( $registration, $show_errors = TRUE ) { |
873
|
|
|
// verify object |
874
|
|
|
if ( $registration instanceof EE_Registration ) { |
875
|
|
|
// should this registration be processed during this visit ? |
876
|
|
|
if ( $this->visit_allows_processing_of_this_registration( $registration ) ) { |
877
|
|
|
//set TXN ID |
878
|
|
|
if ( ! $registration->transaction_ID() ) { |
879
|
|
|
$registration->set_transaction_id( $this->transaction->ID() ); |
880
|
|
|
} |
881
|
|
|
// verify and save the attendee |
882
|
|
|
$this->_save_registration_attendee( $registration, $show_errors ); |
883
|
|
|
// save answers to reg form questions |
884
|
|
|
$this->_save_registration_answers( $registration, $show_errors ); |
885
|
|
|
// save changes |
886
|
|
|
$registration->save(); |
887
|
|
|
// update txn cache |
888
|
|
View Code Duplication |
if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) { |
889
|
|
|
if ( $show_errors ) { |
890
|
|
|
EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
891
|
|
|
} |
892
|
|
|
} |
893
|
|
|
} |
894
|
|
|
} else { |
895
|
|
|
if ( $show_errors ) { |
896
|
|
|
EE_Error::add_error( |
897
|
|
|
__( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ), |
898
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
899
|
|
|
); |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
|
905
|
|
|
|
906
|
|
|
/** |
907
|
|
|
* _save_registration_attendee |
908
|
|
|
* |
909
|
|
|
* @param EE_Registration $registration |
910
|
|
|
* @param bool $show_errors |
911
|
|
|
* @return void |
912
|
|
|
* @throws \EE_Error |
913
|
|
|
*/ |
914
|
|
|
private function _save_registration_attendee( $registration, $show_errors = TRUE ) { |
915
|
|
|
if ( $registration->attendee() instanceof EE_Attendee ) { |
916
|
|
|
// save so that ATT has ID |
917
|
|
|
$registration->attendee()->save(); |
918
|
|
View Code Duplication |
if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) { |
919
|
|
|
if ( $show_errors ) { |
920
|
|
|
EE_Error::add_error( |
921
|
|
|
__( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ), |
922
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
923
|
|
|
); |
924
|
|
|
} |
925
|
|
|
} |
926
|
|
View Code Duplication |
} else { |
927
|
|
|
if ( $show_errors ) { |
928
|
|
|
EE_Error::add_error( |
929
|
|
|
sprintf( |
930
|
|
|
'%1$s||%1$s $attendee = %2$s', |
931
|
|
|
__( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ), |
932
|
|
|
var_export( $registration->attendee(), true ) |
933
|
|
|
), |
934
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
935
|
|
|
); |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
|
941
|
|
|
|
942
|
|
|
/** |
943
|
|
|
* _save_question_answers |
944
|
|
|
* |
945
|
|
|
* @param EE_Registration $registration |
946
|
|
|
* @param bool $show_errors |
947
|
|
|
* @return void |
948
|
|
|
* @throws \EE_Error |
949
|
|
|
*/ |
950
|
|
|
private function _save_registration_answers( $registration, $show_errors = TRUE ) { |
951
|
|
|
// now save the answers |
952
|
|
|
foreach ( $registration->answers() as $cache_key => $answer ) { |
953
|
|
|
// verify object |
954
|
|
|
if ( $answer instanceof EE_Answer ) { |
955
|
|
|
$answer->set_registration( $registration->ID() ); |
956
|
|
|
$answer->save(); |
957
|
|
|
if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) { |
958
|
|
|
if ( $show_errors ) { |
959
|
|
|
EE_Error::add_error( |
960
|
|
|
__( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ), |
961
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
962
|
|
|
); |
963
|
|
|
} |
964
|
|
|
} |
965
|
|
|
} else { |
966
|
|
|
if ( $show_errors ) { |
967
|
|
|
EE_Error::add_error( |
968
|
|
|
__( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ), |
969
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
970
|
|
|
); |
971
|
|
|
} |
972
|
|
|
} |
973
|
|
|
} |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
|
977
|
|
|
|
978
|
|
|
/** |
979
|
|
|
* refresh_all_entities |
980
|
|
|
* will either refresh the entity map with objects form the db or from the checkout cache |
981
|
|
|
* |
982
|
|
|
* @access public |
983
|
|
|
* @param bool $from_db |
984
|
|
|
* @return bool |
985
|
|
|
* @throws \EE_Error |
986
|
|
|
*/ |
987
|
|
|
public function refresh_all_entities( $from_db = false ) { |
988
|
|
|
$from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
989
|
|
|
? true |
990
|
|
|
: $from_db; |
991
|
|
|
//$this->log( |
992
|
|
|
// __CLASS__, __FUNCTION__, __LINE__, |
993
|
|
|
// array( 'from_db' =>$from_db ) |
994
|
|
|
//); |
995
|
|
|
return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map(); |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
|
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* refresh_entity_map |
1002
|
|
|
* simply loops through the current transaction and updates each |
1003
|
|
|
* model's entity map using EEM_Base::refresh_entity_map_from_db() |
1004
|
|
|
* |
1005
|
|
|
* @access public |
1006
|
|
|
* @return bool |
1007
|
|
|
* @throws \EE_Error |
1008
|
|
|
*/ |
1009
|
|
|
protected function refresh_from_db() { |
1010
|
|
|
// verify the transaction |
1011
|
|
|
if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
1012
|
|
|
// pull fresh TXN data from the db |
1013
|
|
|
$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() ); |
1014
|
|
|
// update EE_Checkout's cached primary_attendee object |
1015
|
|
|
$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction ); |
1016
|
|
|
// update EE_Checkout's cached payment object |
1017
|
|
|
$payment = $this->transaction->last_payment(); |
1018
|
|
|
$this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
1019
|
|
|
// update EE_Checkout's cached payment_method object |
1020
|
|
|
$payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
1021
|
|
|
$this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method; |
1022
|
|
|
//now refresh the cart, based on the TXN |
1023
|
|
|
$this->cart = $this->get_cart_for_transaction( $this->transaction ); |
1024
|
|
|
} else { |
1025
|
|
|
EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
1026
|
|
|
return FALSE; |
1027
|
|
|
} |
1028
|
|
|
return TRUE; |
1029
|
|
|
} |
1030
|
|
|
|
1031
|
|
|
|
1032
|
|
|
|
1033
|
|
|
/** |
1034
|
|
|
* _refresh_primary_attendee_obj_from_db |
1035
|
|
|
* |
1036
|
|
|
* @param EE_Transaction $transaction |
1037
|
|
|
* @return EE_Attendee | null |
1038
|
|
|
* @throws \EE_Error |
1039
|
|
|
*/ |
1040
|
|
|
protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) { |
1041
|
|
|
|
1042
|
|
|
$primary_attendee_obj = null; |
1043
|
|
|
// grab the saved registrations from the transaction |
1044
|
|
|
foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) { |
1045
|
|
|
// verify object |
1046
|
|
|
if ( $registration instanceof EE_Registration ) { |
1047
|
|
|
$attendee = $registration->attendee(); |
1048
|
|
|
// verify object && maybe cache primary_attendee_obj ? |
1049
|
|
|
if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) { |
1050
|
|
|
$primary_attendee_obj = $attendee; |
1051
|
|
|
} |
1052
|
|
|
} else { |
1053
|
|
|
EE_Error::add_error( |
1054
|
|
|
__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
1055
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
1056
|
|
|
); |
1057
|
|
|
} |
1058
|
|
|
} |
1059
|
|
|
return $primary_attendee_obj; |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
|
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* refresh_entity_map |
1066
|
|
|
* simply loops through the current transaction and updates |
1067
|
|
|
* each model's entity map using EEM_Base::refresh_entity_map_with() |
1068
|
|
|
* |
1069
|
|
|
* @access public |
1070
|
|
|
* @return bool |
1071
|
|
|
* @throws \EE_Error |
1072
|
|
|
*/ |
1073
|
|
|
protected function refresh_entity_map() { |
1074
|
|
|
// verify the transaction |
1075
|
|
|
if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
1076
|
|
|
// never cache payment info |
1077
|
|
|
$this->transaction->clear_cache( 'Payment' ); |
1078
|
|
|
/** @type EE_Transaction_Processor $transaction_processor */ |
1079
|
|
|
$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
1080
|
|
|
// is the Payment Options Reg Step completed ? |
1081
|
|
|
if ( $transaction_processor->reg_step_completed( $this->transaction, 'payment_options' ) ) { |
1082
|
|
|
// then check for payments and update TXN accordingly |
1083
|
|
|
/** @type EE_Transaction_Payments $transaction_payments */ |
1084
|
|
|
$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
1085
|
|
|
$transaction_payments->calculate_total_payments_and_update_status( $this->transaction ); |
1086
|
|
|
} |
1087
|
|
|
// grab the saved registrations from the transaction |
1088
|
|
|
foreach ( |
1089
|
|
|
$this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration |
1090
|
|
|
) { |
1091
|
|
|
$this->_refresh_registration( $reg_cache_ID, $registration ); |
|
|
|
|
1092
|
|
|
} |
1093
|
|
|
// make sure our cached TXN is added to the model entity mapper |
1094
|
|
|
$this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction ); |
1095
|
|
|
|
1096
|
|
|
} else { |
1097
|
|
|
EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
1098
|
|
|
return FALSE; |
1099
|
|
|
} |
1100
|
|
|
// verify and update the cart because inaccurate totals are not so much fun |
1101
|
|
|
if ( $this->cart instanceof EE_Cart ) { |
1102
|
|
|
$grand_total = $this->cart->get_grand_total(); |
1103
|
|
|
if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) { |
1104
|
|
|
$grand_total->recalculate_total_including_taxes(); |
1105
|
|
|
$grand_total = $grand_total->get_model()->refresh_entity_map_with( |
1106
|
|
|
$this->cart->get_grand_total()->ID(), |
1107
|
|
|
$this->cart->get_grand_total() |
1108
|
|
|
); |
1109
|
|
|
} |
1110
|
|
View Code Duplication |
if ( $grand_total instanceof EE_Line_Item ) { |
1111
|
|
|
$this->cart = EE_Cart::instance( $grand_total ); |
1112
|
|
|
} else { |
1113
|
|
|
EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
1114
|
|
|
return false; |
1115
|
|
|
} |
1116
|
|
|
} |
1117
|
|
|
return TRUE; |
1118
|
|
|
} |
1119
|
|
|
|
1120
|
|
|
|
1121
|
|
|
|
1122
|
|
|
/** |
1123
|
|
|
* _refresh_registration |
1124
|
|
|
* |
1125
|
|
|
* @param string | int $reg_cache_ID |
1126
|
|
|
* @param EE_Registration $registration |
1127
|
|
|
* @return void |
1128
|
|
|
* @throws \EE_Error |
1129
|
|
|
*/ |
1130
|
|
|
protected function _refresh_registration( $reg_cache_ID, $registration ) { |
1131
|
|
|
|
1132
|
|
|
// verify object |
1133
|
|
View Code Duplication |
if ( $registration instanceof EE_Registration ) { |
1134
|
|
|
// update the entity mapper attendee |
1135
|
|
|
$this->_refresh_registration_attendee( $registration ); |
1136
|
|
|
// update the entity mapper answers for reg form questions |
1137
|
|
|
$this->_refresh_registration_answers( $registration ); |
1138
|
|
|
// make sure the cached registration is added to the model entity mapper |
1139
|
|
|
$registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration ); |
1140
|
|
|
} else { |
1141
|
|
|
EE_Error::add_error( |
1142
|
|
|
__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
1143
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
1144
|
|
|
); |
1145
|
|
|
} |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
|
1149
|
|
|
|
1150
|
|
|
/** |
1151
|
|
|
* _save_registration_attendee |
1152
|
|
|
* |
1153
|
|
|
* @param EE_Registration $registration |
1154
|
|
|
* @return void |
1155
|
|
|
* @throws \EE_Error |
1156
|
|
|
*/ |
1157
|
|
|
protected function _refresh_registration_attendee( $registration ) { |
1158
|
|
|
|
1159
|
|
|
$attendee = $registration->attendee(); |
1160
|
|
|
// verify object |
1161
|
|
|
if ( $attendee instanceof EE_Attendee && $attendee->ID() ) { |
1162
|
|
|
// make sure the cached attendee is added to the model entity mapper |
1163
|
|
|
$registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee ); |
1164
|
|
|
// maybe cache primary_attendee_obj ? |
1165
|
|
|
if ( $registration->is_primary_registrant() ) { |
1166
|
|
|
$this->primary_attendee_obj = $attendee; |
1167
|
|
|
} |
1168
|
|
|
} |
1169
|
|
|
} |
1170
|
|
|
|
1171
|
|
|
|
1172
|
|
|
|
1173
|
|
|
/** |
1174
|
|
|
* _refresh_registration_answers |
1175
|
|
|
* |
1176
|
|
|
* @param EE_Registration $registration |
1177
|
|
|
* @return void |
1178
|
|
|
* @throws \EE_Error |
1179
|
|
|
*/ |
1180
|
|
|
protected function _refresh_registration_answers( $registration ) { |
1181
|
|
|
|
1182
|
|
|
// now update the answers |
1183
|
|
|
foreach ( $registration->answers() as $cache_key => $answer ) { |
1184
|
|
|
// verify object |
1185
|
|
View Code Duplication |
if ( $answer instanceof EE_Answer ) { |
1186
|
|
|
if ( $answer->ID() ) { |
1187
|
|
|
// make sure the cached answer is added to the model entity mapper |
1188
|
|
|
$answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer ); |
1189
|
|
|
} |
1190
|
|
|
} else { |
1191
|
|
|
EE_Error::add_error( |
1192
|
|
|
__( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
1193
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
1194
|
|
|
); |
1195
|
|
|
} |
1196
|
|
|
} |
1197
|
|
|
} |
1198
|
|
|
|
1199
|
|
|
|
1200
|
|
|
|
1201
|
|
|
/** |
1202
|
|
|
* __wakeup |
1203
|
|
|
* to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
1204
|
|
|
* this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
1205
|
|
|
*/ |
1206
|
|
|
public function __wakeup() { |
1207
|
|
|
foreach ( $this->reg_steps as $reg_step ) { |
1208
|
|
|
$reg_step->checkout = $this; |
1209
|
|
|
} |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
|
1213
|
|
|
|
1214
|
|
|
/** |
1215
|
|
|
* debug |
1216
|
|
|
* |
1217
|
|
|
* @param string $class |
1218
|
|
|
* @param string $func |
1219
|
|
|
* @param string $line |
1220
|
|
|
* @param array $info |
1221
|
|
|
* @param bool $display_request |
1222
|
|
|
* @throws \EE_Error |
1223
|
|
|
*/ |
1224
|
|
|
public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) { |
1225
|
|
|
$disabled = true; |
1226
|
|
|
if ( WP_DEBUG && ! $disabled ) { |
1227
|
|
|
$debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() ); |
1228
|
|
|
$default_data = array( |
1229
|
|
|
$class => $func . '() : ' . $line, |
1230
|
|
|
'request->step' => $this->step, |
1231
|
|
|
'request->action' => $this->action, |
1232
|
|
|
'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
1233
|
|
|
$this->current_step->slug() : '', |
1234
|
|
|
'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
1235
|
|
|
$this->current_step->completed() : '', |
1236
|
|
|
'txn_status_updated' => $this->txn_status_updated, |
1237
|
|
|
'reg_status_updated' => $this->reg_status_updated, |
1238
|
|
|
'reg_url_link' => $this->reg_url_link, |
1239
|
|
|
'REQ' => $display_request ? $_REQUEST : '', |
1240
|
|
|
); |
1241
|
|
|
if ( $this->transaction instanceof EE_Transaction ) { |
1242
|
|
|
$default_data[ 'TXN_status' ] = $this->transaction->status_ID(); |
1243
|
|
|
$default_data[ 'TXN_reg_steps' ] = $this->transaction->reg_steps(); |
1244
|
|
|
foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) { |
1245
|
|
|
$default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID(); |
|
|
|
|
1246
|
|
|
} |
1247
|
|
|
if ( $this->transaction->ID() ) { |
1248
|
|
|
$TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
1249
|
|
|
// don't serialize objects |
1250
|
|
|
$info = $this->_strip_objects( $info ); |
1251
|
|
|
if ( ! isset( $debug_data[ $TXN_ID ] ) ) { |
1252
|
|
|
$debug_data[ $TXN_ID ] = array(); |
1253
|
|
|
} |
1254
|
|
|
$debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
1255
|
|
|
$default_data, |
1256
|
|
|
$info |
1257
|
|
|
); |
1258
|
|
|
update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data ); |
1259
|
|
|
} |
1260
|
|
|
} |
1261
|
|
|
} |
1262
|
|
|
} |
1263
|
|
|
|
1264
|
|
|
|
1265
|
|
|
/** |
1266
|
|
|
* _strip_objects |
1267
|
|
|
* |
1268
|
|
|
* @param array $info |
1269
|
|
|
* @return array |
1270
|
|
|
*/ |
1271
|
|
|
public function _strip_objects( $info = array() ) { |
1272
|
|
|
foreach ( (array)$info as $key => $value ) { |
1273
|
|
View Code Duplication |
if ( is_array( $value )) { |
1274
|
|
|
$info[ $key ] = $this->_strip_objects( $value ); |
1275
|
|
|
} else if ( is_object( $value ) ) { |
1276
|
|
|
$object_class = get_class( $value ); |
1277
|
|
|
$info[ $object_class ] = array(); |
1278
|
|
|
$info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0; |
1279
|
|
|
if ( method_exists( $value, 'status' ) ) { |
1280
|
|
|
$info[ $object_class ][ 'status' ] = $value->status(); |
1281
|
|
|
} else if ( method_exists( $value, 'status_ID' ) ) { |
1282
|
|
|
$info[ $object_class ][ 'status' ] = $value->status_ID(); |
1283
|
|
|
} |
1284
|
|
|
unset( $info[ $key ] ); |
1285
|
|
|
} |
1286
|
|
|
} |
1287
|
|
|
return (array)$info; |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
|
1291
|
|
|
|
1292
|
|
|
|
1293
|
|
|
} |
1294
|
|
|
// End of file EE_Checkout.class.php |
1295
|
|
|
// Location: /EE_Checkout.class.php |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.