PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.10.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.10.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
fluent-booking / app / Services / Integrations / FluentCart / CartHelper.php

CartHelper.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.10.0, at app/Services/Integrations/FluentCart/CartHelper.php

146 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services\Integrations\FluentCart;
4
5 use FluentBooking\Framework\Support\Arr;
6 use FluentCart\App\Models\Order as CartOrder;
7 use FluentCart\App\Models\ProductVariation as CartProductVariant;
8
9 class CartHelper
10 {
11 public static function getProduct($productId)
12 {
13 return CartProductVariant::where('id', $productId)
14 ->whereHas('product', function ($query) {
15 $query->where('post_status', 'publish');
16 })
17 ->first();
18 }
19
20 public static function getOrder($orderId)
21 {
22 return CartOrder::find($orderId);
23 }
24
25 public static function getEventProductId($calendarEvent, $duration = null)
26 {
27 $paymentSettings = $calendarEvent->getPaymentSettings();
28
29 if ($calendarEvent->isMultiDurationEnabled() && Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes') {
30 if ($productId = Arr::get($paymentSettings, 'multi_payment_cart_ids.'. $duration)) {
31 return (int) $productId;
32 }
33 return null;
34 }
35
36 $productId = Arr::get($paymentSettings, 'cart_product_id');
37 if ($productId) {
38 return (int) $productId;
39 }
40
41 return null;
42 }
43
44 public static function getProductVariationOptions($product)
45 {
46 $placeholder = self::getPlaceholderImage();
47
48 $isSimple = Arr::get($product->detail, 'variation_type') == 'simple';
49
50 $options = [];
51 foreach ($product->variants as $variant) {
52 $thumbnail = $isSimple ? $product->thumbnail : $variant->thumbnail;
53 $options[] = [
54 'value' => strval($variant->id),
55 'title' => $variant->variation_title,
56 'price' => $variant->formatted_total,
57 'image' => $thumbnail ?? $placeholder
58 ];
59 }
60
61 if (!empty($options)) {
62 return [
63 'id' => $product->ID,
64 'title' => $product->post_title,
65 'options' => $options
66 ];
67 }
68
69 return [];
70 }
71
72 public static function getPlaceholderImage()
73 {
74 return \FluentCart\App\Vite::getAssetUrl('images/placeholder.svg');
75 }
76
77 public static function getCartProductPrice($paymentSettings, $defaultDuration)
78 {
79 $productId = $paymentSettings['cart_product_id'];
80
81 if (Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes') {
82 $productId = Arr::get($paymentSettings, 'multi_payment_cart_ids.' . $defaultDuration);
83 }
84
85 $price = '';
86 $product = self::getProduct($productId);
87 if ($product) {
88 $price = $product->formatted_total;
89 }
90
91 return $price;
92 }
93
94 public static function getCartProductPriceByDuration($productIds = [])
95 {
96 $productPrices = [];
97 if (empty($productIds)) {
98 return $productPrices;
99 }
100
101 $products = CartProductVariant::whereIn('id', array_values($productIds))
102 ->whereHas('product', function ($query) {
103 $query->where('post_status', 'publish');
104 })
105 ->get()
106 ->keyBy('id');
107
108 foreach ($productIds as $duration => $productId) {
109 if (!isset($products[$productId])) {
110 continue;
111 }
112
113 $product = $products[$productId];
114 $productPrices[$duration] = [
115 'value' => $product->formatted_total
116 ];
117 }
118
119 return $productPrices;
120 }
121
122 public static function isEnabled($calendarEvent = null)
123 {
124 if (!$calendarEvent) {
125 return false;
126 }
127
128 return $calendarEvent->isPaidEvent() && $calendarEvent->isCartEnabled();
129 }
130
131 public static function getSuccessLog($bookingId, $order)
132 {
133 return [
134 'booking_id' => $bookingId,
135 'status' => 'closed',
136 'type' => 'success',
137 'title' => __('Cart: Booking status changed to scheduled', 'fluent-booking'),
138 'description' => sprintf(
139 /* translators: Notification message for the change of Woocommerce order status and booking status to scheduled. %1$s is a link to view the order, %2$s is the closing link tag */
140 __('Cart order status changed to paid and booking status changed to scheduled. %1$sView Order%2$s', 'fluent-booking'),
141 '<a target="_blank" href="' . $order->getViewUrl('admin') . '">',
142 '</a>'
143 )
144 ];
145 }
146 }