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

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

181 lines 6.2 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 if ($this->isAllPageSetUpDone($settings)) {
68 $completed++;
69 $steps['page_setup']['completed'] = true;
70 }
71
72 if (!$this->isAnyPaymentModuleEnabled()) {
73 $steps['setup_payments']['completed'] = false;
74 } else {
75 $completed++;
76 }
77
78 if (defined('BRICKS_VERSION')) {
79 $steps['install_bricks_addon'] = [
80 'title' => __('Install Bricks Addon', 'fluent-cart'),
81 'text' => __('Design your store pages with FluentCart elements in Bricks.', 'fluent-cart'),
82 'icon' => 'AppsLine',
83 'completed' => false,
84 'hash_id' => 'fluent-cart-bricks-blocks',
85 'url' => $baseUrl . "settings/addons"
86 ];
87
88 if (defined('FLUENT_CART_BRICKS_BLOCKS_VERSION')) {
89 $steps['install_bricks_addon']['completed'] = true;
90 $completed++;
91 }
92 }
93
94 if (defined('ELEMENTOR_VERSION')) {
95 $steps['install_elementor_addon'] = [
96 'title' => __('Install Elementor Addon', 'fluent-cart'),
97 'text' => __('Design your store pages with FluentCart widgets in Elementor.', 'fluent-cart'),
98 'icon' => 'AppsLine',
99 'completed' => false,
100 'hash_id' => 'fluent-cart-elementor-blocks',
101 'url' => $baseUrl . "settings/addons"
102 ];
103
104 if (defined('FLUENTCART_ELEMENTOR_BLOCKS_VERSION')) {
105 $steps['install_elementor_addon']['completed'] = true;
106 $completed++;
107 }
108 }
109
110 if (strpos(get_template(), 'Divi') !== false) {
111 $steps['install_divi_addon'] = [
112 'title' => __('Install Divi Addon', 'fluent-cart'),
113 'text' => __('Design your store pages with FluentCart modules in Divi.', 'fluent-cart'),
114 'icon' => 'AppsLine',
115 'completed' => false,
116 'hash_id' => 'fluent-cart-divi-blocks',
117 'url' => $baseUrl . "settings/addons"
118 ];
119
120 if (defined('FLUENTCART_DIVI_BLOCKS_VERSION')) {
121 $steps['install_divi_addon']['completed'] = true;
122 $completed++;
123 }
124 }
125
126 return $this->response->json([
127 'data' => [
128 'steps' => $steps,
129 'completed' => $completed
130 ]
131 ]);
132 }
133
134 protected function isStoreInfoProvided(array $settings): bool
135 {
136 $storeName = Arr::get($settings, 'store_name');
137 $storeLogo = Arr::get($settings, 'store_logo');
138 return !(
139 //$storeName === 'Fluent Cart Shop' ||
140 empty($storeName) ||
141 empty($storeLogo)
142 );
143 }
144
145 protected function isProductInfoProvided(): bool
146 {
147 return Product::query()->count() > 0;
148 }
149
150
151 private function isAllPageSetUpDone(array $settings): bool
152 {
153 $pages = (new Pages())->getGeneratablePage();
154 foreach ($pages as $pageKey => $page) {
155 $pageKey = "{$pageKey}_page_id";
156 if (empty(Arr::get($settings, $pageKey))) {
157 return false;
158 }
159 }
160 return true;
161 }
162
163 private function isAnyPaymentModuleEnabled(): bool
164 {
165 $gateways = (new GlobalPaymentHandler())->getAll();
166 foreach ($gateways as $gateway) {
167 if ($gateway['status']) {
168 return true;
169 }
170 }
171 return false;
172 }
173
174 public function getDashboardStats(): \WP_REST_Response
175 {
176 return $this->sendSuccess([
177 'stats' => DashboardWidget::widgets()
178 ]);
179 }
180 }
181