PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.28
Booktics – Appointment Booking Calendar for Service Businesses v1.0.28
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
← All changes | core/cart/controllers/cart-controller.php +32 -10 1.0.22 → 1.0.28 View file →
@@ -102,17 +102,30 @@
102 102 *
103 103 * @return []|array|bool|WP_Error
104 104 */
105 105 private function prepare_item_to_save( array $data ) {
106 - $validated = booktics_validate(
107 - $data, array(
108 - 'date' => array( 'required' ),
109 - 'start_time' => array( 'required' ),
110 - 'service_id' => array( 'required' ),
111 - 'team_member_id' => array( 'required' ),
112 - )
106 + $item_rules = array(
107 + 'date' => array( 'required' ),
108 + 'start_time' => array( 'required' ),
109 + 'service_id' => array( 'required' ),
110 + 'team_member_id' => array( 'required' ),
113 111 );
114 112
113 + /**
114 + * Filters the validation rules applied to a cart item.
115 + *
116 + * Extensions that assign a team member server-side (Booktics Pro
117 + * round robin) drop the team_member_id requirement here.
118 + *
119 + * @since 1.0.26
120 + *
121 + * @param array $item_rules Validation rules.
122 + * @param array $data The cart item being validated.
123 + */
124 + $item_rules = apply_filters( 'booktics_cart_item_validation_rules', $item_rules, $data );
125 +
126 + $validated = booktics_validate( $data, $item_rules );
127 +
115 128 if ( is_wp_error( $validated ) ) {
116 129 return $validated;
117 130 }
118 131
@@ -245,11 +258,16 @@
245 258 if ( ! $service ) {
246 259 $error->add( 'invalid_service', __( 'Invalid service selected', 'booktics' ) );
247 260 }
248 261
249 - $team_member = ( new Team_Member_Model() )->find( $data['team_member_id'] );
250 - if ( empty( $team_member ) ) {
251 - $error->add( 'invalid_team_member', __( 'Invalid team member selected', 'booktics' ) );
262 + // A cart item may legitimately arrive without a team member when the
263 + // service assigns one server-side. Only verify a member that was
264 + // actually supplied; the booking is refused later if none can be found.
265 + if ( ! empty( $data['team_member_id'] ) ) {
266 + $team_member = ( new Team_Member_Model() )->find( $data['team_member_id'] );
267 + if ( empty( $team_member ) ) {
268 + $error->add( 'invalid_team_member', __( 'Invalid team member selected', 'booktics' ) );
269 + }
252 270 }
253 271
254 272 $service_price = 0;
255 273 $addition_durations = $service->additional_durations;
@@ -297,8 +315,12 @@
297 315 }
298 316
299 317 // Add UUID to validated data
300 318 $validated['uuid'] = $uuid;
319 +
320 + // Calculate end time from start time and total duration
321 + $total_duration_min = $this->calculate_total_duration( $validated );
322 + $validated['end_time'] = $this->get_endtime_from_starttime( $validated['start_time'], $total_duration_min );
301 323
302 324 // Update the cart item
303 325 $updated_item = $this->cart_manager->edit_cart_item( $uuid, $validated );
304 326