PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.2
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 / Helpers / AdminHelper.php

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

223 lines 7.8 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 // Attributes power the advanced-variations feature.
86 $children['product_attributes'] = [
87 'label' => __('Attributes', 'fluent-cart'),
88 'link' => $baseUrl . 'products/attributes',
89 'permission' => ['products/view']
90 ];
91
92 // Inventory only when the advanced-inventory toggle is on.
93 if (ModuleSettings::isActive('stock_management') &&
94 ModuleSettings::getSettings('stock_management.enable_advanced_inventory') === 'yes') {
95 $children['product_inventory'] = [
96 'label' => __('Inventory', 'fluent-cart'),
97 'link' => $baseUrl . 'products/inventory',
98 'permission' => ['products/view']
99 ];
100 }
101
102 $menu['children'] = $children;
103
104 return $menu;
105 }
106
107 public static function getAdminMenu($echo = false, $activeNav = '')
108 {
109 $menuItems = self::getMenuItems();
110
111 if (!$echo) {
112 return App::make('view')->make('admin.admin_menu', [
113 'menu_items' => $menuItems,
114 'active' => $activeNav
115 ]);
116 }
117
118 App::make('view')->render('admin.admin_menu', [
119 'menu_items' => $menuItems,
120 'active' => $activeNav
121 ]);
122 }
123
124 public static function getMenuItems($withSettings = false)
125 {
126 $baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []);
127 $menuItems = apply_filters('fluent_cart/global_admin_menu_items', [
128 'dashboard' => [
129 'label' => __('Dashboard', 'fluent-cart'),
130 'link' => $baseUrl
131 ],
132 'orders' => [
133 'label' => __('Orders', 'fluent-cart'),
134 'link' => $baseUrl . 'orders',
135 'permission' => ['orders/view']
136 ],
137 'customers' => [
138 'label' => __('Customers', 'fluent-cart'),
139 'link' => $baseUrl . 'customers',
140 'permission' => ['customers/view', 'customers/manage']
141 ],
142 'products' => self::getProductsMenu($baseUrl),
143 'subscriptions' => [
144 'label' => __('Subscriptions', 'fluent-cart'),
145 'link' => $baseUrl . 'subscriptions',
146 'permission' => ['subscriptions/view']
147 ],
148 'reports' => [
149 'label' => __('Reports', 'fluent-cart'),
150 'link' => $baseUrl . 'reports/overview',
151 'permission' => ['reports/view']
152 ],
153 ], ['base_url' => $baseUrl]);
154
155 $moreItems = apply_filters('fluent_cart/global_admin_menu_more_items', array_filter([
156 'integrations' => [
157 'label' => __('Integrations', 'fluent-cart'),
158 'link' => $baseUrl . 'integrations',
159 'permission' => ['is_super_admin'],
160 ],
161 'order_bump' => App::isProActive() && ModuleSettings::isActive('order_bump') ? [
162 'label' => __('Order Bump', 'fluent-cart'),
163 'link' => $baseUrl . 'order_bump',
164 ] : false,
165 'coupons' => [
166 'label' => __('Coupons', 'fluent-cart'),
167 'link' => $baseUrl . 'coupons',
168 ],
169 'taxes' => TaxModule::isTaxEnabled() ? [
170 'label' => __('Taxes', 'fluent-cart'),
171 'link' => $baseUrl . 'taxes',
172 'permission' => ['store/settings', 'store/sensitive'],
173 ] : false,
174 'categories' => [
175 'label' => __('Categories', 'fluent-cart'),
176 'link' => admin_url('edit-tags.php?taxonomy=product-categories&post_type=fluent-products')
177 ],
178 'brands' => [
179 'label' => __('Brands', 'fluent-cart'),
180 'link' => admin_url('edit-tags.php?taxonomy=product-brands&post_type=fluent-products')
181 ],
182 'logs' => [
183 'label' => __('Logs', 'fluent-cart'),
184 'link' => $baseUrl . 'logs',
185 ],
186 ]), ['base_url' => $baseUrl]);
187
188 if ($withSettings) {
189 $menuItems['settings'] = [
190 'label' => __('Settings', 'fluent-cart'),
191 'link' => $baseUrl . 'settings/store-settings',
192 'permission' => ['store/settings', 'store/sensitive'],
193 'icon' => 'fluent-settings'
194 ];
195 }
196
197 $menuItems['more'] = [
198 'label' => __('More', 'fluent-cart'),
199 'link' => '#',
200 'children' => $moreItems,
201 ];
202
203
204 return $menuItems;
205 }
206
207 public static function pushGlobalAdminAssets()
208 {
209 $app = App::getInstance();
210
211 $assets = $app['url.assets'];
212
213 $slug = $app->config->get('app.slug');
214
215 wp_enqueue_style(
216 $slug . '_global_admin_app', $assets . 'admin/global_admin.css',
217 [],
218 FLUENTCART_VERSION,
219 );
220 }
221 }
222
223