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

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