PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.8
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 All 48 releases
← All changes | lib/controllers/orders_controller.php +118 -209 trunk5.2.8 View file →
@@ -19,9 +19,9 @@
19 19 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'orders/';
20 20 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'orders' );
21 21 $this->vars['breadcrumbs'][] = array(
22 22 'label' => __( 'Orders', 'latepoint' ),
23 - 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'orders', 'index' ) ),
23 + 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'orders', 'index' ) )
24 24 );
25 25
26 26 $this->action_access['public'] = array_merge( $this->action_access['public'], [ 'continue_order_intent', 'continue_transaction_intent' ] );
27 27 }
@@ -27,17 +27,12 @@
27 27 }
28 28
29 29
30 30 public function view_order_log() {
31 - $order_id = absint( $this->params['order_id'] );
32 - $order = ( new OsOrderModel() )->where( [ LATEPOINT_TABLE_ORDERS . '.id' => $order_id ] )->filter_allowed_records()->set_limit( 1 )->get_results_as_models();
33 - if ( ! $order ) {
34 - $this->access_not_allowed();
35 - return;
36 - }
31 + $activities = new OsActivityModel();
32 + $activities = $activities->where( [ 'order_id' => absint($this->params['order_id']) ] )->order_by( 'id desc' )->get_results_as_models();
37 33
38 - $activities = new OsActivityModel();
39 - $activities = $activities->where( [ 'order_id' => $order_id ] )->order_by( 'id desc' )->get_results_as_models();
34 + $order = new OsOrderModel( $this->params['order_id'] );
40 35
41 36 $this->vars['order'] = $order;
42 37 $this->vars['activities'] = $activities;
43 38
@@ -46,38 +41,36 @@
46 41
47 42
48 43 public function continue_order_intent() {
49 44 $order_intent_key = $this->params['order_intent_key'];
50 - $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key( $order_intent_key );
45 + $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key($order_intent_key);
51 46
52 - if ( $order_intent->is_new_record() ) {
47 + if($order_intent->is_new_record()){
53 48 http_response_code( 400 );
54 - OsDebugHelper::log( 'Order intent not found, id:' . $order_intent_key );
49 + OsDebugHelper::log('Order intent not found, id:'. $order_intent_key);
55 50 exit();
56 - } else {
51 + }else{
57 52
58 53 $order_intent->convert_to_order();
59 54
60 - nocache_headers();
61 - // Redirect with the intent key in either outcome, front.js resumes the booking flow at the confirmation
62 - // step when convert_to_order succeeded, or at the payment step when it didn't (e.g. cancelled Mollie/PayPal
63 - // payment). The "double payment information" issue is fixed at the cart-model layer (see
64 - // OsCartModel::clear) without that fix, the resume lightbox showed every cart item twice.
65 - wp_redirect( $order_intent->get_page_url_with_intent(), 302 );
66 - exit;
55 + if ( $order_intent ) {
56 + nocache_headers();
57 + wp_redirect( $order_intent->get_page_url_with_intent(), 302 );
58 + }
67 59 }
60 +
68 61 }
69 62
70 63
71 64 public function continue_transaction_intent() {
72 - $intent_key = $this->params['transaction_intent_key'];
73 - $transaction_intent = OsTransactionIntentHelper::get_transaction_intent_by_intent_key( $intent_key );
65 + $intent_key = $this->params['transaction_intent_key'];
66 + $transaction_intent = OsTransactionIntentHelper::get_transaction_intent_by_intent_key($intent_key);
74 67
75 - if ( $transaction_intent->is_new_record() ) {
68 + if($transaction_intent->is_new_record()){
76 69 http_response_code( 400 );
77 - OsDebugHelper::log( 'Transaction intent not found, id:' . $intent_key );
70 + OsDebugHelper::log('Transaction intent not found, id:'. $intent_key);
78 71 exit();
79 - } else {
72 + }else{
80 73 $transaction_intent->convert_to_transaction();
81 74
82 75 if ( $transaction_intent ) {
83 76 nocache_headers();
@@ -109,17 +102,8 @@
109 102 $validation_errors = [];
110 103
111 104 if ( ! empty( $this->params['order']['id'] ) ) {
112 105 $this->check_nonce( 'edit_order_' . $this->params['order']['id'] );
113 - $allowed_order = ( new OsOrderModel() )->where( [ LATEPOINT_TABLE_ORDERS . '.id' => absint( $this->params['order']['id'] ) ] )->filter_allowed_records()->set_limit( 1 )->get_results_as_models();
114 - if ( ! $allowed_order ) {
115 - $this->send_json(
116 - array(
117 - 'status' => LATEPOINT_STATUS_ERROR,
118 - 'message' => __( 'Not Allowed', 'latepoint' ),
119 - )
120 - );
121 - }
122 106 } else {
123 107 $this->check_nonce( 'new_order' );
124 108 }
125 109
@@ -125,10 +109,12 @@
125 109
126 110 $order_params = $this->params['order'];
127 111 $customer_params = $this->params['customer'];
128 112
113 +
129 114 $order_items_params = $this->params['order_items'] ?? [];
130 115
116 +
131 117 $order = new OsOrderModel( $order_params['id'] );
132 118
133 119 // if we are updating a order - save a copy by cloning old order
134 120 $old_order = ( $order->is_new_record() ) ? [] : clone $order;
@@ -133,10 +119,10 @@
133 119 // if we are updating a order - save a copy by cloning old order
134 120 $old_order = ( $order->is_new_record() ) ? [] : clone $order;
135 121 $order->set_data( $order_params );
136 122
123 +
137 124 // first validate & create a customer the customer
138 - $old_customer_data = [];
139 125 if ( $order->customer_id ) {
140 126 $customer = new OsCustomerModel( $order->customer_id );
141 127 $old_customer_data = $customer->get_data_vars();
142 128 $is_new_customer = false;
@@ -143,66 +129,44 @@
143 129 } else {
144 130 $customer = new OsCustomerModel();
145 131 $is_new_customer = true;
146 132 }
147 -
148 - // The submitted customer[...] fields may overwrite an EXISTING customer record only when
149 - // (1) the current user is authorized to edit that customer
150 - // (2) the customer is is an allowed customer list.
151 - // Attaching any customer to an order is always permitted; new customers proceed normally.
152 - if ( $is_new_customer || $customer->is_new_record() ) {
153 - $can_modify_customer = true;
154 - } else {
155 - $wp_link_is_safe = empty( $customer->wordpress_user_id )
156 - || OsCustomerHelper::is_wp_user_safe_for_customer_link( (int) $customer->wordpress_user_id );
157 - $can_modify_customer = $wp_link_is_safe
158 - && OsRolesHelper::can_user_make_action_on_model_record( $customer, 'edit' );
159 - }
160 -
161 - if ( $can_modify_customer ) {
162 - // Set customer data only if is allowed. Prevent mass assignment of wordpress_user_id.
163 - // Use admin scope for backend panel users (admin, agent, custom roles), otherwise restrict to public fields
164 - $customer->set_data( $customer_params, OsAuthHelper::get_current_user()->has_backend_access() ? LATEPOINT_PARAMS_SCOPE_ADMIN : LATEPOINT_PARAMS_SCOPE_PUBLIC );
165 - if ( $customer->save() ) {
166 - if ( $is_new_customer ) {
167 - do_action( 'latepoint_customer_created', $customer );
168 - $this->fields_to_update['order[customer_id]'] = $customer->id;
169 - } else {
170 - do_action( 'latepoint_customer_updated', $customer, $old_customer_data );
171 - }
172 -
173 - $order->customer_id = $customer->id;
133 + // Security fix: Prevent mass assignment of wordpress_user_id by non-admin users.
134 + // Use admin scope if user is authenticated as admin, otherwise restrict to public fields.
135 + $customer->set_data( $customer_params, OsAuthHelper::is_admin_logged_in() ? LATEPOINT_PARAMS_SCOPE_ADMIN : LATEPOINT_PARAMS_SCOPE_PUBLIC );
136 + if ( $customer->save() ) {
137 + if ( $is_new_customer ) {
138 + do_action( 'latepoint_customer_created', $customer );
139 + $this->fields_to_update['order[customer_id]'] = $customer->id;
174 140 } else {
175 - $this->send_json(
176 - [
177 - 'status' => LATEPOINT_STATUS_ERROR,
178 - // translators: %s is the description of an error
179 - 'message' => sprintf( __( 'Error: %s', 'latepoint' ), implode( ', ', $customer->get_error_messages() ) ),
180 - ]
181 - );
141 + do_action( 'latepoint_customer_updated', $customer, $old_customer_data );
182 142 }
143 +
144 + $order->customer_id = $customer->id;
145 + }else{
146 + $this->send_json( [
147 + 'status' => LATEPOINT_STATUS_ERROR,
148 + // translators: %s is the description of an error
149 + 'message' => sprintf(__( 'Error: %s', 'latepoint'), implode( ', ', $customer->get_error_messages() ) ),
150 + ]
151 + );
183 152 }
184 153
185 154 // validate order items
186 155 foreach ( $order_items_params as $order_item_id => $order_item ) {
187 156 foreach ( $order_item['bookings'] as $booking_id => $booking_params ) {
188 - $booking = OsOrdersHelper::create_booking_object_from_booking_data_form( $booking_params );
189 - $booking->customer_id = $order->customer_id;
190 - if ( ! $booking->validate( false, [ 'order_item_id' ] ) ) {
191 - $validation_errors = array_merge( $validation_errors, $booking->get_error_messages() );
157 + $booking = OsOrdersHelper::create_booking_object_from_booking_data_form( $booking_params );
158 + $booking->customer_id = $order->customer_id;
159 + if ( !$booking->validate(false, ['order_item_id']) ) {
160 + $validation_errors = array_merge($validation_errors, $booking->get_error_messages());
192 161 }
193 162 }
194 163 }
195 164
196 165 // check if there are errors saving bookings
197 - if ( $validation_errors ) {
166 + if($validation_errors){
198 167 // translators: %s is the description of an error
199 - $this->send_json(
200 - array(
201 - 'status' => LATEPOINT_STATUS_ERROR,
202 - 'message' => sprintf( __( 'Error: %s', 'latepoint' ), implode( ', ', $validation_errors ) ),
203 - )
204 - );
168 + $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => sprintf(__( 'Error: %s', 'latepoint'), implode( ', ', $validation_errors ) ) ) );
205 169 }
206 170
207 171 if ( $old_order ) {
208 172 // make sure old order items are still there, if not - remove them
@@ -232,9 +196,9 @@
232 196 * @hook latepoint_order_item_deleted
233 197 *
234 198 */
235 199 do_action( 'latepoint_order_item_deleted', $order_item_id_to_delete );
236 - OsActivitiesHelper::log_order_item_deleted( $order_item );
200 + OsActivitiesHelper::log_order_item_deleted($order_item);
237 201 } else {
238 202 // it's a bundle order item - search for bookings that are attached to this bundle and remove them if not found in passed params list
239 203 if ( $order_item->is_bundle() ) {
240 204 $old_bundle_bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item->id );
@@ -266,9 +230,9 @@
266 230 * @hook latepoint_booking_deleted
267 231 *
268 232 */
269 233 do_action( 'latepoint_booking_deleted', $booking_id_to_delete );
270 - OsActivitiesHelper::log_booking_deleted( $old_bundle_booking );
234 + OsActivitiesHelper::log_booking_deleted($old_bundle_booking);
271 235 } else {
272 236 OsDebugHelper::log( 'Not allowed: Deleting Booking', 'permissions_error' );
273 237 }
274 238 }
@@ -288,28 +252,28 @@
288 252 }
289 253
290 254 // save price breakdown, we only need to save before and after subtotal, as total and subtotal values are stored on the Order record itself
291 255 if ( ! empty( $this->params['price_breakdown'] ) ) {
292 - $order->price_breakdown = wp_json_encode( OsOrdersHelper::generate_price_breakdown_from_params( $this->params['price_breakdown'] ) );
256 + $order->price_breakdown = wp_json_encode( OsOrdersHelper::generate_price_breakdown_from_params($this->params['price_breakdown']) );
293 257 }
294 258
295 259 // Check if we have to create a payment request
296 - $create_payment_request = ( sanitize_text_field( $this->params['create_payment_request'] ?? '' ) == LATEPOINT_VALUE_ON );
297 - if ( $create_payment_request ) {
298 - $payment_request_data = $this->params['payment_request'];
299 - $payment_request_data['portion'] = sanitize_text_field( $payment_request_data['portion'] );
300 - $payment_request_data['charge_amount'] = sanitize_text_field( $payment_request_data[ 'charge_amount_' . $payment_request_data['portion'] ] );
301 - $payment_request_data['due_at'] = OsTimeHelper::custom_datetime_utc_in_db_format( sanitize_text_field( $payment_request_data['due_at'] ) . ' 23:59:59' );
302 - $order->set_initial_payment_data_value( 'time', LATEPOINT_PAYMENT_TIME_NOW, false );
303 - $order->set_initial_payment_data_value( 'portion', $payment_request_data['portion'], false );
304 - $order->set_initial_payment_data_value( 'charge_amount', OsMoneyHelper::convert_amount_from_money_input_to_db_format( $payment_request_data['charge_amount'] ) );
260 + $create_payment_request = (sanitize_text_field($this->params['create_payment_request'] ?? '') == LATEPOINT_VALUE_ON);
261 + if($create_payment_request){
262 + $payment_request_data = $this->params['payment_request'];
263 + $payment_request_data['portion'] = sanitize_text_field($payment_request_data['portion']);
264 + $payment_request_data['charge_amount'] = sanitize_text_field($payment_request_data['charge_amount_'.$payment_request_data['portion']]);
265 + $payment_request_data['due_at'] = OsTimeHelper::custom_datetime_utc_in_db_format(sanitize_text_field($payment_request_data['due_at']).' 23:59:59');
266 + $order->set_initial_payment_data_value('time', LATEPOINT_PAYMENT_TIME_NOW, false);
267 + $order->set_initial_payment_data_value('portion', $payment_request_data['portion'], false);
268 + $order->set_initial_payment_data_value('charge_amount', OsMoneyHelper::convert_amount_from_money_input_to_db_format($payment_request_data['charge_amount'], false));
305 269
306 270 $payment_request = new OsPaymentRequestModel();
307 271
308 - $payment_request = $payment_request->set_data( $payment_request_data );
272 + $payment_request = $payment_request->set_data($payment_request_data);
309 273
310 - } else {
311 - $order->set_initial_payment_data_value( 'time', LATEPOINT_PAYMENT_TIME_LATER );
274 + }else{
275 + $order->set_initial_payment_data_value('time', LATEPOINT_PAYMENT_TIME_LATER);
312 276 $payment_request = null;
313 277 }
314 278
315 279 if ( $order->save() ) {
@@ -382,11 +346,11 @@
382 346 $order_item_model->save();
383 347 }
384 348 if ( $old_booking ) {
385 349 do_action( 'latepoint_booking_updated', $booking, $old_booking );
386 - if ( $old_booking->status != $booking->status ) {
350 + if($old_booking->status != $booking->status){
387 351 do_action( 'latepoint_booking_change_status', $booking, $old_booking );
388 - OsActivitiesHelper::log_booking_change_status( $booking, $old_booking );
352 + OsActivitiesHelper::log_booking_change_status($booking, $old_booking);
389 353 }
390 354 } else {
391 355 do_action( 'latepoint_booking_created', $booking );
392 356 }
@@ -413,9 +377,9 @@
413 377 *
414 378 */
415 379 do_action( 'latepoint_order_updated', $order, $old_order );
416 380 } else {
417 - OsInvoicesHelper::create_invoices_for_new_order( $order, $payment_request );
381 + OsInvoicesHelper::create_invoices_for_new_order($order, $payment_request);
418 382 /**
419 383 * Order was created
420 384 *
421 385 * @param {OsOrderModel} $order instance of order model that was created
@@ -426,27 +390,23 @@
426 390 */
427 391 do_action( 'latepoint_order_created', $order );
428 392 }
429 393
430 - $status = LATEPOINT_STATUS_SUCCESS;
394 + $status = LATEPOINT_STATUS_SUCCESS;
431 395 // translators: %s is a link to the updated order
432 396 $response_html = sprintf( ( ( $old_order ) ? __( 'Order Updated ID: %s', 'latepoint' ) : __( 'Order Created ID: %s', 'latepoint' ) ), '<span class="os-notification-link" ' . OsOrdersHelper::quick_order_btn_html( $order->id ) . '>' . $order->id . '</span>' );
433 397 } else {
434 398 OsDebugHelper::log( 'Error saving order (admin)', 'order_save_error', $order->get_error_messages() );
435 - $status = LATEPOINT_STATUS_ERROR;
399 + $status = LATEPOINT_STATUS_ERROR;
436 400
437 401 // translators: %s is an error message
438 - $response_html = sprintf( __( 'Error: %s', 'latepoint' ), implode( ', ', $order->get_error_messages() ) );
402 + $response_html = sprintf(__( 'Error: %s', 'latepoint'), implode( ', ', $order->get_error_messages() ));
439 403 }
440 404
441 405 if ( $this->get_return_format() == 'json' ) {
442 - $this->send_json(
443 - array(
444 - 'status' => $status,
445 - 'message' => $response_html,
446 - )
447 - );
406 + $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
448 407 }
408 +
449 409 }
450 410
451 411
452 412 // reloads a section of a quick edit form that has a price breakdown
@@ -470,9 +430,9 @@
470 430 *
471 431 * @param {OsOrderModel} $order Order for which to reload price breakdown
472 432 * @returns {OsOrderModel} Filtered order with updated price breakdown rows
473 433 */
474 - $order = apply_filters( 'latepoint_order_reload_price_breakdown', $order );
434 + $order = apply_filters( 'latepoint_order_reload_price_breakdown', $order );
475 435
476 436 // we don't need to generate balance and payments info as it is printed in a separate block
477 437 $this->vars['price_breakdown_rows'] = $order->generate_price_breakdown_rows( [ 'balance', 'payments' ], true );
478 438
@@ -480,9 +440,9 @@
480 440 $this->format_render( __FUNCTION__ );
481 441 }
482 442
483 443 function reload_balance_and_payments() {
484 - $order_params = $this->params['order'];
444 + $order_params = $this->params['order'];
485 445 $order_items_params = $this->params['order_items'] ?? [];
486 446
487 447 $order = new OsOrderModel();
488 448 $order->set_data( $order_params );
@@ -508,20 +468,15 @@
508 468
509 469 function generate_bundle_order_item_block() {
510 470 $bundle = new OsBundleModel( $this->params['bundle_id'] );
511 471
512 - $order_item_id = OsUtilHelper::generate_form_id();
513 - $response_html = '<div class="order-item order-item-variant-bundle" data-order-item-id="' . $order_item_id . '">';
472 + $order_item_id = OsUtilHelper::generate_form_id();
473 + $response_html = '<div class="order-item order-item-variant-bundle" data-order-item-id="' . $order_item_id . '">';
514 474 $response_html .= OsOrdersHelper::generate_order_item_pill_for_bundle( $bundle, $order_item_id );
515 475 $response_html .= '</div>';
516 476
517 477 if ( $this->get_return_format() == 'json' ) {
518 - $this->send_json(
519 - array(
520 - 'status' => LATEPOINT_STATUS_SUCCESS,
521 - 'message' => $response_html,
522 - )
523 - );
478 + $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ) );
524 479 }
525 480 }
526 481
527 482 function generate_booking_order_item_block() {
@@ -531,11 +486,11 @@
531 486 $booking = OsBookingHelper::build_booking_model_from_item_data( json_decode( base64_decode( $this->params['booking_item_data'] ), true ) );
532 487 $response_html = OsOrdersHelper::booking_data_form_for_order_item_id( $this->params['order_item_id'], $booking, LATEPOINT_ITEM_VARIANT_BUNDLE, false );
533 488 } else {
534 489 // regular booking
535 - $booking = OsBookingHelper::prepare_new_from_params( $this->params );
536 - $order_item_id = OsUtilHelper::generate_form_id();
537 - $response_html = '<div class="order-item order-item-variant-booking" data-order-item-id="' . $order_item_id . '">';
490 + $booking = OsBookingHelper::prepare_new_from_params( $this->params );
491 + $order_item_id = OsUtilHelper::generate_form_id();
492 + $response_html = '<div class="order-item order-item-variant-booking" data-order-item-id="' . $order_item_id . '">';
538 493 $response_html .= OsOrdersHelper::booking_data_form_for_order_item_id( $order_item_id, $booking, LATEPOINT_ITEM_VARIANT_BOOKING, false );
539 494 $response_html .= '</div>';
540 495 }
541 496
@@ -540,14 +495,9 @@
540 495 }
541 496
542 497
543 498 if ( $this->get_return_format() == 'json' ) {
544 - $this->send_json(
545 - array(
546 - 'status' => LATEPOINT_STATUS_SUCCESS,
547 - 'message' => $response_html,
548 - )
549 - );
499 + $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ) );
550 500 }
551 501 }
552 502
553 503 function fold_booking_data_form() {
@@ -562,14 +512,9 @@
562 512 $response_html = OsOrdersHelper::generate_order_item_pill_for_bundle_booking( $booking, $order_item_id );
563 513 } else {
564 514 $response_html = OsOrdersHelper::generate_order_item_pill_for_booking( $booking, $order_item_id );
565 515 }
566 - $this->send_json(
567 - array(
568 - 'status' => LATEPOINT_STATUS_SUCCESS,
569 - 'message' => $response_html,
570 - )
571 - );
516 + $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ) );
572 517 }
573 518
574 519 function generate_order_item_booking_data_form() {
575 520 $order_item = new OsOrderItemModel();
@@ -593,14 +538,9 @@
593 538 $booking = OsBookingHelper::prepare_new_from_params( $this->params );
594 539 }
595 540
596 541 $response_html = OsOrdersHelper::booking_data_form_for_order_item_id( $order_item->get_form_id(), $booking, $order_item->variant );
597 - $this->send_json(
598 - array(
599 - 'status' => LATEPOINT_STATUS_SUCCESS,
600 - 'message' => $response_html,
601 - )
602 - );
542 + $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ) );
603 543 }
604 544
605 545 function quick_edit() {
606 546
@@ -628,13 +568,13 @@
628 568 }
629 569
630 570 if ( $order_id ) {
631 571 // EDITING EXISTING ORDER
632 - $order = ( new OsOrderModel() )->where( [ LATEPOINT_TABLE_ORDERS . '.id' => absint( $order_id ) ] )->filter_allowed_records()->set_limit( 1 )->get_results_as_models();
633 - if ( ! $order ) {
634 - $this->access_not_allowed();
635 - return;
636 - }
572 + $order = new OsOrderModel( $order_id );
573 + // TODO add this check for order
574 +// if(!OsRolesHelper::can_user_make_action_on_model_record($order, 'view')){
575 +// $this->send_json(array('status' => LATEPOINT_STATUS_ERROR, 'message' => 'Not Allowed'));
576 +// }
637 577
638 578 $transactions = $order->get_transactions();
639 579
640 580 } else {
@@ -687,52 +627,27 @@
687 627 $this->vars['default_fields_for_customer'] = OsSettingsHelper::get_default_fields_for_customer();
688 628 $this->format_render( __FUNCTION__ );
689 629 }
690 630
691 - /**
692 - * Legacy method. Not used anymore.
693 - * But kept for backward compatibility with old code that might be using it
694 - */
695 - // public function edit_form() {
696 - // if ( empty( $this->params['id'] ) ) {
697 - // $order = new OsOrderModel();
698 - // } else {
699 - // $order = ( new OsOrderModel() )->where( [ LATEPOINT_TABLE_ORDERS . '.id' => absint( $this->params['id'] ) ] )->filter_allowed_records()->set_limit( 1 )->get_results_as_models();
700 - // if ( ! $order ) {
701 - // $this->send_json(
702 - // array(
703 - // 'status' => LATEPOINT_STATUS_ERROR,
704 - // 'message' => __( 'Not Allowed', 'latepoint' ),
705 - // )
706 - // );
707 - // return;
708 - // }
709 - // }
710 - // // legacy fix for older orders that didn't have portion column, get it from connected order
711 - // if ( ! $order->is_new_record() && empty( $order->payment_portion ) && ! empty( $order->booking_id ) ) {
712 - // $booking = new OsBookingModel( $order->booking_id );
713 - // if ( ! empty( $booking->id ) ) {
714 - // $order->payment_portion = $booking->payment_portion;
715 - // }
716 - // }
717 - // $this->vars['real_or_rand_id'] = ( $order->is_new_record() ) ? 'new_order_' . OsUtilHelper::random_text( 'alnum', 5 ) : $order->id;
718 - // $this->vars['order'] = $order;
631 + public function edit_form() {
632 + $order = ( empty( $this->params['id'] ) ) ? new OsOrderModel() : new OsOrderModel( $this->params['id'] );
633 + // legacy fix for older orders that didn't have portion column, get it from connected order
634 + if ( ! $order->is_new_record() && empty( $order->payment_portion ) && ! empty( $order->booking_id ) ) {
635 + $booking = new OsBookingModel( $order->booking_id );
636 + if ( ! empty( $booking->id ) ) {
637 + $order->payment_portion = $booking->payment_portion;
638 + }
639 + }
640 + $this->vars['real_or_rand_id'] = ( $order->is_new_record() ) ? 'new_order_' . OsUtilHelper::random_text( 'alnum', 5 ) : $order->id;
641 + $this->vars['order'] = $order;
719 642
720 - // $this->format_render( __FUNCTION__ );
721 - // }
643 + $this->format_render( __FUNCTION__ );
644 + }
722 645
723 646 public function destroy() {
724 647 if ( filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
725 648 $this->check_nonce( 'destroy_order_' . $this->params['id'] );
726 - $order = ( new OsOrderModel() )->where( [ LATEPOINT_TABLE_ORDERS . '.id' => absint( $this->params['id'] ) ] )->filter_allowed_records()->set_limit( 1 )->get_results_as_models();
727 - if ( ! $order ) {
728 - $this->send_json(
729 - array(
730 - 'status' => LATEPOINT_STATUS_ERROR,
731 - 'message' => __( 'Not Allowed', 'latepoint' ),
732 - )
733 - );
734 - }
649 + $order = new OsOrderModel( $this->params['id'] );
735 650 if ( $order->delete() ) {
736 651 $status = LATEPOINT_STATUS_SUCCESS;
737 652 $response_html = __( 'Order Removed', 'latepoint' );
738 653 } else {
@@ -743,14 +658,9 @@
743 658 $status = LATEPOINT_STATUS_ERROR;
744 659 $response_html = __( 'Error Removing Order', 'latepoint' );
745 660 }
746 661 if ( $this->get_return_format() == 'json' ) {
747 - $this->send_json(
748 - array(
749 - 'status' => $status,
750 - 'message' => $response_html,
751 - )
752 - );
662 + $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
753 663 }
754 664 }
755 665
756 666 /*
@@ -758,10 +668,10 @@
758 668 */
759 669
760 670 public function index() {
761 671
762 - $per_page = OsSettingsHelper::get_number_of_records_per_page();
763 - $page_number = isset( $this->params['page_number'] ) ? $this->params['page_number'] : 1;
672 + $per_page = OsSettingsHelper::get_number_of_records_per_page();
673 + $page_number = isset($this->params['page_number']) ? $this->params['page_number'] : 1;
764 674
765 675 $this->vars['page_header'] = false;
766 676
767 677 $orders = new OsOrderModel();
@@ -794,9 +704,9 @@
794 704 $orders->select( LATEPOINT_TABLE_ORDERS . '.*, ' . LATEPOINT_TABLE_CUSTOMERS . '.first_name, ' . LATEPOINT_TABLE_CUSTOMERS . '.last_name' );
795 705 $orders->join( LATEPOINT_TABLE_CUSTOMERS, [ 'id' => LATEPOINT_TABLE_ORDERS . '.customer_id' ] );
796 706
797 707 $query_args[ 'concat_ws(" ", ' . LATEPOINT_TABLE_CUSTOMERS . '.first_name,' . LATEPOINT_TABLE_CUSTOMERS . '.last_name) LIKE' ] = '%' . $filter['customer']['full_name'] . '%';
798 - $this->vars['customer_name_query'] = $filter['customer']['full_name'];
708 + $this->vars['customer_name_query'] = $filter['customer']['full_name'];
799 709
800 710 }
801 711
802 712 if ( ! empty( $filter['created_at_from'] ) && ! empty( $filter['created_at_to'] ) ) {
@@ -807,11 +717,11 @@
807 717
808 718
809 719 // OUTPUT CSV IF REQUESTED
810 720 if ( isset( $this->params['download'] ) && $this->params['download'] == 'csv' ) {
811 - $csv_filename = 'orders_' . OsUtilHelper::random_text() . '.csv';
721 + $csv_filename = 'payments_' . OsUtilHelper::random_text() . '.csv';
812 722
813 - header( 'Content-Type: text/csv' );
723 + header( "Content-Type: text/csv" );
814 724 header( "Content-Disposition: attachment; filename={$csv_filename}" );
815 725
816 726 $labels_row = [
817 727 __( 'ID', 'latepoint' ),
@@ -822,9 +732,9 @@
822 732 __( 'Method', 'latepoint' ),
823 733 __( 'Amount', 'latepoint' ),
824 734 __( 'Status', 'latepoint' ),
825 735 __( 'Type', 'latepoint' ),
826 - __( 'Date', 'latepoint' ),
736 + __( 'Date', 'latepoint' )
827 737 ];
828 738
829 739
830 740 $orders_data = [];
@@ -841,9 +751,9 @@
841 751 $order->booking_id,
842 752 ( $order->customer_id ? $order->customer->full_name : 'n/a' ),
843 753 $order->processor,
844 754 $order->payment_method,
845 - OsMoneyHelper::format_price( $order->total, true, false ),
755 + OsMoneyHelper::format_price( $order->amount, true, false ),
846 756 $order->status,
847 757 $order->kind,
848 758 $order->created_at,
849 759 ];
@@ -849,8 +759,9 @@
849 759 ];
850 760 $values_row = apply_filters( 'latepoint_order_row_for_csv_export', $values_row, $order, $this->params );
851 761 $orders_data[] = $values_row;
852 762 }
763 +
853 764 }
854 765
855 766 $orders_data = apply_filters( 'latepoint_orders_data_for_csv_export', $orders_data, $this->params );
856 767 OsCSVHelper::array_to_csv( $orders_data );
@@ -882,22 +793,20 @@
882 793
883 794 $this->vars['showing_from'] = ( ( $page_number - 1 ) * $per_page ) ? ( ( $page_number - 1 ) * $per_page ) : 1;
884 795 $this->vars['showing_to'] = min( $page_number * $per_page, $total_orders );
885 796
886 - $this->format_render(
887 - [
888 - 'json_view_name' => '_table_body',
889 - 'html_view_name' => __FUNCTION__,
890 - ],
891 - [],
892 - [
893 - 'total_pages' => $total_pages,
894 - 'showing_from' => $this->vars['showing_from'],
895 - 'showing_to' => $this->vars['showing_to'],
896 - 'total_records' => $total_orders,
897 - ]
898 - );
797 + $this->format_render( [
798 + 'json_view_name' => '_table_body',
799 + 'html_view_name' => __FUNCTION__
800 + ], [], [
801 + 'total_pages' => $total_pages,
802 + 'showing_from' => $this->vars['showing_from'],
803 + 'showing_to' => $this->vars['showing_to'],
804 + 'total_records' => $total_orders
805 + ] );
899 806 }
807 +
808 +
900 809 }
901 810
902 811
903 -endif;
812 +endif;