| 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 (isset($_GET['custom-editor']) && $_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 |
// 'product_pricing' => [ |
| 44 |
// 'label' => __('Pricing', 'fluent-cart'), |
| 45 |
// 'link' => $baseUrl . 'products/' . $productId . '/pricing' |
| 46 |
// ], |
| 47 |
// 'product_integrations' => [ |
| 48 |
// 'label' => __('Integrations', 'fluent-cart'), |
| 49 |
// 'link' => $baseUrl . 'products/' . $productId . '/integrations' |
| 50 |
// ] |
| 51 |
], [ |
| 52 |
'product_id' => $productId, |
| 53 |
'base_url' => $baseUrl |
| 54 |
]); |
| 55 |
|
| 56 |
$request = App::request()->all(); |
| 57 |
if (isset($request['action']) && $request['action'] == 'edit') { |
| 58 |
$menuItems['product_details'] = [ |
| 59 |
'label' => __('Edit Pricing', 'fluent-cart'), |
| 60 |
'link' => admin_url('admin.php?page=fluent-cart#/products/' . $productId) |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
$productName = $product->post_title; |
| 66 |
|
| 67 |
$data = [ |
| 68 |
'menu_items' => $menuItems, |
| 69 |
'active' => $activeMenu, |
| 70 |
'products_url' => $baseUrl . 'products', |
| 71 |
'product_name' => $productName, |
| 72 |
'status' => $product->post_status, |
| 73 |
'product_id' => $productId |
| 74 |
]; |
| 75 |
|
| 76 |
if ($echo) { |
| 77 |
App::make('view')->render('admin.admin_product_menu', $data); |
| 78 |
} else { |
| 79 |
return (string)App::make('view')->make('admin.admin_product_menu', $data); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
public static function getAdminMenu($echo = false, $activeNav = '') |
| 84 |
{ |
| 85 |
$baseUrl = apply_filters('fluent_cart/admin_base_url', admin_url('admin.php?page=fluent-cart#/'), []); |
| 86 |
$menuItems = apply_filters('fluent_cart/global_admin_menu_items', [ |
| 87 |
'dashboard' => [ |
| 88 |
'label' => __('Dashboard', 'fluent-cart'), |
| 89 |
'link' => $baseUrl |
| 90 |
], |
| 91 |
'orders' => [ |
| 92 |
'label' => __('Orders', 'fluent-cart'), |
| 93 |
'link' => $baseUrl . 'orders', |
| 94 |
'permission' => ['orders/view'] |
| 95 |
], |
| 96 |
'customers' => [ |
| 97 |
'label' => __('Customers', 'fluent-cart'), |
| 98 |
'link' => $baseUrl . 'customers', |
| 99 |
'permission' => ['customers/view', 'customers/manage'] |
| 100 |
], |
| 101 |
'products' => [ |
| 102 |
'label' => __('Products', 'fluent-cart'), |
| 103 |
'link' => $baseUrl . 'products', |
| 104 |
'permission' => ['products/view'] |
| 105 |
], |
| 106 |
'subscriptions' => [ |
| 107 |
'label' => __('Subscriptions', 'fluent-cart'), |
| 108 |
'link' => $baseUrl . 'subscriptions', |
| 109 |
'permission' => ['subscriptions/view'] |
| 110 |
], |
| 111 |
'reports' => [ |
| 112 |
'label' => __('Reports', 'fluent-cart'), |
| 113 |
'link' => $baseUrl . 'reports/overview', |
| 114 |
'permission' => ['reports/view'] |
| 115 |
], |
| 116 |
], ['base_url' => $baseUrl]); |
| 117 |
|
| 118 |
$menuItems['more'] = [ |
| 119 |
'label' => __('More', 'fluent-cart'), |
| 120 |
'link' => '#', |
| 121 |
'children' => [] |
| 122 |
]; |
| 123 |
|
| 124 |
|
| 125 |
$moreItems = apply_filters('fluent_cart/global_admin_menu_more_items', array_filter([ |
| 126 |
'integrations' => [ |
| 127 |
'label' => __('Integrations', 'fluent-cart'), |
| 128 |
'link' => $baseUrl . 'integrations', |
| 129 |
'permission' => ['is_super_admin'], |
| 130 |
], |
| 131 |
'order_bump' => App::isProActive() && ModuleSettings::isActive('order_bump') ? [ |
| 132 |
'label' => __('Order Bump', 'fluent-cart'), |
| 133 |
'link' => $baseUrl . 'order_bump', |
| 134 |
] : false, |
| 135 |
'coupons' => [ |
| 136 |
'label' => __('Coupons', 'fluent-cart'), |
| 137 |
'link' => $baseUrl . 'coupons', |
| 138 |
], |
| 139 |
'taxes' => TaxModule::isTaxEnabled() ? [ |
| 140 |
'label' => __('Taxes', 'fluent-cart'), |
| 141 |
'link' => $baseUrl . 'taxes', |
| 142 |
'permission' => ['store/settings', 'store/sensitive'], |
| 143 |
] : false, |
| 144 |
'categories' => [ |
| 145 |
'label' => __('Categories', 'fluent-cart'), |
| 146 |
'link' => admin_url('edit-tags.php?taxonomy=product-categories&post_type=fluent-products') |
| 147 |
], |
| 148 |
'brands' => [ |
| 149 |
'label' => __('Brands', 'fluent-cart'), |
| 150 |
'link' => admin_url('edit-tags.php?taxonomy=product-brands&post_type=fluent-products') |
| 151 |
], |
| 152 |
'logs' => [ |
| 153 |
'label' => __('Logs', 'fluent-cart'), |
| 154 |
'link' => $baseUrl . 'logs', |
| 155 |
], |
| 156 |
]), ['base_url' => $baseUrl]); |
| 157 |
|
| 158 |
$menuItems['more']['children'] = $moreItems; |
| 159 |
|
| 160 |
if ($echo) { |
| 161 |
App::make('view')->render('admin.admin_menu', [ |
| 162 |
'menu_items' => $menuItems, |
| 163 |
'active' => $activeNav |
| 164 |
]); |
| 165 |
} else { |
| 166 |
return App::make('view')->make('admin.admin_menu', [ |
| 167 |
'menu_items' => $menuItems, |
| 168 |
'active' => $activeNav |
| 169 |
]); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
public static function pushGlobalAdminAssets() |
| 174 |
{ |
| 175 |
$app = App::getInstance(); |
| 176 |
|
| 177 |
$assets = $app['url.assets']; |
| 178 |
|
| 179 |
$slug = $app->config->get('app.slug'); |
| 180 |
|
| 181 |
wp_enqueue_style( |
| 182 |
$slug . '_global_admin_app', $assets . 'admin/global_admin.css', |
| 183 |
[], |
| 184 |
FLUENTCART_VERSION, |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|