PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 1.6.6 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 All 50 releases
fluent-cart / app / Helpers / AdminHelper.php

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

246 lines 8.9 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 // Any-of: a reviews-only role (reviews/manage without
81 // products/view) must still see the parent, or its authorized
82 // Reviews child could never render. Children gate individually —
83 // including on the reviews module being switched on at all.
84 'permission' => ['products/view', 'reviews/manage']
85 ];
86
87 $children = [];
88
89 // The parent link is not reachable on touch (the tap opens the dropdown),
90 // and the off-canvas menu renders children only — so list it as a child too.
91 $children['all_products'] = [
92 'label' => __('All Products', 'fluent-cart'),
93 'link' => $baseUrl . 'products',
94 'permission' => ['products/view']
95 ];
96
97 // Attributes power the advanced-variations feature.
98 $children['product_attributes'] = [
99 'label' => __('Attributes', 'fluent-cart'),
100 'link' => $baseUrl . 'products/attributes',
101 'permission' => ['products/view']
102 ];
103
104 // Inventory only when the advanced-inventory toggle is on.
105 if (ModuleSettings::isActive('stock_management') &&
106 ModuleSettings::getSettings('stock_management.enable_advanced_inventory') === 'yes') {
107 $children['product_inventory'] = [
108 'label' => __('Inventory', 'fluent-cart'),
109 'link' => $baseUrl . 'products/inventory',
110 'permission' => ['products/view']
111 ];
112 }
113
114 // Only while the store has reviews switched on. The screen behind it
115 // already redirects to the dashboard when the module is off, so an
116 // entry here would be a menu item that bounces whoever clicks it.
117 if (ModuleSettings::isActive('reviews')) {
118 $children['reviews'] = [
119 'label' => __('Reviews', 'fluent-cart'),
120 'link' => $baseUrl . 'reviews',
121 'permission' => ['reviews/manage']
122 ];
123 }
124
125 $menu['children'] = $children;
126
127 return $menu;
128 }
129
130 public static function getAdminMenu($echo = false, $activeNav = '')
131 {
132 $menuItems = self::getMenuItems();
133
134 if (!$echo) {
135 return App::make('view')->make('admin.admin_menu', [
136 'menu_items' => $menuItems,
137 'active' => $activeNav
138 ]);
139 }
140
141 App::make('view')->render('admin.admin_menu', [
142 'menu_items' => $menuItems,
143 'active' => $activeNav
144 ]);
145 }
146
147 public static function getMenuItems($withSettings = false)
148 {
149 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
150 $menuItems = apply_filters('fluent_cart/global_admin_menu_items', [
151 'dashboard' => [
152 'label' => __('Dashboard', 'fluent-cart'),
153 'link' => $baseUrl
154 ],
155 'orders' => [
156 'label' => __('Orders', 'fluent-cart'),
157 'link' => $baseUrl . 'orders',
158 'permission' => ['orders/view']
159 ],
160 'customers' => [
161 'label' => __('Customers', 'fluent-cart'),
162 'link' => $baseUrl . 'customers',
163 'permission' => ['customers/view', 'customers/manage']
164 ],
165 'products' => self::getProductsMenu($baseUrl),
166 'subscriptions' => [
167 'label' => __('Subscriptions', 'fluent-cart'),
168 'link' => $baseUrl . 'subscriptions',
169 'permission' => ['subscriptions/view']
170 ],
171 'reports' => [
172 'label' => __('Reports', 'fluent-cart'),
173 'link' => $baseUrl . 'reports/overview',
174 'permission' => ['reports/view']
175 ],
176 ], ['base_url' => $baseUrl]);
177
178 $moreItems = apply_filters('fluent_cart/global_admin_menu_more_items', array_filter([
179 'integrations' => [
180 'label' => __('Integrations', 'fluent-cart'),
181 'link' => $baseUrl . 'integrations',
182 'permission' => ['is_super_admin'],
183 ],
184 'order_bump' => App::isProActive() && ModuleSettings::isActive('order_bump') ? [
185 'label' => __('Order Bump', 'fluent-cart'),
186 'link' => $baseUrl . 'order_bump',
187 ] : false,
188 'coupons' => [
189 'label' => __('Coupons', 'fluent-cart'),
190 'link' => $baseUrl . 'coupons',
191 ],
192 'taxes' => TaxModule::isTaxEnabled() ? [
193 'label' => __('Taxes', 'fluent-cart'),
194 'link' => $baseUrl . 'taxes',
195 'permission' => ['store/settings', 'store/sensitive'],
196 ] : false,
197 'categories' => [
198 'label' => __('Categories', 'fluent-cart'),
199 'link' => admin_url('edit-tags.php?taxonomy=product-categories&post_type=fluent-products')
200 ],
201 'brands' => [
202 'label' => __('Brands', 'fluent-cart'),
203 'link' => admin_url('edit-tags.php?taxonomy=product-brands&post_type=fluent-products')
204 ],
205 'logs' => [
206 'label' => __('Logs', 'fluent-cart'),
207 'link' => $baseUrl . 'logs',
208 ],
209 ]), ['base_url' => $baseUrl]);
210
211 if ($withSettings) {
212 $menuItems['settings'] = [
213 'label' => __('Settings', 'fluent-cart'),
214 'link' => $baseUrl . 'settings/store-settings',
215 'permission' => ['store/settings', 'store/sensitive'],
216 'icon' => 'fluent-settings'
217 ];
218 }
219
220 $menuItems['more'] = [
221 'label' => __('More', 'fluent-cart'),
222 'link' => '#',
223 'children' => $moreItems,
224 ];
225
226
227 return $menuItems;
228 }
229
230 public static function pushGlobalAdminAssets()
231 {
232 $app = App::getInstance();
233
234 $assets = $app['url.assets'];
235
236 $slug = $app->config->get('app.slug');
237
238 wp_enqueue_style(
239 $slug . '_global_admin_app', $assets . 'admin/global_admin.css',
240 [],
241 FLUENTCART_VERSION,
242 );
243 }
244 }
245
246