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 / Helpers / AdminHelper.php

AdminHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Helpers/AdminHelper.php

231 lines 8.1 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\Helpers;
4
5 use FluentCart\Api\ModuleSettings;
6 use FluentCart\App\App;
7 use FluentCart\App\Http\Controllers\ProductController;
8 use FluentCart\App\Models\Product;
9 use FluentCart\App\Modules\Tax\TaxModule;
10 use FluentCart\App\Services\Filter\OrderFilter;
11 use FluentCart\App\Services\URL;
12
13 class AdminHelper
14 {
15 public static function getProductMenu($product, $echo = false, $activeMenu = '')
16 {
17 // Skip rendering menu when custom editor modal is open
18 if (App::request()->get('custom-editor') === 'true') {
19 return '';
20 }
21
22 if (!$product instanceof Product) {
23 $product = Product::query()->find($product);
24 }
25
26 $productId = $product->ID;
27
28 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
29
30 $menuItems = apply_filters('fluent_cart/product_admin_items', [
31 'product_edit' => [
32 'label' => __('Edit Product', 'fluent-cart'),
33 'link' => $baseUrl . 'products/' . $productId
34 ],
35 'product_upgrade_paths' => [
36 'label' => __('Upgrade Paths', 'fluent-cart'),
37 'link' => $baseUrl . 'products/' . $productId . '/upgrade-paths'
38 ],
39 'product_integrations' => [
40 'label' => __('Integrations', 'fluent-cart'),
41 'link' => $baseUrl . 'products/' . $productId . '/integrations'
42 ],
43 ], [
44 'product_id' => $productId,
45 'base_url' => $baseUrl
46 ]);
47
48 $request = App::request()->all();
49 if (isset($request['action']) && $request['action'] === 'edit') {
50 $menuItems['product_details'] = [
51 'label' => __('Edit Pricing', 'fluent-cart'),
52 'link' => admin_url('admin.php?page=fluent-cart#/products/' . $productId)
53 ];
54 }
55
56
57 $productName = $product->post_title;
58
59 $data = [
60 'menu_items' => $menuItems,
61 'active' => $activeMenu,
62 'products_url' => $baseUrl . 'products',
63 'product_name' => $productName,
64 'status' => $product->post_status,
65 'product_id' => $productId
66 ];
67
68 if (!$echo) {
69 return (string)App::make('view')->make('admin.admin_product_menu', $data);
70 }
71
72 App::make('view')->render('admin.admin_product_menu', $data);
73 }
74
75 private static function getProductsMenu($baseUrl)
76 {
77 $menu = [
78 'label' => __('Products', 'fluent-cart'),
79 'link' => $baseUrl . 'products',
80 'permission' => ['products/view']
81 ];
82
83 $children = [];
84
85 // The parent link is not reachable on touch (the tap opens the dropdown),
86 // and the off-canvas menu renders children only — so list it as a child too.
87 $children['all_products'] = [
88 'label' => __('All Products', 'fluent-cart'),
89 'link' => $baseUrl . 'products',
90 'permission' => ['products/view']
91 ];
92
93 // Attributes power the advanced-variations feature.
94 $children['product_attributes'] = [
95 'label' => __('Attributes', 'fluent-cart'),
96 'link' => $baseUrl . 'products/attributes',
97 'permission' => ['products/view']
98 ];
99
100 // Inventory only when the advanced-inventory toggle is on.
101 if (ModuleSettings::isActive('stock_management') &&
102 ModuleSettings::getSettings('stock_management.enable_advanced_inventory') === 'yes') {
103 $children['product_inventory'] = [
104 'label' => __('Inventory', 'fluent-cart'),
105 'link' => $baseUrl . 'products/inventory',
106 'permission' => ['products/view']
107 ];
108 }
109
110 $menu['children'] = $children;
111
112 return $menu;
113 }
114
115 public static function getAdminMenu($echo = false, $activeNav = '')
116 {
117 $menuItems = self::getMenuItems();
118
119 if (!$echo) {
120 return App::make('view')->make('admin.admin_menu', [
121 'menu_items' => $menuItems,
122 'active' => $activeNav
123 ]);
124 }
125
126 App::make('view')->render('admin.admin_menu', [
127 'menu_items' => $menuItems,
128 'active' => $activeNav
129 ]);
130 }
131
132 public static function getMenuItems($withSettings = false)
133 {
134 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
135 $menuItems = apply_filters('fluent_cart/global_admin_menu_items', [
136 'dashboard' => [
137 'label' => __('Dashboard', 'fluent-cart'),
138 'link' => $baseUrl
139 ],
140 'orders' => [
141 'label' => __('Orders', 'fluent-cart'),
142 'link' => $baseUrl . 'orders',
143 'permission' => ['orders/view']
144 ],
145 'customers' => [
146 'label' => __('Customers', 'fluent-cart'),
147 'link' => $baseUrl . 'customers',
148 'permission' => ['customers/view', 'customers/manage']
149 ],
150 'products' => self::getProductsMenu($baseUrl),
151 'subscriptions' => [
152 'label' => __('Subscriptions', 'fluent-cart'),
153 'link' => $baseUrl . 'subscriptions',
154 'permission' => ['subscriptions/view']
155 ],
156 'reports' => [
157 'label' => __('Reports', 'fluent-cart'),
158 'link' => $baseUrl . 'reports/overview',
159 'permission' => ['reports/view']
160 ],
161 ], ['base_url' => $baseUrl]);
162
163 $moreItems = apply_filters('fluent_cart/global_admin_menu_more_items', array_filter([
164 'integrations' => [
165 'label' => __('Integrations', 'fluent-cart'),
166 'link' => $baseUrl . 'integrations',
167 'permission' => ['is_super_admin'],
168 ],
169 'order_bump' => App::isProActive() && ModuleSettings::isActive('order_bump') ? [
170 'label' => __('Order Bump', 'fluent-cart'),
171 'link' => $baseUrl . 'order_bump',
172 ] : false,
173 'coupons' => [
174 'label' => __('Coupons', 'fluent-cart'),
175 'link' => $baseUrl . 'coupons',
176 ],
177 'taxes' => TaxModule::isTaxEnabled() ? [
178 'label' => __('Taxes', 'fluent-cart'),
179 'link' => $baseUrl . 'taxes',
180 'permission' => ['store/settings', 'store/sensitive'],
181 ] : false,
182 'categories' => [
183 'label' => __('Categories', 'fluent-cart'),
184 'link' => admin_url('edit-tags.php?taxonomy=product-categories&post_type=fluent-products')
185 ],
186 'brands' => [
187 'label' => __('Brands', 'fluent-cart'),
188 'link' => admin_url('edit-tags.php?taxonomy=product-brands&post_type=fluent-products')
189 ],
190 'logs' => [
191 'label' => __('Logs', 'fluent-cart'),
192 'link' => $baseUrl . 'logs',
193 ],
194 ]), ['base_url' => $baseUrl]);
195
196 if ($withSettings) {
197 $menuItems['settings'] = [
198 'label' => __('Settings', 'fluent-cart'),
199 'link' => $baseUrl . 'settings/store-settings',
200 'permission' => ['store/settings', 'store/sensitive'],
201 'icon' => 'fluent-settings'
202 ];
203 }
204
205 $menuItems['more'] = [
206 'label' => __('More', 'fluent-cart'),
207 'link' => '#',
208 'children' => $moreItems,
209 ];
210
211
212 return $menuItems;
213 }
214
215 public static function pushGlobalAdminAssets()
216 {
217 $app = App::getInstance();
218
219 $assets = $app['url.assets'];
220
221 $slug = $app->config->get('app.slug');
222
223 wp_enqueue_style(
224 $slug . '_global_admin_app', $assets . 'admin/global_admin.css',
225 [],
226 FLUENTCART_VERSION,
227 );
228 }
229 }
230
231