Skip to content

Commit 2b2f694

Browse files
author
Chris Gårdenberg
committed
fix: Fixed a bug with saving attribute values
add: More errorhandling to booking handler
1 parent a4f715a commit 2b2f694

8 files changed

Lines changed: 81 additions & 45 deletions

File tree

class/class-eduadmin-bookinghandler.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@ public function book_single_participant() {
449449
return $error_list;
450450
}
451451

452+
if ( ! empty( $booking['ErrorMessages'] ) ) {
453+
$error_list = array();
454+
foreach ( $booking['ErrorMessages'] as $error ) {
455+
$std_error = array();
456+
$std_error['ErrorCode'] = -1;
457+
$std_error['ErrorDetails'] = $error;
458+
$std_error['ErrorText'] = $error;
459+
460+
$error_list['Errors'][] = $std_error;
461+
}
462+
463+
return $error_list;
464+
}
465+
452466
if ( ! empty( $booking['Errors'] ) ) {
453467
$error_list = array();
454468
$error_list['Errors'] = $booking['Errors'];
@@ -630,6 +644,20 @@ public function book_multiple_participants() {
630644
return $error_list;
631645
}
632646

647+
if ( ! empty( $booking['ErrorMessages'] ) ) {
648+
$error_list = array();
649+
foreach ( $booking['ErrorMessages'] as $error ) {
650+
$std_error = array();
651+
$std_error['ErrorCode'] = -1;
652+
$std_error['ErrorDetails'] = $error;
653+
$std_error['ErrorText'] = $error;
654+
655+
$error_list['Errors'][] = $std_error;
656+
}
657+
658+
return $error_list;
659+
}
660+
633661
if ( ! empty( $booking['Errors'] ) ) {
634662
$error_list = array();
635663
$error_list['Errors'] = $booking['Errors'];
@@ -756,7 +784,7 @@ private function get_custom_field_data( $key, $custom_field_id, $custom_field_ty
756784
if ( 'check' === $custom_field_type || 'radio' === $custom_field_type ) {
757785
$answer->CustomFieldValue = true;
758786
} else {
759-
$answer->CustomFieldValue = intval( $custom_field_id );
787+
$answer->CustomFieldValue = intval( $_POST[ $key ] );
760788
}
761789
break;
762790
default:

content/template/bookingTemplate/contact-view.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,28 @@
7171
'ShowOnWeb and CustomFieldOwner eq \'Person\'',
7272
'CustomFieldAlternatives'
7373
)['value'];
74-
75-
foreach ( $contact_custom_fields as $custom_field ) {
76-
$data = null;
77-
foreach ( $contact->CustomFields as $cf ) {
78-
if ( $cf->CustomFieldId === $custom_field['CustomFieldId'] ) {
79-
switch ( $cf->CustomFieldType ) {
80-
case 'Checkbox':
81-
$data = $cf->CustomFieldChecked;
82-
break;
83-
case 'Dropdown':
84-
$data = $cf->CustomFieldAlternativeId;
85-
break;
86-
default:
87-
$data = $cf->CustomFieldValue;
88-
break;
74+
if ( ! empty( $contact_custom_fields ) ) {
75+
foreach ( $contact_custom_fields as $custom_field ) {
76+
$data = null;
77+
foreach ( $contact->CustomFields as $cf ) {
78+
if ( $cf->CustomFieldId === $custom_field['CustomFieldId'] ) {
79+
switch ( $cf->CustomFieldType ) {
80+
case 'Checkbox':
81+
$data = $cf->CustomFieldChecked;
82+
break;
83+
case 'Dropdown':
84+
$data = $cf->CustomFieldAlternativeId;
85+
break;
86+
default:
87+
$data = $cf->CustomFieldValue;
88+
break;
89+
}
90+
break;
8991
}
90-
break;
9192
}
93+
render_attribute( $custom_field, false, 'contact', $data );
9294
}
93-
render_attribute( $custom_field, false, 'contact', $data );
9495
}
95-
9696
?>
9797

9898
<label>

content/template/bookingTemplate/customer-view.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,27 @@
148148
'ShowOnWeb and CustomFieldOwner eq \'Customer\'',
149149
'CustomFieldAlternatives'
150150
)['value'];
151-
152-
foreach ( $customer_custom_fields as $custom_field ) {
153-
$data = null;
154-
foreach ( $customer->CustomFields as $cf ) {
155-
if ( $cf->CustomFieldId === $custom_field['CustomFieldId'] ) {
156-
switch ( $cf->CustomFieldType ) {
157-
case 'Checkbox':
158-
$data = $cf->CustomFieldChecked;
159-
break;
160-
case 'Dropdown':
161-
$data = $cf->CustomFieldAlternativeId;
162-
break;
163-
default:
164-
$data = $cf->CustomFieldValue;
165-
break;
151+
if ( ! empty( $customer_custom_fields ) ) {
152+
foreach ( $customer_custom_fields as $custom_field ) {
153+
$data = null;
154+
foreach ( $customer->CustomFields as $cf ) {
155+
if ( $cf->CustomFieldId === $custom_field['CustomFieldId'] ) {
156+
switch ( $cf->CustomFieldType ) {
157+
case 'Checkbox':
158+
$data = $cf->CustomFieldChecked;
159+
break;
160+
case 'Dropdown':
161+
$data = $cf->CustomFieldAlternativeId;
162+
break;
163+
default:
164+
$data = $cf->CustomFieldValue;
165+
break;
166+
}
167+
break;
166168
}
167-
break;
168169
}
170+
render_attribute( $custom_field, false, 'customer', $data );
169171
}
170-
render_attribute( $custom_field, false, 'customer', $data );
171172
}
172173
if ( ! $no_invoice_free_events || $first_price->Price > 0 ) {
173174
?>

content/template/bookingTemplate/participants/participant-template.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
</label>
4747
<?php } ?>
4848
<?php
49-
50-
foreach ( $contact_custom_fields as $attr ) {
51-
render_attribute( $attr, true, 'participant' );
49+
if ( ! empty( $contact_custom_fields ) ) {
50+
foreach ( $contact_custom_fields as $attr ) {
51+
render_attribute( $attr, true, 'participant' );
52+
}
5253
}
5354

5455
?>
@@ -99,9 +100,10 @@
99100
}
100101
echo '<br />';
101102
}
102-
103-
foreach ( $participant_questions as $question ) {
104-
render_question( $question, true, 'participant' );
103+
if ( ! empty( $participant_questions ) ) {
104+
foreach ( $participant_questions as $question ) {
105+
render_question( $question, true, 'participant' );
106+
}
105107
}
106108
?>
107109
</div>

content/template/bookingTemplate/single-person-booking.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
if ( ! empty( $customer_custom_fields ) ) {
229229
foreach ( $customer_custom_fields as $custom_field ) {
230230
$data = null;
231+
231232
foreach ( $customer->CustomFields as $cf ) {
232233
if ( $cf->CustomFieldId === $custom_field['CustomFieldId'] ) {
233234
switch ( $cf->CustomFieldType ) {

eduadmin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin URI: https://www.eduadmin.se
1010
* Description: EduAdmin plugin to allow visitors to book courses at your website
1111
* Tags: booking, participants, courses, events, eduadmin, lega online
12-
* Version: 2.0.4
12+
* Version: 2.0.5
1313
* GitHub Plugin URI: multinetinteractive/eduadmin-wordpress
1414
* GitHub Plugin URI: https://github.com/multinetinteractive/eduadmin-wordpress
1515
* Requires at least: 4.7

includes/edu-attribute-functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function render_select_field( $attribute, $multiple, $suffix, $data ) {
120120
echo ' data-replace="name|index"';
121121
echo ' data-name-template="edu-attr_' . esc_attr( $attribute['CustomFieldId'] . '_dropdown' . ( '' !== $suffix ? '-' . $suffix : '' ) . '_{{index}}' ) . '"';
122122
}
123-
echo "\">\n";
123+
echo ">\n";
124124
foreach ( $attribute['CustomFieldAlternatives'] as $val ) {
125125
echo "\t<option" . ( ! empty( $data ) && $data === $val['CustomFieldAlternativeId'] ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $val['CustomFieldAlternativeId'] ) . '">' . esc_html( $val['CustomFieldAlternativeValue'] ) . "</option>\n";
126126
}

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: mnchga
33
Tags: booking, participants, courses, events, eduadmin, lega online
44
Requires at least: 4.7
55
Tested up to: 4.9
6-
Stable tag: 2.0.4
6+
Stable tag: 2.0.5
77
Requires PHP: 5.2
88
License: GPL3
99
License-URI: https://www.gnu.org/licenses/gpl-3.0.en.html
@@ -39,6 +39,10 @@ If you notice that your API key doesn't work any more, you have to contact us.
3939

4040
== Changelog ==
4141

42+
### 2.0.5 ###
43+
- fix: Fixed a bug with saving attribute values
44+
- add: More errorhandling to booking handler
45+
4246
### 2.0.4 ###
4347
- fix: Fixed so that strings from the EduAdmin-API also gets captured into `data`
4448
- add: Show price on programme booking-page

0 commit comments

Comments
 (0)