PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.7
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.7
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 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / steps_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 year ago auth_controller.php 1 year ago booking_form_settings_controller.php 1 year ago bookings_controller.php 1 year ago calendars_controller.php 1 year ago carts_controller.php 1 year ago controller.php 1 year ago customer_cabinet_controller.php 1 year ago customers_controller.php 1 year ago dashboard_controller.php 1 year ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 1 year ago integrations_controller.php 1 year ago invoices_controller.php 1 year ago manage_booking_by_key_controller.php 1 year ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 1 year ago pro_controller.php 1 year ago process_jobs_controller.php 1 year ago processes_controller.php 1 year ago search_controller.php 1 year ago services_controller.php 1 year ago settings_controller.php 1 year ago steps_controller.php 1 year ago stripe_connect_controller.php 1 year ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 1 year ago wizard_controller.php 1 year ago
steps_controller.php
298 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsStepsController' ) ) :
8
9
10 class OsStepsController extends OsController {
11
12 private $booking;
13
14 function __construct() {
15 parent::__construct();
16 $this->action_access['customer'] = array_merge( $this->action_access['customer'], [ 'start_from_order_intent' ] );
17 $this->action_access['public'] = array_merge( $this->action_access['public'], [
18 'start',
19 'load_step',
20 'reload_booking_form_summary_panel',
21 'check_order_intent_bookable',
22 'load_datepicker_month'
23 ] );
24
25 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'steps/';
26 $this->vars['page_header'] = __( 'Appointments', 'latepoint' );
27 $this->vars['breadcrumbs'][] = array(
28 'label' => __( 'Appointments', 'latepoint' ),
29 'link' => OsRouterHelper::build_link( [
30 'bookings',
31 'pending_approval'
32 ] )
33 );
34 }
35
36 public function load_datepicker_month() {
37 OsStepsHelper::set_required_objects( $this->params );
38
39 $target_date = new OsWpDateTime( $this->params['target_date_string'] );
40 $calendar_settings = [
41 'layout' => $this->params['calendar_layout'] ?? 'classic',
42 'timezone_name' => $this->params['timezone_name'] ?? false,
43 ];
44
45 $calendar_settings['earliest_possible_booking'] = OsSettingsHelper::get_settings_value( 'earliest_possible_booking', false );
46 $calendar_settings['latest_possible_booking'] = OsSettingsHelper::get_settings_value( 'latest_possible_booking', false );
47
48 $this->format_render( 'partials/_monthly_calendar_days', [
49 'target_date' => $target_date,
50 'calendar_settings' => $calendar_settings,
51 'booking_request' => \LatePoint\Misc\BookingRequest::create_from_booking_model( OsStepsHelper::$booking_object )
52 ] );
53 }
54
55
56 public function check_order_intent_bookable() {
57 OsStepsHelper::set_required_objects( $this->params );
58 if(OsStepsHelper::$cart_object->order_id){
59 // already converted, so we are good
60 $this->send_json( [
61 'status' => LATEPOINT_STATUS_SUCCESS,
62 'message' => __( 'Cart has already been converted to order', 'latepoint' )
63 ] );
64 }
65 $order_intent = OsOrderIntentHelper::create_or_update_order_intent( OsStepsHelper::$cart_object, OsStepsHelper::$restrictions, OsStepsHelper::$presets );
66 if ( $order_intent->is_bookable() ) {
67 $this->send_json( [
68 'status' => LATEPOINT_STATUS_SUCCESS,
69 'message' => __( 'Order intent can be converted to order', 'latepoint' )
70 ] );
71 } else {
72 $this->send_json( [
73 'status' => LATEPOINT_STATUS_ERROR,
74 'message' => __( 'Selected booking slot is not available anymore. Please pick a different time slot.', 'latepoint' )
75 ] );
76 }
77 }
78
79
80 function reload_booking_form_summary_panel() {
81 OsStepsHelper::set_required_objects( $this->params );
82 $this->vars['cart'] = OsStepsHelper::$cart_object;
83
84 if ( OsStepsHelper::is_ready_for_summary() ) {
85 $this->vars['booking'] = OsStepsHelper::$booking_object;
86 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
87
88 if ( $this->get_return_format() == 'json' ) {
89 $response_html = $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', 'none' );
90 wp_send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => $response_html ] );
91 exit();
92 } else {
93 echo $this->render( $this->views_folder . 'partials/_booking_form_summary_panel', $this->get_layout() );
94 }
95 } else {
96 wp_send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => '' ] );
97 }
98
99 }
100
101
102 public function start_from_order_intent() {
103 $order_intent = OsOrderIntentHelper::get_order_intent_by_intent_key($this->params['order_intent_key']);
104
105 if ( !$order_intent->is_new_record() ) {
106 $step_codes_to_preload = [];
107 $steps = OsStepsHelper::get_steps();
108 OsStepsHelper::set_required_objects($this->params);
109
110 if ( $order_intent->order_id ) {
111 // if order is created - load it
112 OsStepsHelper::load_order_object( $order_intent->order_id );
113 $current_step_code = 'confirmation';
114 $current_step = $steps[ $current_step_code ];
115
116 $this->vars['price_breakdown_rows'] = OsStepsHelper::$order_object->generate_price_breakdown_rows();
117
118 $steps = [ 'confirmation' => $steps['confirmation'] ];
119
120
121 } else {
122
123 OsStepsHelper::set_cart_object_from_order_intent( $order_intent );
124 $current_step_code = 'verify';
125 $current_step = $steps[ $current_step_code ];
126
127
128 foreach ( OsStepsHelper::$step_codes_in_order as $step_code ) {
129 if ( $step_code == $current_step_code ) {
130 break;
131 } else {
132 $step_codes_to_preload[] = $step_code;
133 }
134 }
135
136 $this->vars['price_breakdown_rows'] = OsStepsHelper::$cart_object->generate_price_breakdown_rows();
137 // order exists - only load confirmation step
138 $this->vars['step_codes_to_preload'] = $step_codes_to_preload;
139
140 }
141
142 $this->vars['cart'] = OsStepsHelper::$cart_object;
143 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step_code );
144 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step_code );
145 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
146 $this->vars['steps'] = $steps;
147 $this->vars['current_step'] = $current_step;
148
149 $this->vars['current_step_code'] = $current_step_code;
150 $this->vars['booking'] = OsStepsHelper::$booking_object;
151 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
152 $this->vars['restrictions'] = OsStepsHelper::$restrictions;
153 $this->vars['presets'] = OsStepsHelper::$presets;
154 $this->vars['booking_element_type'] = 'lightbox';
155 $this->vars['booking_element_styles'] = [];
156
157
158
159
160
161 $this->set_layout( 'none' );
162
163 $this->format_render( 'start', array(), array( 'lightbox_class' => '' ) );
164 } else {
165 $this->send_json( array(
166 'status' => LATEPOINT_STATUS_ERROR,
167 'message' => __( 'Invalid order intent key', 'latepoint' )
168 ) );
169 }
170
171 }
172
173 public function start( array $custom_restrictions = [], array $custom_presets = [], array $booking_element_styles = [], bool $output = true, string $booking_element_type = 'lightbox' ) {
174 $merged_params = $this->params;
175
176 if ( ! empty( $custom_restrictions ) ) {
177 $merged_params['restrictions'] = $custom_restrictions;
178 }
179 if ( ! empty( $custom_presets ) ) {
180 $merged_params['presets'] = $custom_presets;
181 }
182 if( ! empty( $this->params['booking_element_type'] ) ) {
183 $booking_element_type = $this->params['booking_element_type'];
184 }
185
186
187 if(!empty($merged_params['booking_element_styles'])){
188 $booking_element_styles = array_merge( $booking_element_styles, $merged_params['booking_element_styles'] );
189 }
190
191 // set early to check if it's converted or should be emptied
192 OsStepsHelper::set_cart_object();
193 if(!empty(OsStepsHelper::$cart_object->order_id)){
194 OsCartsHelper::reset_cart();
195 OsStepsHelper::set_cart_object();
196 }
197 // clear cart if "shopping cart" feature is not enabled
198 if ( ! OsCartsHelper::can_checkout_multiple_items() ) OsStepsHelper::$cart_object->clear();
199
200
201
202
203 OsStepsHelper::set_required_objects( $merged_params );
204
205 $steps = OsStepsHelper::get_steps();
206
207 $current_step_code = OsStepsHelper::get_step_codes_in_order()[0];
208
209 if ( OsStepsHelper::should_step_be_skipped( $current_step_code ) ) {
210 $current_step_code = OsStepsHelper::get_next_step_code( $current_step_code );
211 }
212 // check if all booking steps have to be skipped, if so - it means the booking object is ready and we can add it to the cart
213 $ready_to_add_to_cart = true;
214 if(OsStepsHelper::$active_cart_item->is_booking()){
215 foreach($steps as $step_code => $step_object) {
216 $step_main_parent_code = explode('__', $step_code);
217 if(!empty($step_main_parent_code[0]) && $step_main_parent_code[0] == 'booking'){
218 $ready_to_add_to_cart = false;
219 break;
220 }
221 }
222 }
223 // looks like item is ready to be added to cart (because all necessary steps/presets where applied in a trigger element), add it to cart
224 if($ready_to_add_to_cart){
225 try{
226 OsStepsHelper::add_current_item_to_cart();
227 }catch(Exception $e){
228 $this->vars['booking'] = OsStepsHelper::$booking_object;
229 if ( $output ) {
230 $this->format_render( 'preset_slot_not_available' );
231 return false;
232 } else {
233 return $this->format_render_return( 'preset_slot_not_available' );
234 }
235 }
236 }
237 $current_step = $steps[ $current_step_code ];
238
239 $this->vars['cart'] = OsStepsHelper::$cart_object;
240 $this->vars['show_next_btn'] = OsStepsHelper::can_step_show_next_btn( $current_step->code );
241 $this->vars['show_prev_btn'] = OsStepsHelper::can_step_show_prev_btn( $current_step->code );
242 $this->vars['all_steps'] = OsStepsHelper::get_steps( true );
243 $this->vars['steps'] = $steps;
244 $this->vars['current_step'] = $current_step;
245
246 $this->vars['current_step_code'] = $current_step->code;
247 $this->vars['booking'] = OsStepsHelper::$booking_object;
248 $this->vars['active_cart_item'] = OsStepsHelper::$active_cart_item;
249 $this->vars['restrictions'] = OsStepsHelper::$restrictions;
250 $this->vars['presets'] = OsStepsHelper::$presets;
251 $this->vars['booking_element_type'] = $booking_element_type;
252 $this->vars['booking_element_styles'] = $booking_element_styles;
253
254 $this->set_layout( 'none' );
255
256
257
258 if ( $output ) {
259 $this->format_render( __FUNCTION__, [], [ 'step' => $current_step->code ] );
260 } else {
261 return $this->format_render_return( __FUNCTION__, [], [ 'step' => $current_step->code ] );
262 }
263 }
264
265
266 public function load_step() {
267 OsStepsHelper::set_required_objects( $this->params );
268
269 $current_step_code = OsStepsHelper::retrieve_step_code( $this->params['current_step_code'] );
270 if ( empty( $current_step_code ) ) {
271 return false;
272 }
273
274 $step_direction = $this->params['step_direction'] ?? 'next';
275 $step_code_to_load = false;
276 switch ( $step_direction ) {
277 case 'next':
278 do_action( 'latepoint_process_step', $current_step_code, OsStepsHelper::$booking_object );
279 $step_code_to_load = OsStepsHelper::get_next_step_code( $current_step_code );
280 break;
281 case 'prev':
282 $step_code_to_load = OsStepsHelper::get_prev_step_code( $current_step_code );
283 break;
284 case 'specific':
285 $step_code_to_load = OsStepsHelper::should_step_be_skipped( $current_step_code ) ? OsStepsHelper::get_next_step_code( $current_step_code ) : $current_step_code;
286 break;
287 }
288 if ( $step_code_to_load ) {
289 do_action( 'latepoint_load_step', $step_code_to_load, 'json', $this->params );
290 }
291 }
292
293
294 }
295
296
297 endif;
298