| @@ -2,20 +2,17 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentBooking\App\Models; |
| 4 | 4 | |
| 5 | 5 | use FluentBooking\App\Models\Model; |
| 6 | +use FluentBooking\Framework\Support\Arr; | |
| 6 | 7 | use FluentBooking\App\Services\SanitizeService; |
| 7 | 8 | use FluentBooking\App\Services\AvailabilityService; |
| 8 | 9 | use FluentBooking\App\Services\BookingFieldService; |
| 9 | 10 | use FluentBooking\App\Services\DateTimeHelper; |
| 10 | 11 | use FluentBooking\App\Services\Helper; |
| 11 | -use FluentBooking\App\Services\BookingService; | |
| 12 | 12 | use FluentBooking\App\Services\CurrenciesHelper; |
| 13 | -use FluentBooking\App\Services\EditorShortCodeParser; | |
| 14 | -use FluentBooking\App\Services\LandingPage\LandingPageHandler; | |
| 15 | -use FluentBooking\App\Services\LandingPage\LandingPageHelper; | |
| 16 | 13 | use FluentBooking\App\Services\LocationService; |
| 17 | -use FluentBooking\Framework\Support\Arr; | |
| 14 | +use FluentBooking\App\Services\Integrations\FluentCart\CartHelper; | |
| 18 | 15 | |
| 19 | 16 | class CalendarSlot extends Model |
| 20 | 17 | { |
| 21 | 18 | protected $table = 'fcal_calendar_events'; |
| @@ -89,8 +86,19 @@ | ||
| 89 | 86 | { |
| 90 | 87 | return \maybe_unserialize($locationSettings); |
| 91 | 88 | } |
| 92 | 89 | |
| 90 | + public function getShortDescriptionAttribute() | |
| 91 | + { | |
| 92 | + $description = preg_replace('/<[^>]*>/', ' ', $this->getDescription()); | |
| 93 | + | |
| 94 | + $maxLength = apply_filters('fluent_booking/event_short_description_length', 160, $this); | |
| 95 | + | |
| 96 | + $description = Helper::excerpt($description, $maxLength); | |
| 97 | + | |
| 98 | + return apply_filters('fluent_booking/event_short_description', $description, $this); | |
| 99 | + } | |
| 100 | + | |
| 93 | 101 | public function calendar() |
| 94 | 102 | { |
| 95 | 103 | return $this->belongsTo(Calendar::class, 'calendar_id'); |
| 96 | 104 | } |
| @@ -110,8 +118,13 @@ | ||
| 110 | 118 | return $this->hasMany(Meta::class, 'object_id', 'id') |
| 111 | 119 | ->whereIn('object_type', ['calendar_event', 'integration']); |
| 112 | 120 | } |
| 113 | 121 | |
| 122 | + public function isOneToOne() | |
| 123 | + { | |
| 124 | + return $this->event_type == 'single'; | |
| 125 | + } | |
| 126 | + | |
| 114 | 127 | public function isGroup() |
| 115 | 128 | { |
| 116 | 129 | return $this->event_type == 'group'; |
| 117 | 130 | } |
| @@ -125,8 +138,18 @@ | ||
| 125 | 138 | { |
| 126 | 139 | return $this->event_type == 'group_event'; |
| 127 | 140 | } |
| 128 | 141 | |
| 142 | + /** | |
| 143 | + * Every value event_type can hold, on both fcal_calendar_slots and fcal_bookings. | |
| 144 | + * | |
| 145 | + * @return array | |
| 146 | + */ | |
| 147 | + public static function getEventTypes() | |
| 148 | + { | |
| 149 | + return ['single', 'group', 'round_robin', 'collective', 'single_event', 'group_event']; | |
| 150 | + } | |
| 151 | + | |
| 129 | 152 | public function isRoundRobin() |
| 130 | 153 | { |
| 131 | 154 | return $this->event_type == 'round_robin'; |
| 132 | 155 | } |
| @@ -160,16 +183,26 @@ | ||
| 160 | 183 | { |
| 161 | 184 | return $this->isGroup() || $this->isGroupEvent(); |
| 162 | 185 | } |
| 163 | 186 | |
| 187 | + public function isRecurringEvent() | |
| 188 | + { | |
| 189 | + return Arr::isTrue($this->getRecurringConfig(), 'enabled'); | |
| 190 | + } | |
| 191 | + | |
| 164 | 192 | public function isProEvent() |
| 165 | 193 | { |
| 166 | - return $this->isGroup() || $this->isTeamEvent() || $this->isOneOffEvent(); | |
| 194 | + return $this->isGroup() || $this->isTeamEvent() || $this->isOneOffEvent() || $this->allowMultiBooking(); | |
| 167 | 195 | } |
| 168 | 196 | |
| 197 | + public function isMultiBooking() | |
| 198 | + { | |
| 199 | + return Arr::isTrue($this->settings, 'multiple_booking.enabled'); | |
| 200 | + } | |
| 201 | + | |
| 169 | 202 | public function allowMultiBooking() |
| 170 | 203 | { |
| 171 | - return Arr::isTrue($this->settings, 'multiple_booking.enabled'); | |
| 204 | + return $this->isMultiBooking() || $this->isRecurringEvent(); | |
| 172 | 205 | } |
| 173 | 206 | |
| 174 | 207 | public function multiBookingLimit() |
| 175 | 208 | { |
| @@ -208,11 +241,19 @@ | ||
| 208 | 241 | { |
| 209 | 242 | $teamMembers = []; |
| 210 | 243 | $teamMemberIds = $this->getHostIds(); |
| 211 | 244 | |
| 245 | + cache_users($teamMemberIds); | |
| 246 | + | |
| 247 | + $calendars = Calendar::whereIn('user_id', $teamMemberIds) | |
| 248 | + ->where('type', 'simple') | |
| 249 | + ->orderBy('id', 'desc') | |
| 250 | + ->with(['metas', 'user', 'user.metas']) | |
| 251 | + ->get() | |
| 252 | + ->keyBy('user_id'); | |
| 253 | + | |
| 212 | 254 | foreach ($teamMemberIds as $teamMemberId) { |
| 213 | - $calendar = Calendar::where('user_id', $teamMemberId)->where('type', 'simple')->first(); | |
| 214 | - if ($calendar) { | |
| 255 | + if ($calendar = $calendars->get($teamMemberId)) { | |
| 215 | 256 | $teamMembers[] = $calendar->getAuthorProfile($public); |
| 216 | 257 | } |
| 217 | 258 | } |
| 218 | 259 | |
| @@ -218,8 +259,13 @@ | ||
| 218 | 259 | |
| 219 | 260 | return $teamMembers; |
| 220 | 261 | } |
| 221 | 262 | |
| 263 | + public function getRecurringConfig() | |
| 264 | + { | |
| 265 | + return Arr::get($this->settings, 'recurring_config', []); | |
| 266 | + } | |
| 267 | + | |
| 222 | 268 | public function isLocationFieldRequired() |
| 223 | 269 | { |
| 224 | 270 | $locationSettings = Arr::get($this, 'location_settings'); |
| 225 | 271 | |
| @@ -259,9 +305,9 @@ | ||
| 259 | 305 | |
| 260 | 306 | $availability = AvailabilityService::maybeCreateAvailability($calendar, $weeklySchedule); |
| 261 | 307 | |
| 262 | 308 | $defaultData = [ |
| 263 | - 'title' => '30 Minute Meeting', | |
| 309 | + 'title' => '', | |
| 264 | 310 | 'calendar_id' => $calendar->id, |
| 265 | 311 | 'user_id' => $calendar->user_id, |
| 266 | 312 | 'status' => 'active', |
| 267 | 313 | 'event_type' => 'single', |
| @@ -273,10 +319,10 @@ | ||
| 273 | 319 | 'max_book_per_slot' => 1, |
| 274 | 320 | 'is_display_spots' => false, |
| 275 | 321 | 'location_settings' => [ |
| 276 | 322 | [ |
| 277 | - 'type' => 'in_person_guest', | |
| 278 | - 'title' => 'In Person (Attendee Address)', | |
| 323 | + 'type' => '', | |
| 324 | + 'title' => '', | |
| 279 | 325 | 'description' => '', |
| 280 | 326 | 'host_phone_number' => '' |
| 281 | 327 | ] |
| 282 | 328 | ], |
| @@ -289,71 +335,9 @@ | ||
| 289 | 335 | 'range_date_between' => ['', ''], |
| 290 | 336 | 'schedule_conditions' => [ |
| 291 | 337 | 'value' => 4, |
| 292 | 338 | 'unit' => 'hours' |
| 293 | - ], | |
| 294 | - 'buffer_time_before' => '0', | |
| 295 | - 'buffer_time_after' => '0', | |
| 296 | - 'slot_interval' => '', | |
| 297 | - 'booking_title' => '', | |
| 298 | - 'submit_button_text' => '', | |
| 299 | - 'multiple_booking' => [ | |
| 300 | - 'enabled' => false, | |
| 301 | - 'limit' => 5 | |
| 302 | - ], | |
| 303 | - 'booking_frequency' => [ | |
| 304 | - 'enabled' => false, | |
| 305 | - 'limits' => [ | |
| 306 | - ['unit' => 'per_day', 'value' => 5] | |
| 307 | - ] | |
| 308 | - ], | |
| 309 | - 'booking_duration' => [ | |
| 310 | - 'enabled' => false, | |
| 311 | - 'limits' => [ | |
| 312 | - ['unit' => 'per_day', 'value' => 120] | |
| 313 | - ] | |
| 314 | - ], | |
| 315 | - 'can_not_cancel' => [ | |
| 316 | - 'enabled' => false, | |
| 317 | - 'message' => 'Sorry! you can not cancel this', | |
| 318 | - 'type' => 'always', | |
| 319 | - 'condition' => [ | |
| 320 | - 'unit' => 'minutes', | |
| 321 | - 'value' => 30 | |
| 322 | - ] | |
| 323 | - ], | |
| 324 | - 'can_not_reschedule' => [ | |
| 325 | - 'enabled' => false, | |
| 326 | - 'message' => 'Sorry! you can not reschedule this', | |
| 327 | - 'type' => 'always', | |
| 328 | - 'condition' => [ | |
| 329 | - 'unit' => 'minutes', | |
| 330 | - 'value' => 30 | |
| 331 | - ] | |
| 332 | - ], | |
| 333 | - 'custom_redirect' => [ | |
| 334 | - 'enabled' => false, | |
| 335 | - 'redirect_url' => '', | |
| 336 | - 'is_query_string' => 'no', | |
| 337 | - 'query_string' => '' | |
| 338 | - ], | |
| 339 | - 'multi_duration' => [ | |
| 340 | - 'enabled' => false, | |
| 341 | - 'default_duration' => '', | |
| 342 | - 'available_durations' => [] | |
| 343 | - ], | |
| 344 | - 'lock_timezone' => [ | |
| 345 | - 'enabled' => false, | |
| 346 | - 'timezone' => '' | |
| 347 | - ], | |
| 348 | - 'requires_confirmation' => [ | |
| 349 | - 'enabled' => false, | |
| 350 | - 'type' => 'always', | |
| 351 | - 'condition' => [ | |
| 352 | - 'unit' => 'minutes', | |
| 353 | - 'value' => 30 | |
| 354 | - ] | |
| 355 | - ], | |
| 339 | + ] | |
| 356 | 340 | ] |
| 357 | 341 | ]; |
| 358 | 342 | |
| 359 | 343 | return $defaultData; |
| @@ -467,15 +451,17 @@ | ||
| 467 | 451 | |
| 468 | 452 | public function getScheduleTimezone($hostId = null) |
| 469 | 453 | { |
| 470 | 454 | if ($hostId && !$this->isTeamCommonSchedule()) { |
| 471 | - $schedule = AvailabilityService::getDefaultSchedule($hostId); | |
| 455 | + $schedule = $this->getHostSchedule($hostId); | |
| 472 | 456 | return Arr::get($schedule, 'value.timezone', 'UTC'); |
| 473 | 457 | } |
| 474 | 458 | |
| 475 | 459 | if ($this->availability_type == 'existing_schedule') { |
| 476 | - $schedule = Availability::findOrFail($this->availability_id); | |
| 477 | - return Arr::get($schedule, 'value.timezone', 'UTC'); | |
| 460 | + $schedule = Availability::find($this->availability_id); | |
| 461 | + if ($schedule) { | |
| 462 | + return Arr::get($schedule, 'value.timezone', 'UTC'); | |
| 463 | + } | |
| 478 | 464 | } |
| 479 | 465 | |
| 480 | 466 | return $this->calendar->author_timezone; |
| 481 | 467 | } |
| @@ -596,8 +582,12 @@ | ||
| 596 | 582 | public function getMinBookableDateTime($startDate = null, $timeZone = null) |
| 597 | 583 | { |
| 598 | 584 | $startDate = $startDate ?: gmdate('Y-m-d H:i:s'); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 599 | 585 | |
| 586 | + if ($timeZone) { | |
| 587 | + $startDate = DateTimeHelper::convertToTimeZone($startDate, $timeZone, 'UTC'); | |
| 588 | + } | |
| 589 | + | |
| 600 | 590 | $rangeType = Arr::get($this->settings, 'range_type', 'range_days'); |
| 601 | 591 | |
| 602 | 592 | if ($rangeType == 'range_date_between') { |
| 603 | 593 | $range = Arr::get($this->settings, 'range_date_between', []); |
| @@ -603,8 +593,9 @@ | ||
| 603 | 593 | $range = Arr::get($this->settings, 'range_date_between', []); |
| 604 | 594 | if (is_array($range) && count(array_filter($range)) == 2) { |
| 605 | 595 | if (strtotime($range[0]) >= strtotime($startDate)) { |
| 606 | 596 | $startDate = gmdate('Y-m-d H:i:s', strtotime($range[0])); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 597 | + $startDate = DateTimeHelper::convertToTimeZone($startDate, $this->calendar->author_timezone, 'UTC'); | |
| 607 | 598 | } |
| 608 | 599 | } |
| 609 | 600 | } |
| 610 | 601 | |
| @@ -664,9 +655,11 @@ | ||
| 664 | 655 | if (!$conditions || empty($conditions['unit'])) { |
| 665 | 656 | return 0; |
| 666 | 657 | } |
| 667 | 658 | |
| 668 | - return strtotime('+' . $conditions['value'] . ' ' . $conditions['unit'], 0) - strtotime('+0 seconds', 0); | |
| 659 | + $value = max(0, (int) Arr::get($conditions, 'value', 0)); | |
| 660 | + | |
| 661 | + return strtotime('+' . $value . ' ' . $conditions['unit'], 0) - strtotime('+0 seconds', 0); | |
| 669 | 662 | } |
| 670 | 663 | |
| 671 | 664 | public function getHostIds($hostId = null) |
| 672 | 665 | { |
| @@ -805,8 +798,20 @@ | ||
| 805 | 798 | ], |
| 806 | 799 | ], $calendarEvent ?: $this); |
| 807 | 800 | } |
| 808 | 801 | |
| 802 | + public function isDisplaySpots() | |
| 803 | + { | |
| 804 | + return $this->is_display_spots == true; | |
| 805 | + } | |
| 806 | + | |
| 807 | + public function isAdditionalGuestEnabled() | |
| 808 | + { | |
| 809 | + $guestField = BookingFieldService::getBookingFieldByName($this, 'guests'); | |
| 810 | + | |
| 811 | + return Arr::isTrue($guestField, 'enabled', false); | |
| 812 | + } | |
| 813 | + | |
| 809 | 814 | public function isConfirmationEnabled() |
| 810 | 815 | { |
| 811 | 816 | return Arr::isTrue($this->settings, 'requires_confirmation.enabled'); |
| 812 | 817 | } |
| @@ -830,8 +835,10 @@ | ||
| 830 | 835 | |
| 831 | 836 | $conditionTime = $conditionValue * 60; |
| 832 | 837 | if ($conditionUnit == 'hours') { |
| 833 | 838 | $conditionTime = $conditionTime * 60; |
| 839 | + } elseif ($conditionUnit == 'days') { | |
| 840 | + $conditionTime = $conditionTime * 60 * 24; | |
| 834 | 841 | } |
| 835 | 842 | |
| 836 | 843 | return $bookingStartTime - $bookingCreatedTime < $conditionTime; |
| 837 | 844 | } |
| @@ -873,12 +880,13 @@ | ||
| 873 | 880 | |
| 874 | 881 | return LocationService::getLocationIconHeadingHtml($default, $this); |
| 875 | 882 | } |
| 876 | 883 | |
| 877 | - public function defaultPaymentIcon($currency, $amount) | |
| 884 | + public function defaultPaymentIcon($amount, $currencySettings = []) | |
| 878 | 885 | { |
| 886 | + $formattedAmount = $currencySettings ? fluentbookingFormattedAmount((float)$amount * 100, $currencySettings) : $amount; | |
| 879 | 887 | $svg = '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" data-v-ea893728=""><path fill="currentColor" d="M256 640v192h640V384H768v-64h150.976c14.272 0 19.456 1.472 24.64 4.288a29.056 29.056 0 0 1 12.16 12.096c2.752 5.184 4.224 10.368 4.224 24.64v493.952c0 14.272-1.472 19.456-4.288 24.64a29.056 29.056 0 0 1-12.096 12.16c-5.184 2.752-10.368 4.224-24.64 4.224H233.024c-14.272 0-19.456-1.472-24.64-4.288a29.056 29.056 0 0 1-12.16-12.096c-2.688-5.184-4.224-10.368-4.224-24.576V640h64z"></path><path fill="currentColor" d="M768 192H128v448h640V192zm64-22.976v493.952c0 14.272-1.472 19.456-4.288 24.64a29.056 29.056 0 0 1-12.096 12.16c-5.184 2.752-10.368 4.224-24.64 4.224H105.024c-14.272 0-19.456-1.472-24.64-4.288a29.056 29.056 0 0 1-12.16-12.096C65.536 682.432 64 677.248 64 663.04V169.024c0-14.272 1.472-19.456 4.288-24.64a29.056 29.056 0 0 1 12.096-12.16C85.568 129.536 90.752 128 104.96 128h685.952c14.272 0 19.456 1.472 24.64 4.288a29.056 29.056 0 0 1 12.16 12.096c2.752 5.184 4.224 10.368 4.224 24.64z"></path><path fill="currentColor" d="M448 576a160 160 0 1 1 0-320 160 160 0 0 1 0 320zm0-64a96 96 0 1 0 0-192 96 96 0 0 0 0 192z"></path></svg>'; |
| 880 | - $html = '<span class="fcal_slot_payment_icon">' . $svg . $currency . $amount . '</span>'; | |
| 888 | + $html = '<span class="fcal_slot_payment_icon">' . $svg . $formattedAmount . '</span>'; | |
| 881 | 889 | return $html; |
| 882 | 890 | } |
| 883 | 891 | |
| 884 | 892 | public function isPaymentEnabled($duration = null) |
| @@ -895,13 +903,25 @@ | ||
| 895 | 903 | |
| 896 | 904 | return $this->type == 'paid' && Helper::isPaymentEnabled(); |
| 897 | 905 | } |
| 898 | 906 | |
| 907 | + public function isPaidEvent() | |
| 908 | + { | |
| 909 | + $paymentSettings = $this->getPaymentSettings(); | |
| 910 | + | |
| 911 | + return $this->type != 'free' && Arr::get($paymentSettings, 'enabled') == 'yes'; | |
| 912 | + } | |
| 913 | + | |
| 899 | 914 | public function isWooEnabled() |
| 900 | 915 | { |
| 901 | 916 | return $this->type == 'woo' && defined('WC_PLUGIN_FILE'); |
| 902 | 917 | } |
| 903 | 918 | |
| 919 | + public function isCartEnabled() | |
| 920 | + { | |
| 921 | + return $this->type == 'cart' && defined('FLUENTCART_VERSION'); | |
| 922 | + } | |
| 923 | + | |
| 904 | 924 | public function getPaymentItems($duration = null) |
| 905 | 925 | { |
| 906 | 926 | $paymentSettings = $this->getPaymentSettings(); |
| 907 | 927 | |
| @@ -907,9 +927,9 @@ | ||
| 907 | 927 | |
| 908 | 928 | $isMultiEnabled = Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes'; |
| 909 | 929 | |
| 910 | 930 | if ($this->isMultiDurationEnabled() && $isMultiEnabled) { |
| 911 | - $duration = $duration ?? $this->getDefaultDuration(); | |
| 931 | + $duration = $duration ?: $this->getDefaultDuration(); | |
| 912 | 932 | return [Arr::get($paymentSettings, 'multi_payment_items.' . $duration)]; |
| 913 | 933 | } |
| 914 | 934 | |
| 915 | 935 | return Arr::get($paymentSettings, 'items', []); |
| @@ -914,24 +934,43 @@ | ||
| 914 | 934 | |
| 915 | 935 | return Arr::get($paymentSettings, 'items', []); |
| 916 | 936 | } |
| 917 | 937 | |
| 918 | - public function getPricingTotal() | |
| 938 | + public function getEventPrice($duration = null) | |
| 919 | 939 | { |
| 940 | + if (!$this->isPaidEvent()) { | |
| 941 | + return 0; | |
| 942 | + } | |
| 943 | + | |
| 944 | + $paymentSettings = $this->getPaymentSettings(); | |
| 945 | + | |
| 946 | + if ($this->isCartEnabled()) { | |
| 947 | + return CartHelper::getCartProductPrice($paymentSettings, $duration, false); | |
| 948 | + } | |
| 949 | + | |
| 950 | + if ($this->isWooEnabled()) { | |
| 951 | + return $this->getWooProductPrice($duration); | |
| 952 | + } | |
| 953 | + | |
| 954 | + return $this->getPricingTotal($duration); | |
| 955 | + } | |
| 956 | + | |
| 957 | + public function getPricingTotal($duration = null) | |
| 958 | + { | |
| 920 | 959 | if (!$this->isPaymentEnabled()) { |
| 921 | 960 | return 0; |
| 922 | 961 | } |
| 923 | 962 | |
| 924 | 963 | $total = 0; |
| 925 | - $items = $this->getPaymentItems(); | |
| 964 | + $items = $this->getPaymentItems($duration); | |
| 926 | 965 | foreach ($items as $item) { |
| 927 | - $total += (int)$item['value']; | |
| 966 | + $total += $item['value']; | |
| 928 | 967 | } |
| 929 | 968 | |
| 930 | 969 | return $total; |
| 931 | 970 | } |
| 932 | 971 | |
| 933 | - public function getWooProductPrice() | |
| 972 | + public function getWooProductPrice($duration = null) | |
| 934 | 973 | { |
| 935 | 974 | $paymentSettings = $this->getPaymentSettings(); |
| 936 | 975 | |
| 937 | 976 | $productId = $paymentSettings['woo_product_id']; |
| @@ -936,9 +975,9 @@ | ||
| 936 | 975 | |
| 937 | 976 | $productId = $paymentSettings['woo_product_id']; |
| 938 | 977 | |
| 939 | 978 | if (Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes') { |
| 940 | - $duration = $this->getDefaultDuration(); | |
| 979 | + $duration = $duration ?? $this->getDefaultDuration(); | |
| 941 | 980 | $productId = Arr::get($paymentSettings, 'multi_payment_woo_ids.' . $duration); |
| 942 | 981 | } |
| 943 | 982 | |
| 944 | 983 | $price = 0; |
| @@ -957,9 +996,9 @@ | ||
| 957 | 996 | foreach ($productIds as $duration => $productId) { |
| 958 | 997 | $product = wc_get_product($productId); |
| 959 | 998 | if ($product) { |
| 960 | 999 | $productPrices[$duration] = [ |
| 961 | - 'value' => $product->get_price() | |
| 1000 | + 'value' => wc_price($product->get_price()) | |
| 962 | 1001 | ]; |
| 963 | 1002 | } |
| 964 | 1003 | } |
| 965 | 1004 | |
| @@ -972,17 +1011,16 @@ | ||
| 972 | 1011 | |
| 973 | 1012 | $driver = Arr::get($this->getPaymentSettings(), 'driver'); |
| 974 | 1013 | |
| 975 | 1014 | if ($driver == 'native' && $this->isPaymentEnabled()) { |
| 976 | - $currency = CurrenciesHelper::getGlobalCurrencySign(); | |
| 1015 | + $currencySettings = CurrenciesHelper::getGlobalCurrencySettings(); | |
| 977 | 1016 | $totalPayment = $this->getPricingTotal(); |
| 978 | - $paymentHtml = $this->defaultPaymentIcon($currency, $totalPayment); | |
| 1017 | + $paymentHtml = $this->defaultPaymentIcon($totalPayment, $currencySettings); | |
| 979 | 1018 | } |
| 980 | 1019 | |
| 981 | 1020 | if ($driver == 'woo' && $this->isWooEnabled()) { |
| 982 | - $currency = get_woocommerce_currency_symbol(); | |
| 983 | - $totalPayment = $this->getWooProductPrice(); | |
| 984 | - $paymentHtml = $this->defaultPaymentIcon($currency, $totalPayment); | |
| 1021 | + $totalPayment = wc_price($this->getWooProductPrice()); | |
| 1022 | + $paymentHtml = $this->defaultPaymentIcon($totalPayment); | |
| 985 | 1023 | } |
| 986 | 1024 | |
| 987 | 1025 | return $paymentHtml; |
| 988 | 1026 | } |
| @@ -1016,8 +1054,13 @@ | ||
| 1016 | 1054 | { |
| 1017 | 1055 | return $this->isRoundRobin() && $this->isTeamCommonSchedule(); |
| 1018 | 1056 | } |
| 1019 | 1057 | |
| 1058 | + public function isCollectiveDefaultSchedule() | |
| 1059 | + { | |
| 1060 | + return $this->isCollective() && $this->isTeamDefaultSchedule(); | |
| 1061 | + } | |
| 1062 | + | |
| 1020 | 1063 | private function getProcessedWeeklySlots($schedule) |
| 1021 | 1064 | { |
| 1022 | 1065 | $scheduleData = Arr::get($schedule, 'value.weekly_schedules', []); |
| 1023 | 1066 | $scheduleTimezone = Arr::get($schedule, 'value.timezone', 'UTC'); |
| @@ -1037,15 +1080,17 @@ | ||
| 1037 | 1080 | |
| 1038 | 1081 | public function getWeeklySlots($hostId = null) |
| 1039 | 1082 | { |
| 1040 | 1083 | if ($hostId && !$this->isTeamCommonSchedule()) { |
| 1041 | - $schedule = AvailabilityService::getDefaultSchedule($hostId); | |
| 1084 | + $schedule = $this->getHostSchedule($hostId); | |
| 1042 | 1085 | return $this->getProcessedWeeklySlots($schedule); |
| 1043 | 1086 | } |
| 1044 | 1087 | |
| 1045 | 1088 | if ($this->availability_type === 'existing_schedule') { |
| 1046 | - $schedule = Availability::findOrFail($this->availability_id); | |
| 1047 | - return $this->getProcessedWeeklySlots($schedule); | |
| 1089 | + $schedule = Availability::find($this->availability_id); | |
| 1090 | + if ($schedule) { | |
| 1091 | + return $this->getProcessedWeeklySlots($schedule); | |
| 1092 | + } | |
| 1048 | 1093 | } |
| 1049 | 1094 | |
| 1050 | 1095 | $scheduleData = Arr::get($this->settings, 'weekly_schedules', []); |
| 1051 | 1096 | $schedule = SanitizeService::weeklySchedules($scheduleData, 'UTC', $this->calendar->author_timezone); |
| @@ -1054,15 +1099,17 @@ | ||
| 1054 | 1099 | |
| 1055 | 1100 | public function getDateOverrides($hostId = null) |
| 1056 | 1101 | { |
| 1057 | 1102 | if ($hostId && !$this->isTeamCommonSchedule()) { |
| 1058 | - $schedule = AvailabilityService::getDefaultSchedule($hostId); | |
| 1103 | + $schedule = $this->getHostSchedule($hostId); | |
| 1059 | 1104 | return $this->getProcessedDateOverrides($schedule); |
| 1060 | 1105 | } |
| 1061 | 1106 | |
| 1062 | 1107 | if ($this->availability_type === 'existing_schedule') { |
| 1063 | - $schedule = Availability::findOrFail($this->availability_id); | |
| 1064 | - return $this->getProcessedDateOverrides($schedule); | |
| 1108 | + $schedule = Availability::find($this->availability_id); | |
| 1109 | + if ($schedule) { | |
| 1110 | + return $this->getProcessedDateOverrides($schedule); | |
| 1111 | + } | |
| 1065 | 1112 | } |
| 1066 | 1113 | |
| 1067 | 1114 | $scheduleData = Arr::get($this->settings, 'date_overrides', []); |
| 1068 | 1115 | $schedule = SanitizeService::slotDateOverrides($scheduleData, 'UTC', $this->calendar->author_timezone); |
| @@ -1102,8 +1149,9 @@ | ||
| 1102 | 1149 | 'enabled' => 'no', |
| 1103 | 1150 | 'multi_payment_enabled' => 'no', |
| 1104 | 1151 | 'stripe_enabled' => 'no', |
| 1105 | 1152 | 'paypal_enabled' => 'no', |
| 1153 | + 'offline_enabled' => 'no', | |
| 1106 | 1154 | 'driver' => 'native', |
| 1107 | 1155 | 'items' => [ |
| 1108 | 1156 | [ |
| 1109 | 1157 | 'title' => __('Booking Fee', 'fluent-booking'), |
| @@ -1110,8 +1158,9 @@ | ||
| 1110 | 1158 | 'value' => 100 |
| 1111 | 1159 | ] |
| 1112 | 1160 | ], |
| 1113 | 1161 | 'woo_product_id' => '', |
| 1162 | + 'cart_product_id' => '', | |
| 1114 | 1163 | 'multi_payment_items' => [ |
| 1115 | 1164 | $duration => [ |
| 1116 | 1165 | 'title' => __('Booking Fee', 'fluent-booking'), |
| 1117 | 1166 | 'value' => 0 |
| @@ -1118,16 +1167,41 @@ | ||
| 1118 | 1167 | ] |
| 1119 | 1168 | ], |
| 1120 | 1169 | 'multi_payment_woo_ids' => [ |
| 1121 | 1170 | $duration => '' |
| 1171 | + ], | |
| 1172 | + 'multi_payment_cart_ids' => [ | |
| 1173 | + $duration => '' | |
| 1122 | 1174 | ] |
| 1123 | 1175 | ]; |
| 1124 | 1176 | |
| 1177 | + $defaults = apply_filters('fluent_booking/event_payment_settings_defaults', $defaults, $this); | |
| 1178 | + | |
| 1125 | 1179 | if (!$settings) { |
| 1126 | 1180 | $settings = $defaults; |
| 1127 | 1181 | } |
| 1128 | 1182 | |
| 1129 | - return wp_parse_args($settings, $defaults); | |
| 1183 | + $settings = wp_parse_args($settings, $defaults); | |
| 1184 | + | |
| 1185 | + return apply_filters('fluent_booking/get_event_payment_settings', $settings, $this); | |
| 1186 | + } | |
| 1187 | + | |
| 1188 | + public function getHostSchedule($hostId) | |
| 1189 | + { | |
| 1190 | + $hostSchedules = Arr::get($this->settings, 'hosts_schedules', []); | |
| 1191 | + if (isset($hostSchedules[$hostId])) { | |
| 1192 | + return Availability::find($hostSchedules[$hostId]); | |
| 1193 | + } | |
| 1194 | + return AvailabilityService::getDefaultSchedule($hostId); | |
| 1195 | + } | |
| 1196 | + | |
| 1197 | + public function getHostsSchedules() { | |
| 1198 | + $hostIds = $this->getHostIds(); | |
| 1199 | + $hostSchedules = Arr::get($this->settings, 'hosts_schedules', []); | |
| 1200 | + foreach ($hostIds as $hostId) { | |
| 1201 | + $hostSchedules[$hostId] = $hostSchedules[$hostId] ?? AvailabilityService::getDefaultSchedule($hostId)['id']; | |
| 1202 | + } | |
| 1203 | + return $hostSchedules; | |
| 1130 | 1204 | } |
| 1131 | 1205 | |
| 1132 | 1206 | public function getCalendarEventsMeta() |
| 1133 | 1207 | { |