PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.4
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.4
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 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 / helpers / bundles_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year ago whatsapp_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
bundles_helper.php
231 lines
1 <?php
2
3 class OsBundlesHelper {
4
5 public static function generate_order_summary_for_bundle(OsBundleModel $bundle, string $order_item_id, $preselected_booking_id = false): string{
6 $html = '<div class="summary-box main-box">';
7
8 $bundle_services = $bundle->get_services();
9 $bundle_services_descriptions = [];
10 $total_bookable_quantity = 0;
11 foreach ($bundle_services as $service) {
12 $qty = $service->join_attributes['quantity'];
13 $qty_html = $qty > 1 ? ' [' . $qty . ']' : '';
14 $bundle_services_descriptions[] = $service->name . $qty_html;
15 $total_bookable_quantity+= $qty;
16 }
17 $html.= '<div class="summary-box-content is-removable">
18 <div class="sbc-big-item">'.$bundle->name.'</div>
19 <div class="sbc-subtle-item">
20 '.implode(', ', $bundle_services_descriptions).'
21 </div>
22 </div>';
23
24
25 $past_count = 0;
26 $booked_count = 0;
27
28 // translators: %s is the name of the bundle
29 $html.= '<div class="hidden-bundle-items-notice"><div class="hidden-bundle-items-notice-message">'.sprintf(__('Part of a %s bundle.', 'latepoint'), '<strong>"'.$bundle->name.'"</strong>').'</div><div class="hidden-bundle-items-notice-link">'.__('Show Full Bundle', 'latepoint').'</div></div>';
30 $html.= '<div class="bookable-items-breakdown">';
31 foreach ($bundle_services as $service) {
32 $bookings = (strpos($order_item_id, 'new_') === false) ? OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses()) : [];
33 foreach($bookings as $booking){
34 $booked_count++;
35 if(!$booking->is_upcoming()) $past_count++;
36 }
37 // translators: %d is the number of sessions
38 if(count($bundle_services) > 1) $html.= '<div class="bundle-service-info">'.$service->name.' ['.sprintf(__('%d sessions', 'latepoint'), $service->join_attributes['quantity']).']</div>';
39 for($i = 0; $i < $service->join_attributes['quantity']; $i++){
40 $html.= '<div class="order-item-variant-bundle-booking-wrapper">';
41 $booking = isset($bookings[$i]) ? new OsBookingModel($bookings[$i]->id) : OsBookingHelper::prepare_new_from_params(['service_id' => $service->id]);
42 $booking->service_id = $service->id;
43 $is_preselected = (!$booking->is_new_record() && $preselected_booking_id == $booking->id);
44 $html.= OsOrdersHelper::generate_booking_block_for_bundle_order_item($booking, $order_item_id, isset($bookings[$i]), $is_preselected);
45 $html.= '</div>';
46 }
47 if(strpos($order_item_id, 'new_') === false){
48 // existing order, find cancelled bookings
49 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, [LATEPOINT_BOOKING_STATUS_CANCELLED]);
50 if(!empty($cancelled_bookings)){
51 $html.= '<div class="order-item-cancelled-bookings-wrapper">';
52 // translators: %d is the number of cancelled appointments
53 $html.= '<div class="order-item-cancelled-bookings-heading">'.sprintf(_n('%d Cancelled Appointment', '%d Cancelled Appointments', count($cancelled_bookings), 'latepoint'), count($cancelled_bookings)).'</div>';
54 $html.= '<div class="order-item-cancelled-bookings-list">';
55 foreach($cancelled_bookings as $booking){
56 $html.= '<div class="order-item-variant-bundle-booking-wrapper">';
57 $html.= OsOrdersHelper::generate_booking_block_for_bundle_order_item($booking, $order_item_id, true, ($preselected_booking_id == $booking->id));
58 $html.= '</div>';
59 }
60 $html.= '</div>';
61 $html.= '</div>';
62 }
63 }
64 }
65 $html.= '</div>';
66 $html.= '<div class="bookable-items">';
67 for($i = 1; $i <= $total_bookable_quantity; $i++){
68 $is_past = ($i <= $past_count) ? 'is-past' : '';
69 $is_booked = ($i <= $booked_count) ? 'is-booked' : '';
70 $html.= '<div class="bookable-item '.$is_past.' '.$is_booked.'"></div>';
71 }
72 $html.= '</div>';
73
74 $html.= '</div>';
75
76 return $html;
77 }
78
79 public static function generate_summary_for_bundle(OsBundleModel $bundle, $cart_item_id = false, $order_item_id = false, $user_type = LATEPOINT_USER_TYPE_ADMIN){
80 ob_start();
81 ?>
82 <div class="summary-box main-box" <?php if($cart_item_id) echo 'data-cart-item-id="'.esc_attr($cart_item_id).'"'; ?>>
83 <?php
84 $bundle_headings = [];
85 $bundle_headings = apply_filters('latepoint_order_summary_bundle_headings', $bundle_headings, $bundle);
86 if ($bundle_headings) {
87 echo '<div class="summary-box-heading">';
88 foreach ($bundle_headings as $heading) {
89 echo '<div class="sbh-item">' . esc_html($heading) . '</div>';
90 }
91 echo '<div class="sbh-line"></div>';
92 echo '</div>';
93 }
94 $bundle_services = $bundle->get_services();
95 $bundle_services_descriptions = [];
96 $total_bookable_quantity = 0;
97 foreach ($bundle_services as $service) {
98 $qty = $service->join_attributes['quantity'];
99 $qty_html = $qty > 1 ? ' [' . $qty . ']' : '';
100 $bundle_services_descriptions[] = $service->name . $qty_html;
101 $total_bookable_quantity+= $qty;
102 }
103 ?>
104 <div class="summary-box-content <?php if($cart_item_id) echo 'os-cart-item'; ?> is-removable">
105 <?php if($cart_item_id && OsCartsHelper::can_checkout_multiple_items()){ ?>
106 <div class="os-remove-item-from-cart" role="button"
107 tabindex="0"
108 data-confirm-text="<?php esc_attr_e('Are you sure you want to remove this item from your cart?', 'latepoint'); ?>"
109 data-cart-item-id="<?php echo esc_attr($cart_item_id); ?>"
110 data-route="<?php echo esc_attr(OsRouterHelper::build_route_name('carts', 'remove_item_from_cart')); ?>"><i
111 class="latepoint-icon latepoint-icon-minus"></i></div>
112 <?php } ?>
113 <div class="sbc-big-item"><?php echo esc_html($bundle->name); ?></div>
114 <div class="sbc-subtle-item">
115 <?php echo esc_html(implode(', ', $bundle_services_descriptions)); ?>
116 </div>
117 </div>
118 <?php if($order_item_id){
119 $past_count = 0;
120 $booked_count = 0;
121 if($user_type == LATEPOINT_USER_TYPE_CUSTOMER){
122 $order_item = new OsOrderItemModel($order_item_id);
123 $order = new OsOrderModel($order_item->order_id);
124 // translators: %s is the order confirmation code
125 echo '<div class="bundle-order-small-info">'.sprintf(esc_html__('Order %s', 'latepoint'), '<a href="#" '.OsCustomerHelper::generate_order_summary_btn($order->id).'>#'.esc_html($order->confirmation_code).'</a>').'</div>';
126 }
127 echo '<div class="bookable-items-breakdown">';
128 foreach ($bundle_services as $service) {
129 $bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses());
130 foreach($bookings as $booking){
131 $booked_count++;
132 if(!$booking->is_upcoming()) $past_count++;
133 }
134 // translators: %d is the number of sessions
135 if(count($bundle_services) > 1) echo '<div class="bundle-service-info">'.esc_html($service->name.' ['.sprintf(__('%d sessions', 'latepoint'), $service->join_attributes['quantity']).']').'</div>';
136 for($i = 0; $i < $service->join_attributes['quantity']; $i++){
137 if(isset($bookings[$i])){
138 $is_past = (!$bookings[$i]->is_upcoming()) ? 'is-past' : '';
139 $trigger_html = ($user_type == LATEPOINT_USER_TYPE_CUSTOMER) ? OsCustomerHelper::generate_booking_summary_preview_btn($bookings[$i]->id) : OsBookingHelper::quick_booking_btn_html($bookings[$i]->id);
140 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-'.esc_attr($bookings[$i]->status).' '.$is_past.'" '.$trigger_html.'>
141 <div class="booking-item-status-pill"></div>
142 <div class="bib-datetime">'.esc_html($bookings[$i]->get_nice_start_datetime()).'</div>
143 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
144 </div>';
145 }else{
146 if($user_type == LATEPOINT_USER_TYPE_CUSTOMER){
147 echo '<div class="order-item-variant-bundle-booking os_trigger_booking" data-hide-side-panel="yes" data-hide-summary="yes" data-order-item-id="'.esc_attr($order_item_id).'" data-selected-service="'.esc_attr($service->id).'"><div class="booking-item-status-pill"></div><div class="bib-label">'.esc_html__('Schedule now', 'latepoint').'</div></div>';
148 }else{
149 echo '<div class="order-item-variant-bundle-booking" '.OsOrdersHelper::quick_order_btn_html(false, ['order_item_id' => $order_item_id, 'service_id' => $service->id]).'><div class="booking-item-status-pill"></div><div class="bib-label">'.esc_html__('Schedule now', 'latepoint').'</div></div>';
150 }
151 }
152 }
153 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, [LATEPOINT_BOOKING_STATUS_CANCELLED]);
154 if(!empty($cancelled_bookings)){
155 echo '<div class="order-item-cancelled-bookings-wrapper">';
156 // translators: %d is the number of cancelled appointments
157 echo '<div class="order-item-cancelled-bookings-heading">'.esc_html(sprintf(_n('%d Cancelled Appointment', '%d Cancelled Appointments', count($cancelled_bookings), 'latepoint'), count($cancelled_bookings))).'</div>';
158 echo '<div class="order-item-cancelled-bookings-list">';
159 foreach($cancelled_bookings as $cancelled_booking){
160 echo '<div class="order-item-variant-bundle-booking-wrapper">';
161 $is_past = (!$cancelled_booking->is_upcoming()) ? 'is-past' : '';
162 $trigger_html = ($user_type == LATEPOINT_USER_TYPE_CUSTOMER) ? OsCustomerHelper::generate_booking_summary_preview_btn($cancelled_booking->id) : OsBookingHelper::quick_booking_btn_html($cancelled_booking->id);
163 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-'.esc_attr($cancelled_booking->status).' '.$is_past.'" '.$trigger_html.'>
164 <div class="booking-item-status-pill"></div>
165 <div class="bib-datetime">'.esc_html($cancelled_booking->get_nice_start_datetime()).'</div>
166 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
167 </div>';
168 echo '</div>';
169 }
170 echo '</div>';
171 echo '</div>';
172 }
173 }
174 echo '</div>';
175 echo '<div class="bookable-items">';
176 for($i = 1; $i <= $total_bookable_quantity; $i++){
177 $is_past = ($i <= $past_count) ? 'is-past' : '';
178 $is_booked = ($i <= $booked_count) ? 'is-booked' : '';
179 echo '<div class="bookable-item '.esc_attr($is_past).' '.esc_attr($is_booked).'"></div>';
180 }
181 echo '</div>';
182
183 }
184 ?>
185 </div>
186 <?php
187 $response_html = ob_get_clean();
188 return $response_html;
189 }
190
191 /**
192 * @param array $item_data
193 * @return OsBundleModel
194 */
195 public static function build_bundle_model_from_item_data(array $item_data): OsBundleModel{
196 $bundle = new OsBundleModel();
197 if(!empty($item_data['bundle_id'])) $bundle = $bundle->load_by_id($item_data['bundle_id']);
198 return $bundle;
199 }
200
201
202 /**
203 * @param OsBundleModel $bundle
204 * @return mixed|void
205 *
206 * Returns full amount to charge in database format 1999.0000
207 *
208 */
209 public static function calculate_full_amount_for_bundle(OsBundleModel $bundle) {
210 $amount = $bundle->charge_amount;
211 $amount = apply_filters('latepoint_full_amount_for_bundle', $amount, $bundle);
212 $amount = OsMoneyHelper::pad_to_db_format($amount);
213 return $amount;
214 }
215
216
217 /**
218 * @param OsBundleModel $bundle
219 * @param array $options
220 * @return mixed|void
221 *
222 * Returns deposit amount to charge in database format 1999.0000
223 *
224 */
225 public static function calculate_deposit_amount_for_bundle(OsBundleModel $bundle) {
226 $amount = $bundle->deposit_amount;
227 $amount = apply_filters('latepoint_deposit_amount_for_bundle', $amount, $bundle);
228 $amount = OsMoneyHelper::pad_to_db_format($amount);
229 return $amount;
230 }
231 }