PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.0
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Hooks / Handlers / MenuHandler.php

MenuHandler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.0, at app/Hooks/Handlers/MenuHandler.php

666 lines 27.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers;
4
5 use FluentCart\Api\ModuleSettings;
6 use FluentCart\App\App;
7 use FluentCart\App\Services\Renderer\CheckoutFieldsSchema;
8 use FluentCart\App\Vite;
9 use FluentCart\App\Services\URL;
10 use FluentCart\Api\StoreSettings;
11 use FluentCart\Api\PaymentMethods;
12 use FluentCart\App\Helpers\Helper;
13 use FluentCart\App\Helpers\Status;
14 use FluentCart\App\Models\Product;
15 use FluentCart\App\Models\Customer;
16 use FluentCart\Framework\Support\Arr;
17 use FluentCart\App\CPT\FluentProducts;
18 use FluentCart\App\Helpers\AdminHelper;
19 use FluentCart\App\Models\AttributeTerm;
20 use FluentCart\App\Models\AttributeGroup;
21 use FluentCart\App\Models\ShippingMethod;
22 use FluentCart\App\Modules\Tax\TaxModule;
23 use FluentCart\App\Helpers\CurrenciesHelper;
24 use FluentCart\App\Services\Filter\TaxFilter;
25 use FluentCart\App\Services\Filter\OrderFilter;
26 use FluentCart\App\Services\Filter\LicenseFilter;
27 use FluentCart\App\Services\Filter\LicenseSiteFilter;
28 use FluentCart\App\Services\Filter\ProductFilter;
29 use FluentCart\App\Services\Filter\CustomerFilter;
30 use FluentCart\App\Modules\Integrations\AddOnModule;
31 use FluentCart\App\Services\Translations\TransStrings;
32 use FluentCart\App\Services\Permission\PermissionManager;
33 use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager;
34
35 class MenuHandler
36 {
37 public function register()
38 {
39 add_action('init', [$this, 'init']);
40
41 add_action('admin_init', function () {
42 $page = $_GET['page'] ?? '';
43
44 if ($page == 'fluent-cart') {
45
46 \FluentCart\App\Events\FirstTimePluginActivation::handle();
47 add_action('admin_enqueue_scripts', function () {
48 Vite::enqueueStyle('fluent_cart_admin_app_css',
49 'styles/tailwind/style.css',
50 );
51 Vite::enqueueScript('fluent_cart_admin_global_js',
52 'admin/global.js',
53 );
54 });
55
56 }
57 });
58
59 // Inline dark mode init script for all FluentCart admin pages (prevents flicker)
60 add_action('admin_head', [$this, 'outputFluentCartDarkModeScript']);
61
62 // Enqueue dark mode toggle JS for taxonomy pages
63 add_action('admin_head', [$this, 'enqueueDarkModeToggleForTaxonomy']);
64
65 // Add a post display state for special WC pages.
66 add_filter('display_post_states', array($this, 'addDisplayPostStates'), 10, 2);
67
68 }
69
70
71 public function addDisplayPostStates($states, $post)
72 {
73 if (!$post || $post->post_type != 'page') {
74 return $states;
75 }
76
77
78 $targetKeys = [
79 'checkout_page_id' => __('Checkout Page', 'fluent-cart'),
80 'cart_page_id' => __('Cart Page', 'fluent-cart'),
81 'receipt_page_id' => __('Receipt Page', 'fluent-cart'),
82 'shop_page_id' => __('Shop Page', 'fluent-cart'),
83 'customer_profile_page_id' => __('Customer Profile Page', 'fluent-cart'),
84 ];
85
86 $pagesConfig = (new StoreSettings())->getPagesSettings();
87 $pagesConfig = Arr::only($pagesConfig, array_keys($targetKeys));
88
89 if (!is_array($pagesConfig)) {
90 return $states;
91 }
92 $pagesConfig = array_filter($pagesConfig);
93
94 if (empty($pagesConfig)) {
95 return $states;
96 }
97
98
99 $pagesConfig = array_flip($pagesConfig);
100 $targetKey = Arr::get($pagesConfig, $post->ID);
101
102 if ($targetKey && isset($targetKeys[$targetKey])) {
103
104 $logo = '<svg style="vertical-align: middle; height: 18px; width: 18px;" width="18" height="18" viewBox="0 0 300 300" fill="none" xmlns="http://www.w3.org/2000/svg">
105 <rect width="300" height="300" rx="30" fill="white"/>
106 <path d="M136.561 205.944H47.1367L61.1704 173.491C65.2906 163.963 74.6784 157.795 85.0589 157.795H191.584L184.338 174.551C176.098 193.607 157.322 205.944 136.561 205.944Z" fill="#00009F"/>
107 <path d="M210.643 142.439H84.8574L92.1035 125.683C100.344 106.627 119.12 94.2905 139.881 94.2905H248.565L234.531 126.743C230.411 136.271 221.023 142.439 210.643 142.439Z" fill="#00009F"/>
108 </svg>';
109
110 $states['fluent_cart'] = '<span>' . $logo . '<span>' . $targetKeys[$targetKey] . '</span></span>';
111 }
112
113 return $states;
114
115 }
116
117 public function outputFluentCartDarkModeScript()
118 {
119 global $pagenow;
120 $page = $_GET['page'] ?? '';
121 $postType = $_GET['post_type'] ?? '';
122
123 // post.php?post=ID&action=edit omits post_type; resolve it from the post ID.
124 if ($pagenow === 'post.php' && empty($postType)) {
125 $postId = (int) App::request()->get('post', 0);
126 $postType = $postId ? (string) get_post_type($postId) : '';
127 }
128
129 $isFluentCartPage = $page === 'fluent-cart';
130 $isTaxonomyList = $pagenow === 'edit-tags.php' && $postType === FluentProducts::CPT_NAME;
131 $isTermEditPage = $pagenow === 'term.php' && $postType === FluentProducts::CPT_NAME;
132 $isProductEditPage = ($pagenow === 'post.php' || $pagenow === 'edit.php') && $postType === FluentProducts::CPT_NAME;
133
134 if (!$isFluentCartPage && !$isTaxonomyList && !$isTermEditPage && !$isProductEditPage) {
135 return;
136 }
137
138 // Runs synchronously in <head> before any paint — applies the dark class and
139 // data-fct-theme attribute to <html> so logos and the theme icon render correctly
140 // from the very first frame, with no light-to-dark flash.
141 echo '<script>' . $this->getDarkModeInitScript() . '</script>';
142 }
143
144 public function enqueueDarkModeToggleForTaxonomy()
145 {
146 global $pagenow;
147 $postType = $_GET['post_type'] ?? '';
148
149 $isTaxonomyList = $pagenow === 'edit-tags.php' && $postType === FluentProducts::CPT_NAME;
150 $isTermEditPage = $pagenow === 'term.php' && $postType === FluentProducts::CPT_NAME;
151
152 if ($isTaxonomyList || $isTermEditPage) {
153 Vite::enqueueScript(
154 'fluent_cart_dark_mode_toggle',
155 'admin/dark-mode-toggle.js',
156 [],
157 FLUENTCART_VERSION,
158 true
159 );
160 }
161 }
162
163 private function getDarkModeInitScript(): string
164 {
165 return "(function(){" .
166 "var k='fluent_theme_mode',c='fluent_theme_dark'," .
167 "s=localStorage.getItem(k)||localStorage.getItem('fcart_admin_theme')," .
168 "t=s==='dark'?'dark':s==='light'?'light':'system'," .
169 "d=s==='dark'||s==='system:dark'||((!s||s==='system')&&window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches);" .
170 "document.documentElement.setAttribute('data-fct-theme',t);" .
171 "if(d)document.documentElement.classList.add(c);" .
172 "})();";
173 }
174
175 public function init()
176 {
177
178 add_action('admin_menu', array($this, 'addAdminMenu'));
179
180 /*
181 * Disable Gutenberg for Products
182 */
183 add_filter('parent_file', function ($parent_file) {
184 global $submenu_file, $current_screen, $pagenow;
185
186 $postType = $_GET['post_type'] ?? '';
187 if ($postType == FluentProducts::CPT_NAME && $current_screen->post_type == FluentProducts::CPT_NAME) {
188 if ($pagenow == 'post.php') {
189 $submenu_file = 'edit.php?post_type=' . $current_screen->post_type;
190 }
191
192 if ($pagenow == 'edit-tags.php') {
193 $taxonomy = $_GET['taxonomy'] ?? '';
194 $submenu_file = 'edit-tags.php?taxonomy=' . esc_attr($taxonomy) . '&post_type=' . $current_screen->post_type;
195 }
196
197 $parent_file = 'fluent-cart';
198 }
199
200 return $parent_file;
201 });
202
203 add_action('fluent_cart/admin_menu', array($this, 'renderAdminMenu'));
204 // add_action('in_admin_header', array($this, 'maybeRenderAdminMenu'));
205
206 add_action('edit_form_top', array($this, 'pushProductNav'));
207
208 add_action('admin_bar_menu', [$this, 'globalEnqueueAssets'], 10, 1);
209 }
210
211 public function addAdminMenu()
212 {
213 $capability = 'manage_options';
214
215 if (!current_user_can('manage_options') && App::isProActive()) {
216 $capability = PermissionManager::ADMIN_CAP;
217 }
218
219 if (!current_user_can($capability)) {
220 return;
221 }
222
223 global $submenu;
224
225 $adminMenuTitle = apply_filters('fluent_cart/admin_menu_title', 'FluentCart', []);
226
227 add_menu_page(
228 $adminMenuTitle,
229 $adminMenuTitle,
230 $capability,
231 'fluent-cart',
232 [$this, 'renderAdmin'],
233 $this->getMenuIcon(),
234 apply_filters('fluent_cart/admin_menu_position', 3)
235 );
236
237 $submenu['fluent-cart']['dashboard'] = array(
238 __('Dashboard', 'fluent-cart'),
239 $capability,
240 'admin.php?page=fluent-cart#/',
241 '',
242 'fluent_cart_dashboard'
243 );
244
245 if (PermissionManager::hasPermission(['orders/view'])) {
246 $submenu['fluent-cart']['orders'] = array(
247 __('Orders', 'fluent-cart'),
248 $capability,
249 'admin.php?page=fluent-cart#/orders',
250 '',
251 'fluent_cart_orders'
252 );
253 }
254
255 if (PermissionManager::hasPermission(['customers/view', 'customers/manage'])) {
256 $submenu['fluent-cart']['customers'] = array(
257 __('Customers', 'fluent-cart'),
258 $capability,
259 'admin.php?page=fluent-cart#/customers',
260 '',
261 'fluent_cart_customers'
262 );
263 }
264
265 if (PermissionManager::hasPermission(['products/view'])) {
266 $submenu['fluent-cart']['products'] = array(
267 __('Products', 'fluent-cart'),
268 $capability,
269 'admin.php?page=fluent-cart#/products',
270 '',
271 'fluent_cart_products'
272 );
273 }
274
275 if (PermissionManager::hasPermission(['subscriptions/view'])) {
276 $submenu['fluent-cart']['subscriptions'] = array(
277 __('Subscriptions', 'fluent-cart'),
278 $capability,
279 'admin.php?page=fluent-cart#/subscriptions',
280 '',
281 'fluent_cart_subscriptions'
282 );
283 }
284
285 if (PermissionManager::hasPermission(['reports/view'])) {
286 $submenu['fluent-cart']['reports'] = array(
287 __('Reports', 'fluent-cart'),
288 $capability,
289 'admin.php?page=fluent-cart#/reports/overview',
290 '',
291 'fluent_cart_reports'
292 );
293 }
294
295 if (PermissionManager::userCan('is_super_admin')) {
296 $submenu['fluent-cart']['integrations'] = array(
297 __('Integrations', 'fluent-cart'),
298 $capability,
299 'admin.php?page=fluent-cart#/integrations',
300 '',
301 'fluent_cart_integrations'
302 );
303 }
304
305
306 $hasSensitiveAccess = PermissionManager::hasPermission(['store/settings', 'store/sensitive']);
307
308 if ($hasSensitiveAccess) {
309 $submenu['fluent-cart']['settings'] = array(
310 __('Settings', 'fluent-cart'),
311 $capability,
312 'admin.php?page=fluent-cart#/settings/store-settings/',
313 '',
314 'fluent_cart_settings'
315 );
316 }
317
318 if (PermissionManager::hasPermission(['coupons/manage', 'coupons/view'])) {
319 $submenu['fluent-cart']['coupons'] = array(
320 __('Coupons', 'fluent-cart'),
321 $capability,
322 'admin.php?page=fluent-cart#/coupons',
323 '',
324 'fluent_cart_coupons'
325 );
326 }
327
328 if ($hasSensitiveAccess && TaxModule::isTaxEnabled()) {
329 $submenu['fluent-cart']['taxes'] = array(
330 __('Taxes', 'fluent-cart'),
331 $capability,
332 'admin.php?page=fluent-cart#/taxes',
333 '',
334 'fluent_cart_taxes'
335 );
336 }
337
338
339 if (PermissionManager::hasPermission(['products/create', 'products/edit'])) {
340 $taxonomies = get_taxonomies([
341 'object_type' => [FluentProducts::CPT_NAME],
342 'public' => true,
343 ], 'object');
344
345 foreach ($taxonomies as $key => $taxonomy) {
346 $menuUrl = 'edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=' . FluentProducts::CPT_NAME;
347 $submenu['fluent-cart'][$key] = [
348 $taxonomy->label,
349 $capability,
350 $menuUrl,
351 '',
352 $taxonomy->name
353 ];
354 }
355 }
356
357 if (PermissionManager::userCan('is_super_admin')) {
358 $submenu['fluent-cart']['logs'] = array(
359 __('Logs', 'fluent-cart'),
360 $capability,
361 'admin.php?page=fluent-cart#/logs',
362 '',
363 'fluent_cart_logs'
364 );
365 }
366
367 do_action('fluent_cart/admin_submenu_added', $submenu);
368 }
369
370 public function renderAdmin()
371 {
372 $isCustomDashboardSlugChanged = (new StoreSettings())->getCustomerDashboardPageSlug() != (new StoreSettings())->get('customer_profile_page_slug');
373
374 if ($isCustomDashboardSlugChanged) {
375 $allSettings = (new StoreSettings())->get();
376 (new StoreSettings())->save($allSettings); // we are just resaving to flash the settings cache
377 }
378
379 if (function_exists('wp_enqueue_editor')) {
380 wp_enqueue_editor();
381 wp_tinymce_inline_scripts();
382 wp_enqueue_media();
383 }
384
385 $this->enqueueAssets();
386
387 $config = App::getInstance('config');
388
389 $name = $config->get('app.name');
390
391 $slug = $config->get('app.slug');
392
393 $baseUrl = apply_filters('fluent_connector_base_url', admin_url('admin.php?page=newproject#/'));
394
395 $app = App::getInstance();
396 $assets = $app['url.assets'];
397
398 App::make('view')->render('admin.admin_app', [
399 'name' => $name,
400 'slug' => $slug,
401 'baseUrl' => $baseUrl,
402 'logo' => $assets . 'images/logo.svg',
403 ]);
404 }
405
406 public function maybeRenderAdminMenu()
407 {
408 $postType = $_GET['post_type'] ?? '';
409 if ($postType == FluentProducts::CPT_NAME && is_admin()) {
410 AdminHelper::getAdminMenu(true);
411 AdminHelper::pushGlobalAdminAssets();
412 }
413 }
414
415 public function renderAdminMenu()
416 {
417 if (!apply_filters('fluent_cart/show_admin_top_bar', true)) {
418 return;
419 }
420 AdminHelper::getAdminMenu(true);
421 }
422
423 public function pushProductNav($post)
424 {
425 if (!$post || $post->post_type != FluentProducts::CPT_NAME) {
426 return;
427 }
428
429 AdminHelper::getProductMenu($post->ID, true, 'product_edit');
430 AdminHelper::pushGlobalAdminAssets();
431 }
432
433 public function enqueueAssets()
434 {
435 $app = App::getInstance();
436
437 $slug = $app->config->get('app.slug');
438
439 do_action('fluent_cart/loading_app', $app);
440
441 //This should be done before enqueueing the global script.
442 Vite::enqueueScript($slug . '_admin_app_start', 'admin/bootstrap/app.js', [$slug . '_global_admin_hooks']);
443
444 //Don't register this script using vite.
445 if (!wp_script_is('wp-hooks', 'registered')) {
446 $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
447 wp_register_script('wp-hooks', includes_url('js/dist/hooks' . $suffix . '.js'), ['wp-polyfill'], FLUENTCART_VERSION, true);
448 }
449 if (!wp_script_is('wp-hooks', 'enqueued')) {
450 wp_enqueue_script('wp-hooks');
451 }
452
453 wp_enqueue_script($slug . '_global_admin_hooks', Vite::getEnqueuePath('admin/admin_hooks.js'), ['wp-hooks'], FLUENTCART_VERSION, true);
454
455 $manager = GatewayManager::getInstance();
456 $payment_routes = $manager->getRoutes();
457 // $payment_routes = apply_filters('fluent_cart/payments/payment_method_settings_routes', []);
458
459 $storage_driver_routes = apply_filters('fluent_cart/storage/storage_driver_settings_routes', [], []);
460
461 $settings = new StoreSettings();
462 $checkoutUrl = add_query_arg(Helper::INSTANT_CHECKOUT_URL_PARAM, '=', $settings->getCheckoutPage());
463 $restVars = Helper::getRestInfo();
464
465 $filterOptions = [
466 'order_filter_options' => OrderFilter::getTableFilterOptions(),
467 'customer_filter_options' => CustomerFilter::getTableFilterOptions(),
468 'product_filter_options' => ProductFilter::getTableFilterOptions(),
469 'license_filter_options' => LicenseFilter::getTableFilterOptions(),
470 'license_site_filter_options' => LicenseSiteFilter::getTableFilterOptions(),
471 'tax_filter_options' => TaxFilter::getTableFilterOptions(),
472 ];
473 $filterOptions = apply_filters('fluent_cart/admin_filter_options', $filterOptions, []);
474
475 // Structured table config keyed by table name (used by Table.js base class)
476 $tableConfig = [
477 'order_table' => ['filters' => Arr::get($filterOptions, 'order_filter_options', [])],
478 'customers' => ['filters' => Arr::get($filterOptions, 'customer_filter_options', [])],
479 'product_table' => ['filters' => Arr::get($filterOptions, 'product_filter_options', [])],
480 'licenses' => ['filters' => Arr::get($filterOptions, 'license_filter_options', [])],
481 'license_sites' => ['filters' => Arr::get($filterOptions, 'license_site_filter_options', [])],
482 'taxes_table' => ['filters' => Arr::get($filterOptions, 'tax_filter_options', [])],
483 'subscriptions' => ['filters' => Arr::get($filterOptions, 'subscription_filter_options', [])],
484 'shipping_zone_table' => ['filters' => Arr::get($filterOptions, 'shipping_zone_filter_options', [])],
485 ];
486
487 $tableConfig = apply_filters('fluent_cart/admin_table_saved_views', $tableConfig, [
488 'filterOptions' => $filterOptions
489 ]);
490
491 $currentUser = get_user_by('ID', get_current_user_id());
492
493 // Get app config and merge additional properties into it
494 $appConfig = $app->config->get('app');
495 $appConfig['version'] = FLUENTCART_VERSION;
496 $appConfig['permissions'] = PermissionManager::getUserPermissions();
497 $appConfig['isProActive'] = App::isProActive();
498 $appConfig['proVersion'] = defined('FLUENTCART_PRO_PLUGIN_VERSION') ? FLUENTCART_PRO_PLUGIN_VERSION : null;
499
500 $appConfig['logos'] = [
501 'dark' => Vite::getAssetUrl('images/logo/logo-full-dark.svg'),
502 'light' => Vite::getAssetUrl('images/logo/logo-full.svg'),
503 ];
504 $appConfig['isModuleTabEnabled'] = $settings->isModuleTabEnabled();
505 $appConfig['upgrade_url'] = 'https://fluentcart.com/pricing/';
506
507 $max_upload_size = wp_max_upload_size(); // Returns size in bytes
508 $adminLocalizeData = apply_filters('fluent_cart/admin_app_data', [
509 'app_config' => $appConfig,
510 'slug' => $app->config->get('app.slug'),
511 'admin_url' => admin_url('admin.php?page=fluent-cart#/'),
512 'frontend_url' => URL::getFrontEndUrl(''),
513 'nonce' => wp_create_nonce($slug),
514 'rest' => $restVars,
515 'brand_logo' => $this->getMenuIcon(),
516 'asset_url' => Vite::getAssetUrl(),
517 'me' => [
518 'id' => $currentUser->ID,
519 'full_name' => trim($currentUser->display_name),
520 'email' => $currentUser->user_email,
521 'avatar' => get_avatar_url($currentUser->ID)
522 ],
523 'shop' => Helper::shopConfig(),
524 'product_statuses' => Status::getProductStatuses(),
525 'total_products_count' => Product::query()->count(),
526 'payment_statuses' => Status::getEditableTransactionStatuses(true),
527 'payment_routes' => $payment_routes,
528 'storage_driver_routes' => $storage_driver_routes,
529 'editable_payment_statuses' => Status::getEditableTransactionStatuses(true),
530 'order_statuses' => Status::getOrderStatuses(),
531 'editable_order_statuses' => Status::getEditableOrderStatuses(),
532 'editable_customer_statuses' => Status::getEditableCustomerStatuses(),
533 // Backward compat: keep the old typo'd keys for existing frontend code
534 'order_statues' => Status::getOrderStatuses(),
535 'editable_order_statues' => Status::getEditableOrderStatuses(),
536 'editable_customer_statues' => Status::getEditableCustomerStatuses(),
537 'shipping_statuses' => Status::getShippingStatuses(),
538 'allow_bulk_payment_status_change' => true,
539 // Attribute library powering the Advanced Variation feature.
540 'variation_attributes' => AttributeGroup::with(['terms'])->get(),
541 'variation_terms' => AttributeTerm::query()->get()->keyBy('id'),
542 'product_image_base_uri' => Helper::getProductImageBaseUri(),
543 'add_on_modules' => AddOnModule::showAddOns(),
544 'stock_statuses' => Status::getStockStatuses(),
545 'fulfillment_types' => Helper::getFulfilmentTypes(),
546 'variation_types' => Helper::getVariationTypes(),
547 'trans' => TransStrings::getStrings(),
548 'dashboard_url' => admin_url('admin.php?page=fluent-cart#'),
549 'checkout_url' => $checkoutUrl,
550 'dummy_product_info' => apply_filters('fluent_cart/dummy_product_info', []) ?: [],
551 'currency_signs' => CurrenciesHelper::getCurrencySigns(),
552 'filter_options' => $filterOptions,
553 'table_config' => $tableConfig,
554 'receipt_page_url' => $settings->getReceiptPage(),
555 'payment_logos' => PaymentMethods::getIcons(),
556 'is_admin_bar_showing' => is_admin_bar_showing(),
557 'max_upload_size' => size_format($max_upload_size),
558 'available_shipping_method_count' => ShippingMethod::query()->where('is_enabled', '1')->count(),
559 'is_tax_enabled' => TaxModule::isTaxEnabled(),
560 'eu_vat_county_options' => TaxModule::euVatCountyOptions(),
561 'country_tax_titles' => TaxModule::taxTitleLists(),
562 'site_url' => site_url(),
563 'modules_settings' => ModuleSettings::getAllSettings(),
564 'purchase_fluent_cart_link' => 'https://fluentcart.com/',
565 'admin_notices' => apply_filters('fluent_cart/admin_notices', []),
566 'subscription_intervals' => Helper::getAvailableSubscriptionIntervalOptions(),
567
568 'datei18' => TransStrings::dateTimeStrings(),
569 'el_strings' => TransStrings::elStrings(),
570 'wp_locale' => get_locale(),
571 'is_full_name_required' => CheckoutFieldsSchema::isFullNameRequired(),
572 'business_details' => [
573 'company_name' => [
574 'enabled' => CheckoutFieldsSchema::isCompanyNameEnabled(),
575 'required' => CheckoutFieldsSchema::isCompanyNameRequired(),
576 ],
577 'vat_number' => [
578 'enabled' => CheckoutFieldsSchema::isVatNumberEnabled(),
579 'required' => CheckoutFieldsSchema::isVatNumberRequired(),
580 ],
581 'legal_registration_id' => [
582 'enabled' => CheckoutFieldsSchema::isLegalRegistrationIdEnabled(),
583 'required' => CheckoutFieldsSchema::isLegalRegistrationIdRequired(),
584 ],
585 ],
586 'fct_editor_frame' => '',
587 ]);
588
589 wp_localize_script($slug . '_admin_app_start', 'fluentCartAdminApp', $adminLocalizeData);
590
591 wp_localize_script($slug . '_admin_app_start', 'fluentCartRestVars', [
592 'rest' => $restVars,
593 ]);
594
595 do_action('fluent_cart/admin_js_loaded', $app);
596 }
597
598 public function globalEnqueueAssets($adminBar)
599 {
600 if (function_exists('get_current_screen')) {
601 $screen = get_current_screen();
602 } else {
603 $screen = null;
604 }
605
606 if ($screen && $screen->base !== 'user-edit') {
607 return;
608 }
609
610 $app = App::getInstance();
611
612 $slug = $app->config->get('app.slug');
613 if (is_admin()) {
614 wp_enqueue_script($slug . '_edit_wp_user_admin_global_js', Vite::getEnqueuePath('admin/utils/edit-wp-user-global.js'), ['jquery'], FLUENTCART_VERSION, true);
615 }
616
617
618 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
619
620 $editingUserVars = null;
621
622 if (function_exists('get_current_screen')) {
623 $currentScreen = get_current_screen();
624 if ($currentScreen && $currentScreen->id == 'user-edit') {
625 $userId = (int)($_GET['user_id'] ?? 0);
626 $user = get_user_by('ID', $userId);
627
628 if ($userId && $user) {
629 $fluentcartProfile = Customer::query()->where('email', $user->user_email)
630 ->orWhere('user_id', $user->ID)
631 ->first();
632 if ($fluentcartProfile) {
633 $fluentcartProfileUrl = $baseUrl . 'customers/' . $fluentcartProfile->id . '/view';
634 $editingUserVars = [
635 'user_id' => $userId,
636 'fct_profile_id' => $fluentcartProfile->id,
637 'fct_profile_url' => $fluentcartProfileUrl
638 ];
639 }
640 }
641 }
642 }
643 wp_localize_script('fluent-cart_edit_wp_user_admin_global_js', 'fluentcart_edit_user_global_bar_vars', [
644 'customer_base' => $baseUrl . 'customers/',
645 'edit_user_vars' => $editingUserVars
646 ]);
647 }
648
649 protected function getMenuIcon(): string
650 {
651 $svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" fill="none">
652 <g clip-path="url(#clip0_394_8994)">
653 <path d="M90 0C95.5229 0 100 4.47715 100 10V90C100 95.5229 95.5229 100 90 100H10C4.47715 100 0 95.5229 0 90V10C0 4.47715 4.47715 0 10 0H90ZM28.3525 52.5986C24.8927 52.5988 21.7641 54.6544 20.3906 57.8301L15.7119 68.6484H45.5205C52.4408 68.6484 58.6996 64.5355 61.4463 58.1836L63.8613 52.5986H28.3525ZM46.6748 31.333C39.7545 31.333 33.4959 35.4459 30.749 41.7979L28.333 47.3828H70.2617C73.7217 47.3828 76.8513 45.3264 78.2246 42.1504L82.9023 31.333H46.6748Z" fill="#9CA1A8"/>
654 </g>
655 <defs>
656 <clipPath id="clip0_394_8994">
657 <rect width="100" height="100" fill="white"/>
658 </clipPath>
659 </defs>
660 </svg>';
661
662 return 'data:image/svg+xml;base64,' . base64_encode($svg);
663 }
664
665 }
666