PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
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 1.2.0 All 47 releases
fluent-cart / app / Http / Controllers / DashboardController.php

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

214 lines 7.5 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 'hash_id' => '',
25 'url' => $baseUrl . "settings/store-settings/pages_setup"
26 ],
27 'store_info' => [
28 'title' => __('Add Details to Store', 'fluent-cart'),
29 'text' => __('Store details such as addresses, company info etc.', 'fluent-cart'),
30 'icon' => 'StoreIcon',
31 'completed' => false,
32 'hash_id' => '',
33 'url' => $baseUrl . "settings/store-settings"
34 ],
35 'product_info' => [
36 'title' => __('Add Your First Product', 'fluent-cart'),
37 'text' => __('Share your brand story and build trust with customers.', 'fluent-cart'),
38 'icon' => 'ShoppingCartIcon',
39 'completed' => false,
40 'hash_id' => '',
41 'url' => $baseUrl . "products"
42 ],
43
44
45 'setup_payments' => [
46 'title' => __('Setup Payment Methods', 'fluent-cart'),
47 'text' => __("Choose from fast & secure online and offline payment.", 'fluent-cart'),
48 'icon' => 'PaymentIcon',
49 'completed' => true,
50 'hash_id' => '',
51 'url' => $baseUrl . "settings/payments"
52 ],
53 ];
54
55 $settings = (new StoreSettings)->get();
56
57 if ($this->isStoreInfoProvided($settings)) {
58 $completed++;
59 $steps['store_info']['completed'] = true;
60 }
61
62 if ($this->isProductInfoProvided()) {
63 $completed++;
64 $steps['product_info']['completed'] = true;
65 }
66
67 $missingPage = $this->getMissingPageSetup($settings);
68
69 if (!$missingPage) {
70 $completed++;
71 $steps['page_setup']['completed'] = true;
72 } else {
73 // Let whichever plugin registered the missing page (via
74 // fluent_cart/generatable_pages) decide where it should be
75 // resolved. Core stays agnostic of third-party settings screens.
76 $steps['page_setup']['url'] = apply_filters(
77 'fluent_cart/dashboard/page_setup_redirect_url',
78 $steps['page_setup']['url'],
79 [
80 'missing_page' => $missingPage,
81 'base_url' => $baseUrl,
82 ]
83 );
84 }
85
86 if (!$this->isAnyPaymentModuleEnabled()) {
87 $steps['setup_payments']['completed'] = false;
88 } else {
89 $completed++;
90 }
91
92 if (defined('BRICKS_VERSION')) {
93 $steps['install_bricks_addon'] = [
94 'title' => __('Install Bricks Addon', 'fluent-cart'),
95 'text' => __('Design your store pages with FluentCart elements in Bricks.', 'fluent-cart'),
96 'icon' => 'AppsLine',
97 'completed' => false,
98 'hash_id' => 'fluent-cart-bricks-blocks',
99 'url' => $baseUrl . "settings/addons"
100 ];
101
102 if (defined('FLUENT_CART_BRICKS_BLOCKS_VERSION')) {
103 $steps['install_bricks_addon']['completed'] = true;
104 $completed++;
105 }
106 }
107
108 if (defined('ELEMENTOR_VERSION')) {
109 $steps['install_elementor_addon'] = [
110 'title' => __('Install Elementor Addon', 'fluent-cart'),
111 'text' => __('Design your store pages with FluentCart widgets in Elementor.', 'fluent-cart'),
112 'icon' => 'AppsLine',
113 'completed' => false,
114 'hash_id' => 'fluent-cart-elementor-blocks',
115 'url' => $baseUrl . "settings/addons"
116 ];
117
118 if (defined('FLUENTCART_ELEMENTOR_BLOCKS_VERSION')) {
119 $steps['install_elementor_addon']['completed'] = true;
120 $completed++;
121 }
122 }
123
124 if (strpos(get_template(), 'Divi') !== false) {
125 $steps['install_divi_addon'] = [
126 'title' => __('Install Divi Addon', 'fluent-cart'),
127 'text' => __('Design your store pages with FluentCart modules in Divi.', 'fluent-cart'),
128 'icon' => 'AppsLine',
129 'completed' => false,
130 'hash_id' => 'fluent-cart-divi-modules',
131 'url' => $baseUrl . "settings/addons"
132 ];
133
134 // FLUENTCART_DIVI_BLOCKS_VERSION covers installs from before the slug rename
135 if (defined('FLUENTCART_DIVI_MODULES_VERSION') || defined('FLUENTCART_DIVI_BLOCKS_VERSION')) {
136 $steps['install_divi_addon']['completed'] = true;
137 $completed++;
138 }
139 }
140
141 return $this->response->json([
142 'data' => [
143 'steps' => $steps,
144 'completed' => $completed
145 ]
146 ]);
147 }
148
149 protected function isStoreInfoProvided(array $settings): bool
150 {
151 $storeName = Arr::get($settings, 'store_name');
152 $storeLogo = Arr::get($settings, 'store_logo');
153 return !(
154 //$storeName === 'Fluent Cart Shop' ||
155 empty($storeName) ||
156 empty($storeLogo)
157 );
158 }
159
160 protected function isProductInfoProvided(): bool
161 {
162 return Product::query()->count() > 0;
163 }
164
165
166 private function getMissingPageSetup(array $settings): ?array
167 {
168 $pagesInstance = new Pages();
169 $pages = $pagesInstance->getGeneratablePage();
170
171 // Core pages must be checked first regardless of the order a
172 // fluent_cart/generatable_pages listener leaves the filtered array
173 // in, so an add-on can never take priority over a missing core page.
174 $orderedKeys = array_unique(array_merge(
175 array_keys($pagesInstance->corePages()),
176 array_keys($pages)
177 ));
178
179 foreach ($orderedKeys as $pageKey) {
180 if (!isset($pages[$pageKey])) {
181 continue;
182 }
183
184 $settingKey = "{$pageKey}_page_id";
185 if (empty(Arr::get($settings, $settingKey))) {
186 return array_merge($pages[$pageKey], [
187 'key' => $pageKey,
188 'setting_key' => $settingKey,
189 ]);
190 }
191 }
192
193 return null;
194 }
195
196 private function isAnyPaymentModuleEnabled(): bool
197 {
198 $gateways = (new GlobalPaymentHandler())->getAll();
199 foreach ($gateways as $gateway) {
200 if ($gateway['status']) {
201 return true;
202 }
203 }
204 return false;
205 }
206
207 public function getDashboardStats(): \WP_REST_Response
208 {
209 return $this->sendSuccess([
210 'stats' => DashboardWidget::widgets()
211 ]);
212 }
213 }
214