PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.3.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.3.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 1.7.2 All 33 releases
fluent-booking / app / Services / Integrations / FluentCart / CustomerProfileService.php

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

74 lines 2.4 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\App\Services\DateTimeHelper;
6
7 /**
8 * Read a FluentCart customer's profile (lifetime value, orders, status) for the
9 * booking details Customer card. All methods no-op (return null) when FluentCart
10 * is inactive or the booking email has no matching customer.
11 */
12 class CustomerProfileService
13 {
14 public static function isActive()
15 {
16 return defined('FLUENTCART_VERSION');
17 }
18
19 // customers/view is Cart Pro; on free only WP admins pass (FluentCart's own gate).
20 public static function canView()
21 {
22 return self::isActive()
23 && \FluentCart\App\Services\Permission\PermissionManager::userCan('customers/view');
24 }
25
26 public static function getProfileData($email)
27 {
28 if (!self::isActive() || !$email) {
29 return null;
30 }
31
32 $customer = \FluentCart\App\Models\Customer::where('email', $email)->first();
33
34 if (!$customer) {
35 return null;
36 }
37
38 $currency = \FluentCart\Api\CurrencySettings::get('currency');
39
40 return [
41 'full_name' => $customer->full_name,
42 'status' => $customer->status,
43 'profile_url' => self::adminCustomerUrl($customer->id),
44 'stats' => [
45 'ltv' => self::formatMoney($customer->ltv, $currency),
46 'orders' => (int) $customer->purchase_count,
47 'aov' => self::formatMoney($customer->aov, $currency),
48 'last_buy' => $customer->last_purchase_date
49 ? DateTimeHelper::formatToLocale($customer->last_purchase_date, 'date')
50 : '',
51 ],
52 ];
53 }
54
55 /**
56 * Format a cents amount to a currency string. centsToDecimal handles
57 * zero-decimal currencies (JPY, KRW); the sign is an HTML entity rendered
58 * via v-html, so the result is sanitized server-side.
59 */
60 private static function formatMoney($cents, $currency)
61 {
62 $sign = \FluentCart\App\Helpers\CurrenciesHelper::getCurrencySign($currency);
63
64 return wp_kses_post($sign . \FluentCart\App\Helpers\CurrenciesHelper::centsToDecimal($cents, $currency));
65 }
66
67 private static function adminCustomerUrl($id)
68 {
69 $base = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
70
71 return $base . 'customers/' . (int) $id . '/view';
72 }
73 }
74