PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.23
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.23
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 / Http / Controllers / DashboardController.php

DashboardController.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.23, at app/Http/Controllers/DashboardController.php

130 lines 4.0 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\Http\Controllers;
4
5 use FluentCart\Api\StoreSettings;
6 use FluentCart\App\CPT\Pages;
7 use FluentCart\App\Hooks\Handlers\GlobalPaymentHandler;
8 use FluentCart\App\Models\Product;
9 use FluentCart\App\Services\Widgets\DashboardWidget;
10 use FluentCart\Framework\Support\Arr;
11
12 class DashboardController extends Controller
13 {
14 public function getOnboardingData()
15 {
16 $completed = 0;
17 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
18 $steps = [
19 'page_setup' => [
20 'title' => __('Setup Pages', 'fluent-cart'),
21 'text' => __("Customers to find what they're looking for by organising.", 'fluent-cart'),
22 'icon' => 'Cart',
23 'completed' => false,
24 'url' => $baseUrl . "settings/store-settings/pages_setup"
25 ],
26 'store_info' => [
27 'title' => __('Add Details to Store', 'fluent-cart'),
28 'text' => __('Store details such as addresses, company info etc.', 'fluent-cart'),
29 'icon' => 'StoreIcon',
30 'completed' => false,
31 'url' => $baseUrl . "settings/store-settings/"
32 ],
33 'product_info' => [
34 'title' => __('Add Your First Product', 'fluent-cart'),
35 'text' => __('Share your brand story and build trust with customers.', 'fluent-cart'),
36 'icon' => 'ShoppingCartIcon',
37 'completed' => false,
38 'url' => $baseUrl . "products"
39 ],
40
41
42 'setup_payments' => [
43 'title' => __('Setup Payment Methods', 'fluent-cart'),
44 'text' => __("Choose from fast & secure online and offline payment.", 'fluent-cart'),
45 'icon' => 'PaymentIcon',
46 'completed' => true,
47 'url' => $baseUrl . "settings/payments"
48 ],
49 ];
50
51 $settings = (new StoreSettings)->get();
52
53 if ($this->isStoreInfoProvided($settings)) {
54 $completed++;
55 $steps['store_info']['completed'] = true;
56 }
57
58 if ($this->isProductInfoProvided()) {
59 $completed++;
60 $steps['product_info']['completed'] = true;
61 }
62
63 if ($this->isAllPageSetUpDone($settings)) {
64 $completed++;
65 $steps['page_setup']['completed'] = true;
66 }
67
68 if (!$this->isAnyPaymentModuleEnabled()) {
69 $steps['setup_payments']['completed'] = false;
70 } else {
71 $completed++;
72 }
73
74
75 return $this->response->json([
76 'data' => [
77 'steps' => $steps,
78 'completed' => $completed
79 ]
80 ]);
81 }
82
83 protected function isStoreInfoProvided(array $settings): bool
84 {
85 $storeName = Arr::get($settings, 'store_name');
86 $storeLogo = Arr::get($settings, 'store_logo');
87 return !(
88 //$storeName === 'Fluent Cart Shop' ||
89 empty($storeName) ||
90 empty($storeLogo)
91 );
92 }
93
94 protected function isProductInfoProvided(): bool
95 {
96 return Product::query()->count() > 0;
97 }
98
99
100 private function isAllPageSetUpDone(array $settings): bool
101 {
102 $pages = (new Pages())->getGeneratablePage();
103 foreach ($pages as $pageKey => $page) {
104 $pageKey = "{$pageKey}_page_id";
105 if (empty(Arr::get($settings, $pageKey))) {
106 return false;
107 }
108 }
109 return true;
110 }
111
112 private function isAnyPaymentModuleEnabled(): bool
113 {
114 $gateways = (new GlobalPaymentHandler())->getAll();
115 foreach ($gateways as $gateway) {
116 if ($gateway['status']) {
117 return true;
118 }
119 }
120 return false;
121 }
122
123 public function getDashboardStats(): \WP_REST_Response
124 {
125 return $this->sendSuccess([
126 'stats' => DashboardWidget::widgets()
127 ]);
128 }
129 }
130